From 321d1548d46138afdb458c4646eb32ef8683d05b Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 5 Jan 2017 00:55:22 +0700 Subject: Initial implementation of the curly config parser. --- src/curly_parser.mly | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/curly_parser.mly (limited to 'src/curly_parser.mly') diff --git a/src/curly_parser.mly b/src/curly_parser.mly new file mode 100644 index 0000000..0053b56 --- /dev/null +++ b/src/curly_parser.mly @@ -0,0 +1,52 @@ +%{ + open Config_tree +%} + +%token IDENTIFIER +%token STRING +%token COMMENT +%token LEFT_BRACE +%token RIGHT_BRACE +%token LEFT_BRACKET +%token RIGHT_BRACKET +%token SEMI +%token EOF + +%start config +%% + +opt_comment: + | (* empty *) { None } + | c = COMMENT { Some c } + +value: + | v = STRING + { v } + | v = IDENTIFIER + { v } +; + +values: + | v = value { [v] } + | LEFT_BRACKET; vs = separated_nonempty_list(SEMI, value); RIGHT_BRACKET + { vs } +; + +leaf_node: + | comment = opt_comment; name = IDENTIFIER; values = values; SEMI + { Vytree.make_full {default_data with values=values; comment=comment} name []} +; + +node: + | comment = opt_comment; name = IDENTIFIER; LEFT_BRACE; children = list(node_content); RIGHT_BRACE + { let node = Vytree.make_full {default_data with comment=comment} name [] in List.fold_left Vytree.adopt node children } +; + +node_content: n = node { n } | n = leaf_node { n }; + +%public config: + ns = list(node); EOF + { + let root = make "root" in List.fold_left Vytree.adopt root ns + } +; -- cgit v1.2.3