summaryrefslogtreecommitdiff
path: root/lib/configuration/expression_parser.mly
diff options
context:
space:
mode:
Diffstat (limited to 'lib/configuration/expression_parser.mly')
-rw-r--r--lib/configuration/expression_parser.mly108
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/configuration/expression_parser.mly b/lib/configuration/expression_parser.mly
new file mode 100644
index 0000000..8341362
--- /dev/null
+++ b/lib/configuration/expression_parser.mly
@@ -0,0 +1,108 @@
+%token <string>IDENT
+%token L_PAREN
+%token R_PAREN
+%token L_BRACKET R_BRACKET
+%token COLUMN DOLLAR
+%token DOT
+%token <string>LITERAL
+%token <string>INTEGER
+%token COMA
+%token EOF
+%token CONCAT_OPERATOR
+
+%token <Model.Dsl.binary_operator>BINARY_OPERATOR
+%token <Model.Dsl.binary_operator>INEQUALITY_OPERATOR
+%token <Model.Dsl.binary_operator>EQUALITY_OPERATOR
+%token <Model.Dsl.binary_operator>BOOL_OPERATOR
+
+%start <string list Model.Dsl.t> path_expr
+
+%right BOOL_OPERATOR
+%right INEQUALITY_OPERATOR EQUALITY_OPERATOR
+%right CONCAT_OPERATOR BINARY_OPERATOR
+
+%%
+
+path_expr:
+ | expr_(path_, EOF) EOF { $1 }
+ | EOF { Model.Dsl.Empty }
+
+path_:
+ | COLUMN
+ path = separated_list(DOT, IDENT)
+ { Model.Dsl.ValuePath path }
+ | DOLLAR
+ path = separated_list(DOT, IDENT)
+ { Model.Dsl.ContentPath path }
+
+arguments(PATH):
+ | L_PAREN
+ expr = separated_list(COMA, expr_(PATH, COMA))
+ R_PAREN
+ { expr }
+
+group(PATH):
+ | L_BRACKET
+ expr = separated_list(COMA, expr_(PATH, COMA))
+ R_BRACKET
+ { expr }
+
+fixed(PATH):
+ | d = INTEGER
+ { Model.Dsl.Integer d }
+ | l = LITERAL
+ {
+ if String.equal String.empty l then
+ Model.Dsl.Empty
+ else
+ Model.Dsl.Literal l
+ }
+
+%inline boperator:
+ | e = BINARY_OPERATOR { e }
+ | e = INEQUALITY_OPERATOR { e }
+ | e = EQUALITY_OPERATOR { e }
+ | e = BOOL_OPERATOR { e }
+
+(* The expression evaluation receveive in parameters :
+ 1. the way to build a path, as we have two distinct ways to build them in
+ the case of externals (the external_key does not allow a table name)
+ 2. a phantom type telling wich kind of element will end the expression.
+ This can be EOF for the root expression, or COMA when inside a function.
+ This prevent merlin to optimize thoses two path, and allow more precise
+ error messages. *)
+expr_(PATH, ENDING_PHANTOM):
+ | L_PAREN
+ e = expr_(PATH, R_PAREN)
+ R_PAREN
+ { Model.Dsl.Expr e
+ }
+ |
+ p1 = expr_(PATH, ENDING_PHANTOM)
+ CONCAT_OPERATOR
+ p2 = expr_(PATH, COMA)
+ { match p2 with
+ | Model.Dsl.Function(Concat, args) -> Model.Dsl.Function(Concat, (p1::args))
+ | _ -> Model.Dsl.Function(Concat, (p1::p2::[]))
+ }
+ | p1 = expr_(PATH, ENDING_PHANTOM)
+ op = boperator
+ p2 = expr_(PATH, COMA)
+ { Model.Dsl.BOperator (op, p1, p2) }
+
+ | p1 = expr_(PATH, ENDING_PHANTOM)
+ op = EQUALITY_OPERATOR
+ p2 = group(PATH)
+ { Model.Dsl.GEquality(op, p1, p2) }
+ | p = PATH
+ { p }
+ | f = fixed(PATH)
+ { f }
+ | s = IDENT
+ args = arguments(PATH)
+ { Model.Dsl.function_of_name args s }
+
+opt_arg(PATH, SEP):
+ | expr = expr_(PATH, COMA)
+ SEP
+ { expr }