diff --git a/utils/expr_grammar/grammar.js b/utils/expr_grammar/grammar.js index 827e278ba..96ceac937 100644 --- a/utils/expr_grammar/grammar.js +++ b/utils/expr_grammar/grammar.js @@ -112,6 +112,10 @@ var grammar = { {"name": "N", "symbols": ["N$string$18", "_", {"literal":"("}, "_", "P0", "_", {"literal":","}, "_", "P0", "_", {"literal":","}, "_", "P0", "_", {"literal":")"}], "postprocess": function(d) { return window.qwc2ExpressionParserContext.getFeature(d[4], d[8], d[12]); }}, {"name": "N$string$19", "symbols": [{"literal":"g"}, {"literal":"e"}, {"literal":"t"}, {"literal":"_"}, {"literal":"f"}, {"literal":"e"}, {"literal":"a"}, {"literal":"t"}, {"literal":"u"}, {"literal":"r"}, {"literal":"e"}, {"literal":"_"}, {"literal":"b"}, {"literal":"y"}, {"literal":"_"}, {"literal":"i"}, {"literal":"d"}], "postprocess": function joiner(d) {return d.join('');}}, {"name": "N", "symbols": ["N$string$19", "_", {"literal":"("}, "_", "P0", "_", {"literal":","}, "_", "P0", "_", {"literal":")"}], "postprocess": function(d) { return window.qwc2ExpressionParserContext.getFeature(d[4], "id", d[8]); }}, + {"name": "N$string$20", "symbols": [{"literal":"C"}, {"literal":"A"}, {"literal":"S"}, {"literal":"E"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "N$string$21", "symbols": [{"literal":"E"}, {"literal":"L"}, {"literal":"S"}, {"literal":"E"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "N$string$22", "symbols": [{"literal":"E"}, {"literal":"N"}, {"literal":"D"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "N", "symbols": ["N$string$20", "_", "when_args", "_", "N$string$21", "_", "P0", "_", "N$string$22"], "postprocess": function(d) { return d[2] !== undefined ? d[2] : d[6]; }}, {"name": "N$subexpression$1", "symbols": [/[pP]/, /[iI]/], "postprocess": function(d) {return d.join(""); }}, {"name": "N", "symbols": ["N$subexpression$1"], "postprocess": function(d) { return Math.PI; }}, {"name": "N$subexpression$2", "symbols": [/[eE]/], "postprocess": function(d) {return d.join(""); }}, @@ -122,8 +126,14 @@ var grammar = { {"name": "N", "symbols": ["N$subexpression$4"], "postprocess": function(d) { return false; }}, {"name": "N$subexpression$5", "symbols": [/[tT]/, /[rR]/, /[uU]/, /[eE]/], "postprocess": function(d) {return d.join(""); }}, {"name": "N", "symbols": ["N$subexpression$5"], "postprocess": function(d) { return true; }}, - {"name": "var_args", "symbols": ["P0"], "postprocess": function(d) {return [d[0]];}}, + {"name": "var_args", "symbols": ["P0"], "postprocess": function(d) { return [d[0]]; }}, {"name": "var_args", "symbols": ["var_args", "_", {"literal":","}, "_", "P0"], "postprocess": function(d) { return [...d[0], d[4]]; }}, + {"name": "when_args$string$1", "symbols": [{"literal":"W"}, {"literal":"H"}, {"literal":"E"}, {"literal":"N"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "when_args$string$2", "symbols": [{"literal":"T"}, {"literal":"H"}, {"literal":"E"}, {"literal":"N"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "when_args", "symbols": ["when_args$string$1", "_", "P0", "_", "when_args$string$2", "_", "P0"], "postprocess": function(d) { return d[2] ? d[6] : undefined; }}, + {"name": "when_args$string$3", "symbols": [{"literal":"W"}, {"literal":"H"}, {"literal":"E"}, {"literal":"N"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "when_args$string$4", "symbols": [{"literal":"T"}, {"literal":"H"}, {"literal":"E"}, {"literal":"N"}], "postprocess": function joiner(d) {return d.join('');}}, + {"name": "when_args", "symbols": ["when_args", "_", "when_args$string$3", "_", "P0", "_", "when_args$string$4", "_", "P0"], "postprocess": function(d) { return d[0] !== undefined ? d[0] : (d[4] ? d[8] : undefined); }}, {"name": "float", "symbols": ["int", {"literal":"."}, "int"], "postprocess": function(d) { return parseFloat(d[0] + d[1] + d[2])}}, {"name": "float", "symbols": ["int"], "postprocess": function(d) { return parseInt(d[0])}}, {"name": "int$ebnf$1", "symbols": [/[0-9]/]}, diff --git a/utils/expr_grammar/grammar.ne b/utils/expr_grammar/grammar.ne index e97b3cbf5..24dd7a67e 100644 --- a/utils/expr_grammar/grammar.ne +++ b/utils/expr_grammar/grammar.ne @@ -73,15 +73,19 @@ N -> float {% id %} | "attribute" _ "(" _ P0 _ "," _ P0 _ ")" {% function(d) { return d[4]?.properties?.[d[8]] ?? null; } %} | "get_feature" _ "(" _ P0 _ "," _ P0 _ "," _ P0 _ ")" {% function(d) { return window.qwc2ExpressionParserContext.getFeature(d[4], d[8], d[12]); } %} | "get_feature_by_id" _ "(" _ P0 _ "," _ P0 _ ")" {% function(d) { return window.qwc2ExpressionParserContext.getFeature(d[4], "id", d[8]); } %} + | "CASE" _ when_args _ "ELSE" _ P0 _ "END" {% function(d) { return d[2] !== undefined ? d[2] : d[6]; } %} | "PI"i {% function(d) { return Math.PI; } %} | "E"i {% function(d) { return Math.E; } %} | "NULL"i {% function(d) { return null; } %} | "FALSE"i {% function(d) { return false; } %} | "TRUE"i {% function(d) { return true; } %} -var_args -> P0 {% function(d) {return [d[0]];} %} +var_args -> P0 {% function(d) { return [d[0]]; } %} var_args -> var_args _ "," _ P0 {% function(d) { return [...d[0], d[4]]; } %} +when_args -> "WHEN" _ P0 _ "THEN" _ P0 {% function(d) { return d[2] ? d[6] : undefined; } %} +when_args -> when_args _ "WHEN" _ P0 _ "THEN" _ P0 {% function(d) { return d[0] !== undefined ? d[0] : (d[4] ? d[8] : undefined); } %} + # I use `float` to basically mean a number with a decimal point in it float -> int "." int {% function(d) { return parseFloat(d[0] + d[1] + d[2])} %}