Skip to content

Commit

Permalink
Merge pull request #15 from erlcloud/support_hash_symbol_as_comment_d…
Browse files Browse the repository at this point in the history
…elimiter

Add support for '#' character in additon to ';' as comment delimiter
  • Loading branch information
Evgeny Bob authored Mar 4, 2019
2 parents 9eee0dd + ff26cfb commit 53ad98a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/eini_lexer.xrl
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ Definitions.
K = [a-zA-Z0-9_\-\.]+


%% \x23 : $#
%% \x3b : $;
%% \x3d : $=
%% \x5b : $[
%% \x5d : $]
V = [^\x3b\x3d\x5b\x5d\x0d\x0a\s\t]+
V = [^\x23\x3b\x3d\x5b\x5d\x0d\x0a\s\t]+


%% spaces and breaks
%% spaces, breaks and comment delimiters
S = [\s\t]
B = [\n\r]
C = [;#]

Rules.

Expand All @@ -53,6 +55,6 @@ Rules.
{V} : {token, {value, TokenLine, TokenChars}}.

%% comment-like token, but may be a part of value depending on the location
;.* : {token, {comment, TokenLine, TokenChars}}.
{C}.* : {token, {comment, TokenLine, TokenChars}}.

Erlang code.
4 changes: 2 additions & 2 deletions src/eini_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ Terminals

Rootsymbol whole.

%% Leex smash out all blank lines, but at the beggining of file is NOT.
%% Leex smash out all blank lines, but at the beginning of file is NOT.
whole -> sections_with_skip_lines : '$1'.
whole -> blank_line sections_with_skip_lines : '$2'.

blank_line -> blank break : '$1'.

%% Comment lines are treated as:
%% 1. At the biggining of file are included into sections_with_skip_lines
%% 1. At the beginning of file are included into sections_with_skip_lines
%% 2. Other comment lines are included to title_part and property_with_skip_lines

skip_lines -> comment_line : ['$1'].
Expand Down
13 changes: 11 additions & 2 deletions test/eini_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ one_section_title_only_test_() ->
parse(
";"
)),
?_assertEqual({ok, []},
parse(
"#"
)),
?_assertEqual({ok, []},
parse(
"; "
Expand All @@ -39,6 +43,10 @@ one_section_title_only_test_() ->
parse(
"; comment"
)),
?_assertEqual({ok, []},
parse(
"# comment"
)),
?_assertEqual({ok, []},
parse(
"; comment in Japanese 日本語"
Expand All @@ -62,15 +70,16 @@ one_section_title_only_test_() ->
{title, []}
]},
parse(
"; comment line\n"
"; comment line 1\n"
"# comment line 2\n"
" \n"
"[title]\n"
)),
?_assertEqual({ok, [
{title, []}
]},
parse(
"; comment line\n"
"# comment line\n"
"; comment line 2\n"
" \n"
"[title]\n"
Expand Down

0 comments on commit 53ad98a

Please sign in to comment.