From 0a3d779e27e854bcee00c33139e27c4beac41e60 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Tue, 10 Jan 2017 03:34:03 +0700 Subject: Allow valueless nodes in the curly parser. --- src/curly_parser.mly | 2 ++ test/curly_parser_test.ml | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/curly_parser.mly b/src/curly_parser.mly index 896f5c0..df377b9 100644 --- a/src/curly_parser.mly +++ b/src/curly_parser.mly @@ -35,6 +35,8 @@ values: leaf_node: | comment = opt_comment; name = IDENTIFIER; values = values; SEMI { Vytree.make_full {default_data with values=(List.rev values); comment=comment} name []} + | comment = opt_comment; name = IDENTIFIER; SEMI (* valueless node *) + { Vytree.make_full {default_data with comment=comment} name [] } ; node: diff --git a/test/curly_parser_test.ml b/test/curly_parser_test.ml index 6e6f675..7e53065 100644 --- a/test/curly_parser_test.ml +++ b/test/curly_parser_test.ml @@ -15,6 +15,7 @@ let config_tag_top_level = "foo bar { baz quux; }" let config_with_leaf = "foo { bar baz; }" let config_with_leaf_url_unquoted = "foo { bar http://www2.example.org/foo; }" let config_with_leaf_value_quoted = "foo { bar \"foo bar\"; }" +let config_with_leaf_valueless = "foo { bar; }" (* XXX: naive use of Menhir's separated_list doesn't allow [baz; xyzzy;], perhaps we should support it too *) @@ -58,6 +59,11 @@ let test_parse_with_leaf_value_quoted test_ctxt = let config = parse config_with_leaf_value_quoted in assert_equal (CT.get_value config ["foo"; "bar"]) "foo bar" +(* Valueless leaf nodes work *) +let test_parse_with_leaf_valueless test_ctxt = + let config = parse config_with_leaf_valueless in + assert_equal (Vytree.get config ["foo"] |> Vytree.list_children) ["bar"] + (* Top level leaf nodes are not allowed *) let test_parse_top_level_leaf_node test_ctxt = assert_raises Curly_parser.Error (fun () -> parse config_leaf_top_level) @@ -102,6 +108,7 @@ let suite = "test_parse_with_leaf" >:: test_parse_with_leaf; "test_parse_with_leaf_url_unquoted" >:: test_parse_with_leaf_url_unquoted; "test_parse_with_leaf_value_quoted" >:: test_parse_with_leaf_value_quoted; + "test_parse_with_leaf_valueless" >:: test_parse_with_leaf_valueless; "test_parse_top_level_leaf_node" >:: test_parse_top_level_leaf_node; "test_parse_top_level_tag_node" >:: test_parse_top_level_tag_node; "test_parse_with_multi" >:: test_parse_with_multi; -- cgit v1.2.3