diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-02-04 18:36:07 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-02-04 18:45:21 +0100 |
commit | c7e938d6582a436dddc938539e72dd1320625c54 (patch) | |
tree | ae5ed1e3ee150ea8936433fed04f6a2dd03ac2d0 /parser.y | |
parent | cd6629fc75787cbfcbec12282bd738373bc46ac6 (diff) | |
download | jsonpath-c7e938d6582a436dddc938539e72dd1320625c54.tar.gz |
implement POSIX regexp support
Introduce a new operator `~` and new `/.../eis` regular expression syntax.
This allows filtering by regular expression, e.g.
jsonfilter -s '[ "foo", "bar", "baz" ]' -e '$[@ ~ /^b/]'
... would yield the values `bar` and `baz`.
Possible regular expression modifiers are:
- `e` ... enable extended POSIX regular expressions
- `i` ... perform case insensitive matches
- `s` ... let ranges and `.` match the newline character
A regular expression literal may occur on the left or the right side of
the `~` operator, but not on both.
In case neither side of the `~` operator is a regular expression, the right
side will be treated as regular expression pattern. Non-string values are
converted to their string representation before performing matching.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -20,7 +20,7 @@ %left T_AND. %left T_OR. %left T_UNION. -%nonassoc T_EQ T_NE T_GT T_GE T_LT T_LE. +%nonassoc T_EQ T_NE T_GT T_GE T_LT T_LE T_MATCH. %right T_NOT. %include { @@ -87,11 +87,13 @@ cmp_exp(A) ::= unary_exp(B) T_GT unary_exp(C). { A = alloc_op(T_GT, 0, NULL, B, cmp_exp(A) ::= unary_exp(B) T_GE unary_exp(C). { A = alloc_op(T_GE, 0, NULL, B, C); } cmp_exp(A) ::= unary_exp(B) T_EQ unary_exp(C). { A = alloc_op(T_EQ, 0, NULL, B, C); } cmp_exp(A) ::= unary_exp(B) T_NE unary_exp(C). { A = alloc_op(T_NE, 0, NULL, B, C); } +cmp_exp(A) ::= unary_exp(B) T_MATCH unary_exp(C). { A = alloc_op(T_MATCH, 0, NULL, B, C); } cmp_exp(A) ::= unary_exp(B). { A = B; } unary_exp(A) ::= T_BOOL(B). { A = B; } unary_exp(A) ::= T_NUMBER(B). { A = B; } unary_exp(A) ::= T_STRING(B). { A = B; } +unary_exp(A) ::= T_REGEXP(B). { A = B; } unary_exp(A) ::= T_WILDCARD(B). { A = B; } unary_exp(A) ::= T_POPEN or_exps(B) T_PCLOSE. { A = B; } unary_exp(A) ::= T_NOT unary_exp(B). { A = alloc_op(T_NOT, 0, NULL, B); } |