Skip to content

Commit

Permalink
Add support for regexp_match expressions to grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jun 13, 2024
1 parent 131d8ad commit c50157d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
42 changes: 22 additions & 20 deletions utils/expr_grammar/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions utils/expr_grammar/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ N -> float {% id %}
| "ln" _ "(" _ P0 _ ")" {% function(d) { return Math.log(d[4]); } %}
| "atan2" _ "(" _ P0 _ "," _ P0 _ ")" {% function(d) { return Math.atan2(d[4], d[8]); } %}
| "pow" _ "(" _ P0 _ "," _ P0 _ ")" {% function(d) { return Math.pow(d[4], d[8]); } %}
| "CASE" _ when_args _ "ELSE" _ P0 _ "END" {% function(d) { return d[2] !== undefined ? d[2] : d[6]; } %}
| "coalesce" _ "(" _ var_args _ ")" {% function(d) { return d[4].find(x => x !== null) ?? null; } %}
| "if" _ "(" _ P0 _ "," _ P0 _ "," _ P0 _ ")" {% function(d) { return d[4] ? d[8] : d[12]; } %}
| "nullif" _ "(" _ P0 _ "," _ P0 _ ")" {% function(d) { return d[4] === d[8] ? null : d[4]; } %}
| "coalesce" _ "(" _ var_args _ ")" {% function(d) { return d[4].find(x => x !== null) ?? null; } %}
| "regexp_match" _ "(" _ P0 _ "," _ P0 _ ")" {% function(d) { return d[4].search(new RegExp(d[8])) + 1; } %}
| "attribute" _ "(" _ P0 _ ")" {% function(d) { return window.qwc2ExpressionParserContext.feature.properties?.[d[4]] ?? null; } %}
| "current_value" _ "(" _ P0 _ ")" {% function(d) { return window.qwc2ExpressionParserContext.feature.properties?.[d[4]] ?? null; } %}
| "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; } %}
Expand Down

0 comments on commit c50157d

Please sign in to comment.