parser: allow root path specifications
authorJo-Philipp Wich <jo@mein.io>
Tue, 24 May 2016 15:06:50 +0000 (17:06 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 24 May 2016 15:08:38 +0000 (17:08 +0200)
All a patch specification to be just '@' or '$' - this is mainly useful when
exporting the keys of the toplevel object to the shell.

Example:

    $ echo '{ "abc": 1, "def": 2 }' | jsonpath -e 'keys=@'
    export keys='abc'\ 'def';

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
parser.y

index f77779bc72ca8f7a9597c4fdc15f6c2956a6d069..f037a6949219d174266cf4a41714e242ea9c8259 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -56,6 +56,8 @@ expr(A) ::= path(B).                                                          { A = B; }
 
 path(A) ::= T_ROOT segments(B).                                                { A = alloc_op(T_ROOT, 0, NULL, B); }
 path(A) ::= T_THIS segments(B).                                                { A = alloc_op(T_THIS, 0, NULL, B); }
+path(A) ::= T_ROOT(B).                                                         { A = B; }
+path(A) ::= T_THIS(B).                                                         { A = B; }
 
 segments(A) ::= segments(B) segment(C).                                { A = append_op(B, C); }
 segments(A) ::= segment(B).                                                    { A = B; }