Skip to content

Commit

Permalink
Merge pull request #18 from jimdigriz/nested
Browse files Browse the repository at this point in the history
support nested properties
  • Loading branch information
Evgeny Bob authored May 3, 2021
2 parents c20c219 + 38a255a commit 6fcbb5d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/eini_parser.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Nonterminals
title_words
title
property_with_skip_lines
properties property
properties property_base property
properties_nested property_nested
key_part
values single_value
skip_lines
Expand Down Expand Up @@ -86,9 +87,18 @@ properties -> property_with_skip_lines properties : ['$1' | '$2'].
property_with_skip_lines -> property : '$1'.
property_with_skip_lines -> property skip_lines : '$1'.

property -> key_part '=' values break :
property_base -> key_part '=' values break :
{list_to_atom(value_of('$1')), strip_values('$3')}.

property -> property_base : '$1'.
property -> key_part '=' break properties_nested :
{list_to_atom(value_of('$1')), '$4'}.

properties_nested -> property_nested : ['$1'].
properties_nested -> property_nested properties_nested : ['$1' | '$2'].

property_nested -> blank property_base : '$2'.

key_part -> word : '$1'.
key_part -> word blank : '$1'.
key_part -> blank word : '$2'.
Expand All @@ -98,7 +108,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
14 changes: 14 additions & 0 deletions test/eini_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,20 @@ one_section_title_and_one_prop_test_() ->
"[title] \n"
"key1= value1 \n"
)),
%% nested properties: https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html
?_assertEqual({ok, [
{title, [{key1,[{key11,<<"value11">>},{key12,<<"value12">>},{key13,<<"value13">>},{key14,<<"value14">>}]},{key2,<<"value2">>}]}
]},
parse(
"[title]\n"
"key1 =\n"
" key11=value11\n"
" key12 =value12\n"
" key13= value13\n"
" key14 = value14\n"
"key2=value2\n"
)),

%% value has characters which can not used in titles or keys
?_assertEqual({ok, [
{title, [{key1, <<"value1$% '""#!+*=@/:+">>}]}
Expand Down

0 comments on commit 6fcbb5d

Please sign in to comment.