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

Handle spaces in titles #6

Merged
merged 1 commit into from
Mar 26, 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
12 changes: 10 additions & 2 deletions src/eini_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Nonterminals
sections_with_skip_lines
section
title_part
title_word
title_words
title
property_with_skip_lines
properties property
Expand Down Expand Up @@ -70,7 +72,13 @@ title_part -> title blank break : list_to_binary('$1').
title_part -> title break skip_lines : list_to_binary('$1').
title_part -> title blank break skip_lines : list_to_binary('$1').

title -> '[' word ']' : value_of('$2').
title_word -> word : value_of('$1').
title_word -> blank : value_of('$1').

title_words -> title_word : ['$1'].
title_words -> title_word title_words : ['$1' | '$2'].

title -> '[' title_words ']' : string:strip(lists:flatten('$2'), both, $\s).

properties -> '$empty' : [].
properties -> property_with_skip_lines properties : ['$1' | '$2'].
Expand All @@ -90,7 +98,7 @@ values -> single_value : ['$1'].
values -> single_value values : ['$1' | '$2'].

%% At value position, any characters are accepted AS IS.
single_value -> word : value_of('$1').
single_value -> word : value_of('$1').
single_value -> value : value_of('$1').
single_value -> blank : value_of('$1').
single_value -> comment : value_of('$1').
Expand Down
19 changes: 10 additions & 9 deletions test/eini_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ one_section_title_only_test_() ->
"[title] \n"
"\n"
"\n"
))
)),
%% blank char in section title
?_assertEqual({ok, #{ <<"tit le">> => #{}}},
parse("[tit le]")),
?_assertEqual({ok, #{ <<"title">> => #{}}},
parse("[title ]")),
?_assertEqual({ok, #{ <<"title">> => #{}}},
parse("[ title]")),
?_assertEqual({ok, #{ <<"title">> => #{}}},
parse("[ title ]"))
]}.

one_section_title_only_syntax_error_test_() ->
Expand Down Expand Up @@ -373,14 +382,6 @@ syntax_error_title_test_() ->
";\n"
"; comment 2\n"
" [title]")),
%% blank char in section title
?_assertMatch({error, {syntax_error, _, _Reason}},
parse(
"[titleA]\n"
"keyA1=valueA1\n"
"[tit leB]\n"
"keyB1=valueB1\n"
)),
%% comment after title
?_assertMatch({error, {syntax_error, _, ["syntax error before: ", _]}},
parse("[title] ;comment")),
Expand Down
Loading