Skip to content

Commit

Permalink
Merge pull request #47 from Kyorai/mk-cuttlefish-38
Browse files Browse the repository at this point in the history
Grammar: require a space after the "include" directive
  • Loading branch information
michaelklishin authored Aug 3, 2024
2 parents 69bb0a2 + 14a1aef commit 656018e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
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

0 comments on commit 656018e

Please sign in to comment.