From 830e7c5d27d161b91402414e6ecd49f1ed818bfb Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 27 Mar 2026 08:48:05 +0100 Subject: Initial commit --- lib/configuration/expression_parser.mly | 108 ++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 lib/configuration/expression_parser.mly (limited to 'lib/configuration/expression_parser.mly') 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 IDENT +%token L_PAREN +%token R_PAREN +%token L_BRACKET R_BRACKET +%token COLUMN DOLLAR +%token DOT +%token LITERAL +%token INTEGER +%token COMA +%token EOF +%token CONCAT_OPERATOR + +%token BINARY_OPERATOR +%token INEQUALITY_OPERATOR +%token EQUALITY_OPERATOR +%token BOOL_OPERATOR + +%start 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 } -- cgit v1.2.3