github.com/mithrandie/csvq@v1.18.1/lib/json/path_parser.y (about) 1 %{ 2 package json 3 %} 4 5 %union { 6 expression PathExpression 7 member ObjectPath 8 token PathToken 9 } 10 11 %type<expression> path 12 %type<member> object_member 13 14 %token<token> OBJECT_PATH 15 16 %% 17 18 path 19 : 20 { 21 $$ = ObjectPath{} 22 jplex.(*PathLexer).path = $$ 23 } 24 | object_member 25 { 26 $$ = $1 27 jplex.(*PathLexer).path = $$ 28 } 29 30 object_member 31 : OBJECT_PATH 32 { 33 $$ = ObjectPath{Name: $1.Literal} 34 } 35 | OBJECT_PATH '.' object_member 36 { 37 $$ = ObjectPath{Name: $1.Literal, Child: $3} 38 } 39 40 %% 41 42 func ParsePath(src string) (PathExpression, error) { 43 l := new(PathLexer) 44 l.Init(src) 45 jpParse(l) 46 return l.path, l.err 47 }