Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar: require a space after the "include" directive #47

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,32 @@ https://github.com/basho/cuttlefish/wiki/Cuttlefish-for-Application-Users

## What's it look like to application packagers?

* [node_package](https://github.com/basho/cuttlefish/wiki/Cuttlefish-for-node_package-users)
* [non node_package](https://github.com/basho/cuttlefish/wiki/Cuttlefish-for-non-node_package-users)
* [node_package](https://github.com/Kyorai/cuttlefish/wiki/Cuttlefish-for-node_package-users)
* [non node_package](https://github.com/Kyorai/cuttlefish/wiki/Cuttlefish-for-non-node_package-users)


## Current Status

Cuttlefish is ready for production deployments.


## Re-generating parser

```
rebar3 as dev neotoma
After using Neotoma Rebar3 plugin to re-generate conf_parse.erl, you **MUST**
edit that file to change the exported `file/1` function to this code:

``` erl
-spec file(file:name()) -> any().
file(Filename) ->
AbsFilename = filename:absname(Filename),
case erl_prim_loader:get_file(AbsFilename) of
{ok, Bin, _} -> parse(Bin);
error -> {error, undefined}
end.
```

Please see the *NOTE* in `src/conf_parse.peg` as well.
To regenerate the parser from the PEG grammar:

```
rebar3 as dev neotoma compile
```
12 changes: 11 additions & 1 deletion src/conf_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ included_dir_test() ->
], Conf),
ok.

invalid_included_file_test() ->
Conf = conf_parse:file("test/invalid_include_file.conf"),
?assertMatch({[], _PathWithNewLineAndCarriage, {{line,_}, {column, _}}}, Conf),
ok.

invalid_included_dir_test() ->
Conf = conf_parse:file("test/invalid_include_dir.conf"),
?assertMatch({[], _PathWithNewLineAndCarriage, {{line, _},{column, _}}}, Conf),
ok.

escaped_dots_are_removed_test() ->
Conf = conf_parse:parse("#comment\nsetting\\.0 = thing0\n"),
?assertEqual([
Expand Down Expand Up @@ -225,7 +235,7 @@ parse(Error) ->

-spec 'include'(input(), index()) -> parse_result().
'include'(Input, Index) ->
p(Input, Index, 'include', fun(I,D) -> (p_seq([p_zero_or_more(fun 'ws'/2), p_string(<<"include">>), p_zero_or_more(fun 'ws'/2), fun 'included_file_or_dir'/2, p_optional(fun 'comment'/2)]))(I,D) end, fun(Node, _Idx) ->
p(Input, Index, 'include', fun(I,D) -> (p_seq([p_zero_or_more(fun 'ws'/2), p_string(<<"include">>), p_one_or_more(fun 'ws'/2), fun 'included_file_or_dir'/2, p_optional(fun 'comment'/2)]))(I,D) end, fun(Node, _Idx) ->
[_, _Include, _, Included, _] = Node,
{include, Included}
end).
Expand Down
2 changes: 1 addition & 1 deletion src/conf_parse.peg
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ value <- (!((ws* crlf) / comment) .)+ %{
comment <- ws* "#" (!crlf .)* `comment`;

%% An include is a line that begins with 'include' and something.
include <- ws* "include" ws* included_file_or_dir comment? %{
include <- ws* "include" ws+ included_file_or_dir comment? %{
[_, _Include, _, Included, _] = Node,
{include, Included}
%};
Expand Down
2 changes: 2 additions & 0 deletions test/invalid_include_dir.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Missing a space. See Kyorai/cuttlefish#38.
includeconf.d/*.conf
3 changes: 3 additions & 0 deletions test/invalid_include_file.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Missing a space. See Kyorai/cuttlefish#38.
includeriak.conf

Loading