From ff26cfbf7a69c40198285c95f12561e5c9aff29a Mon Sep 17 00:00:00 2001 From: Nicholas Lundgaard Date: Sat, 2 Mar 2019 15:59:27 -0600 Subject: [PATCH] Add support for '#' character in additon to ';' as comment delimiter Resolves erlcloud/erlcloud#583 --- src/eini_lexer.xrl | 8 +++++--- src/eini_parser.yrl | 4 ++-- test/eini_tests.erl | 13 +++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/eini_lexer.xrl b/src/eini_lexer.xrl index d66a249..4d71cb1 100644 --- a/src/eini_lexer.xrl +++ b/src/eini_lexer.xrl @@ -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. @@ -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. diff --git a/src/eini_parser.yrl b/src/eini_parser.yrl index 941cd8c..b09bf03 100644 --- a/src/eini_parser.yrl +++ b/src/eini_parser.yrl @@ -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']. diff --git a/test/eini_tests.erl b/test/eini_tests.erl index b6e5fa5..c36cb03 100644 --- a/test/eini_tests.erl +++ b/test/eini_tests.erl @@ -31,6 +31,10 @@ one_section_title_only_test_() -> parse( ";" )), + ?_assertEqual({ok, []}, + parse( + "#" + )), ?_assertEqual({ok, []}, parse( "; " @@ -39,6 +43,10 @@ one_section_title_only_test_() -> parse( "; comment" )), + ?_assertEqual({ok, []}, + parse( + "# comment" + )), ?_assertEqual({ok, []}, parse( "; comment in Japanese 日本語" @@ -62,7 +70,8 @@ one_section_title_only_test_() -> {title, []} ]}, parse( - "; comment line\n" + "; comment line 1\n" + "# comment line 2\n" " \n" "[title]\n" )), @@ -70,7 +79,7 @@ one_section_title_only_test_() -> {title, []} ]}, parse( - "; comment line\n" + "# comment line\n" "; comment line 2\n" " \n" "[title]\n"