Skip to content

Commit c20c219

Browse files
authored
Merge pull request #17 from pzLib/support_blank_char_in_section_title
support blank in section title
2 parents bbf73de + 18cae19 commit c20c219

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

src/eini_parser.yrl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Nonterminals
2323
sections_with_skip_lines
2424
section
2525
title_part
26+
title_word
27+
title_words
2628
title
2729
property_with_skip_lines
2830
properties property
@@ -70,7 +72,13 @@ title_part -> title blank break : list_to_atom('$1').
7072
title_part -> title break skip_lines : list_to_atom('$1').
7173
title_part -> title blank break skip_lines : list_to_atom('$1').
7274

73-
title -> '[' word ']' : value_of('$2').
75+
title_word -> word : value_of('$1').
76+
title_word -> blank : value_of('$1').
77+
78+
title_words -> title_word : ['$1'].
79+
title_words -> title_word title_words : ['$1' | '$2'].
80+
81+
title -> '[' title_words ']' : string:strip(lists:flatten('$2'), both, $\s).
7482

7583
properties -> '$empty' : [].
7684
properties -> property_with_skip_lines properties : ['$1' | '$2'].

test/eini_tests.erl

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,44 @@ one_section_title_only_test_() ->
138138
"[title] \n"
139139
"\n"
140140
"\n"
141-
))
141+
)),
142+
%% blank char in section title
143+
?_assertEqual({ok, [
144+
{'tit le', []}
145+
]},
146+
parse("[tit le]")),
147+
?_assertEqual({ok, [
148+
{'tit le A', []}
149+
]},
150+
parse("[tit le A]")),
151+
?_assertEqual({ok, [
152+
{'tit le A', []}
153+
]},
154+
parse("[ tit le A ]")),
155+
?_assertEqual({ok, [
156+
{'tit le', []}
157+
]},
158+
parse("[ tit le]")),
159+
?_assertEqual({ok, [
160+
{'tit le', []}
161+
]},
162+
parse("[tit le ]")),
163+
?_assertEqual({ok, [
164+
{'tit le', []}
165+
]},
166+
parse("[ tit le ]")),
167+
?_assertEqual({ok, [
168+
{'title', []}
169+
]},
170+
parse("[ title ]")),
171+
?_assertEqual({ok, [
172+
{'title', []}
173+
]},
174+
parse("[ title]")),
175+
?_assertEqual({ok, [
176+
{'title', []}
177+
]},
178+
parse("[title ]"))
142179
]}.
143180

144181
one_section_title_only_syntax_error_test_() ->
@@ -457,14 +494,6 @@ syntax_error_title_test_() ->
457494
";\n"
458495
"; comment 2\n"
459496
" [title]")),
460-
%% blank char in section title
461-
?_assertMatch({error, {syntax_error, _, _Reason}},
462-
parse(
463-
"[titleA]\n"
464-
"keyA1=valueA1\n"
465-
"[tit leB]\n"
466-
"keyB1=valueB1\n"
467-
)),
468497
%% comment after title
469498
?_assertMatch({error, {syntax_error, _, ["syntax error before: ", _]}},
470499
parse("[title] ;comment")),

0 commit comments

Comments
 (0)