summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-01-05 00:55:22 +0700
committerDaniil Baturin <daniil@baturin.org>2017-01-05 00:55:22 +0700
commit321d1548d46138afdb458c4646eb32ef8683d05b (patch)
tree85baed4c181e1424a2606e6ce8d4d6524d3350e8
parent1710c38d8a174698e5c68d876c8afb8dd91c2d4f (diff)
downloadvyconf-321d1548d46138afdb458c4646eb32ef8683d05b.tar.gz
vyconf-321d1548d46138afdb458c4646eb32ef8683d05b.zip
Initial implementation of the curly config parser.
-rw-r--r--_oasis10
-rw-r--r--_tags93
-rw-r--r--src/curly_lexer.mll62
-rw-r--r--src/curly_parser.mly52
4 files changed, 216 insertions, 1 deletions
diff --git a/_oasis b/_oasis
index f0f45d2..0d3d539 100644
--- a/_oasis
+++ b/_oasis
@@ -38,6 +38,16 @@ Library "value_checker"
FindlibParent: vyconf
BuildDepends: pcre
+Library "curly_lexer"
+ Path: src
+ Modules: Curly_lexer
+ FindlibParent: vyconf
+
+Library "curly_parser"
+ Path: src
+ Modules: Curly_parser
+ FindlibParent: vyconf
+
Library "util"
Path: src
Modules: Util
diff --git a/_tags b/_tags
index 9dc6d49..c8cb0b2 100644
--- a/_tags
+++ b/_tags
@@ -1,8 +1,9 @@
# OASIS_START
-# DO NOT EDIT (digest: e1fbaa814f6e84974fc385e5d815bf45)
+# DO NOT EDIT (digest: 11f71f9fb0db5e0d6e22aa91f3d802d1)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
+true: annot, bin_annot
<**/.svn>: -traverse
<**/.svn>: not_hygienic
".bzr": -traverse
@@ -13,8 +14,98 @@
".git": not_hygienic
"_darcs": -traverse
"_darcs": not_hygienic
+# Library vyconf
+"src/vyconf.cmxs": use_vyconf
+# Library vytree
+"src/vytree.cmxs": use_vytree
+# Library reference_tree
+"src/reference_tree.cmxs": use_reference_tree
+# Library config_tree
+"src/config_tree.cmxs": use_config_tree
+# Library value_checker
+"src/value_checker.cmxs": use_value_checker
+<src/*.ml{,i,y}>: pkg_pcre
+# Library curly_lexer
+"src/curly_lexer.cmxs": use_curly_lexer
+# Library curly_parser
+"src/curly_parser.cmxs": use_curly_parser
+# Library util
+"src/util.cmxs": use_util
+<src/*.ml{,i,y}>: pkg_xml-light
+# Library session
+"src/session.cmxs": use_session
+# Library vyconf_config
+"src/vyconf_config.cmxs": use_vyconf_config
+<src/*.ml{,i,y}>: pkg_ppx_deriving.show
+# Library directories
+"src/directories.cmxs": use_directories
+# Library message
+"src/message.cmxs": use_message
+<src/*.ml{,i,y}>: pkg_ppx_deriving_yojson
+# Library startup
+"src/startup.cmxs": use_startup
+<src/*.ml{,i,y}>: pkg_lwt.log
# Executable vyconfd
+<src/vyconfd.{native,byte}>: pkg_fileutils
+<src/vyconfd.{native,byte}>: pkg_lwt
+<src/vyconfd.{native,byte}>: pkg_lwt.ppx
+<src/vyconfd.{native,byte}>: pkg_lwt.unix
+<src/vyconfd.{native,byte}>: pkg_ppx_deriving.runtime
+<src/vyconfd.{native,byte}>: pkg_ppx_deriving_yojson.runtime
+<src/vyconfd.{native,byte}>: pkg_toml
+<src/vyconfd.{native,byte}>: use_vyconf
+<src/*.ml{,i,y}>: pkg_fileutils
+<src/*.ml{,i,y}>: pkg_lwt
+<src/*.ml{,i,y}>: pkg_lwt.ppx
+<src/*.ml{,i,y}>: pkg_lwt.unix
+<src/*.ml{,i,y}>: pkg_ppx_deriving.runtime
+<src/*.ml{,i,y}>: pkg_ppx_deriving_yojson.runtime
+<src/*.ml{,i,y}>: pkg_toml
+<src/*.ml{,i,y}>: use_vyconf
+# Executable vytree_test
+<test/vytree_test.{native,byte}>: pkg_oUnit
+<test/vytree_test.{native,byte}>: use_vyconf
+# Executable reference_tree_test
+<test/reference_tree_test.{native,byte}>: pkg_oUnit
+<test/reference_tree_test.{native,byte}>: pkg_pcre
+<test/reference_tree_test.{native,byte}>: pkg_xml-light
+<test/reference_tree_test.{native,byte}>: use_vyconf
+# Executable config_tree_test
+<test/config_tree_test.{native,byte}>: pkg_oUnit
+<test/config_tree_test.{native,byte}>: use_vyconf
+# Executable vylist_test
+<test/vylist_test.{native,byte}>: pkg_oUnit
+<test/vylist_test.{native,byte}>: use_vyconf
+# Executable value_checker_test
+<test/value_checker_test.{native,byte}>: pkg_oUnit
+<test/value_checker_test.{native,byte}>: pkg_pcre
+<test/value_checker_test.{native,byte}>: use_vyconf
+# Executable util_test
+<test/util_test.{native,byte}>: pkg_oUnit
+<test/util_test.{native,byte}>: pkg_xml-light
+<test/util_test.{native,byte}>: use_vyconf
+# Executable vyconf_config_test
+<test/vyconf_config_test.{native,byte}>: pkg_oUnit
+<test/vyconf_config_test.{native,byte}>: pkg_ppx_deriving.runtime
+<test/vyconf_config_test.{native,byte}>: pkg_toml
+<test/vyconf_config_test.{native,byte}>: use_vyconf
+<test/*.ml{,i,y}>: pkg_ppx_deriving.runtime
+<test/*.ml{,i,y}>: pkg_toml
+# Executable session_test
+<test/session_test.{native,byte}>: pkg_fileutils
+<test/session_test.{native,byte}>: pkg_oUnit
+<test/session_test.{native,byte}>: pkg_pcre
+<test/session_test.{native,byte}>: pkg_xml-light
+<test/session_test.{native,byte}>: use_vyconf
+<test/*.ml{,i,y}>: pkg_fileutils
+<test/*.ml{,i,y}>: pkg_oUnit
+<test/*.ml{,i,y}>: pkg_pcre
+<test/*.ml{,i,y}>: pkg_xml-light
+# Executable vytree_load_test
+<test/vytree_load_test.{native,byte}>: use_vyconf
+<test/*.ml{,i,y}>: use_vyconf
# OASIS_STOP
true: strict_sequence
true: bin_annot
+true: use_menhir, explain
diff --git a/src/curly_lexer.mll b/src/curly_lexer.mll
new file mode 100644
index 0000000..8086648
--- /dev/null
+++ b/src/curly_lexer.mll
@@ -0,0 +1,62 @@
+{
+
+open Curly_parser
+
+exception Error of string
+
+}
+
+rule token = parse
+| [' ' '\t' '\n']
+ { token lexbuf }
+| '{'
+ { LEFT_BRACE }
+| '}'
+ { RIGHT_BRACE }
+| '['
+ { LEFT_BRACKET }
+| ']'
+ { RIGHT_BRACKET }
+| ';'
+ { SEMI }
+| ['a' - 'z' 'A' - 'Z' '0' - '9' '-' '.' ]+ as s
+ { IDENTIFIER s}
+| eof
+ { EOF }
+| '"'
+ { read_string (Buffer.create 16) lexbuf }
+| "//" [^ '\n']+ '\n'
+ { Lexing.new_line lexbuf ; token lexbuf }
+| "/*"
+ { read_comment (Buffer.create 16) lexbuf }
+| _
+{ raise (Error (Printf.sprintf "At offset %d: unexpected character.\n" (Lexing.lexeme_start lexbuf))) }
+
+and read_string buf =
+ parse
+ | '"' { STRING (Buffer.contents buf) }
+ | '\\' '/' { Buffer.add_char buf '/'; read_string buf lexbuf }
+ | '\\' '\\' { Buffer.add_char buf '\\'; read_string buf lexbuf }
+ | '\\' 'b' { Buffer.add_char buf '\b'; read_string buf lexbuf }
+ | '\\' 'f' { Buffer.add_char buf '\012'; read_string buf lexbuf }
+ | '\\' 'n' { Buffer.add_char buf '\n'; read_string buf lexbuf }
+ | '\\' 'r' { Buffer.add_char buf '\r'; read_string buf lexbuf }
+ | '\\' 't' { Buffer.add_char buf '\t'; read_string buf lexbuf }
+ | '\\' '\'' { Buffer.add_char buf '\''; read_string buf lexbuf }
+ | '\\' '"' { Buffer.add_char buf '"'; read_string buf lexbuf }
+ | '\n' { Lexing.new_line lexbuf; Buffer.add_char buf '\n'; read_string buf lexbuf }
+ | [^ '"' '\\']+
+ { Buffer.add_string buf (Lexing.lexeme lexbuf);
+ read_string buf lexbuf
+ }
+ | _ { raise (Error (Printf.sprintf "Illegal string character: %s" (Lexing.lexeme lexbuf))) }
+ | eof { raise (Error ("String is not terminated")) }
+
+and read_comment buf =
+ parse
+ | "*/"
+ { COMMENT (Buffer.contents buf) }
+ | _
+ { Buffer.add_string buf (Lexing.lexeme lexbuf);
+ read_comment buf lexbuf
+ }
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 <string> IDENTIFIER
+%token <string> STRING
+%token <string> COMMENT
+%token LEFT_BRACE
+%token RIGHT_BRACE
+%token LEFT_BRACKET
+%token RIGHT_BRACKET
+%token SEMI
+%token EOF
+
+%start <Config_tree.t> 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
+ }
+;