| 1 | package parserscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/ |
| 2 | |
| 3 | import ( |
| 4 | "github.com/tomwright/dasel/v3/selector/astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/" |
| 5 | "github.com/tomwright/dasel/v3/selector/lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/" |
| 6 | ) |
| 7 | |
| 8 | // parseFollowingSymbols deals with the expressions following symbols/variables, e.g. |
| 9 | // $this[0][1]['name'] |
| 10 | // foo['bar']['baz'][1] |
| 11 | func parseFollowingSymbolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/parseFollowingSymbol().(p *Parserscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#, prev astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.Exprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/Expr#) (astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.Exprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/Expr#, error) { |
| 12 | res := astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.Expressionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/Expressions#{prev} |
| 13 | |
| 14 | for p.hasTokenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#hasToken().() { |
| 15 | if p.currentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#current().().IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.Spreadscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Spread.) { |
| 16 | p.advanceNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#advanceN().(1) |
| 17 | res = append(res, astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.SpreadExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/SpreadExpr#{}) |
| 18 | continue |
| 19 | } |
| 20 | |
| 21 | // String based indexes |
| 22 | if p.currentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#current().().IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.OpenBracketscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/OpenBracket.) { |
| 23 | |
| 24 | if p.peekNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#peekN().(1).IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.Spreadscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Spread.) && p.peekNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#peekN().(2).IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.CloseBracketscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/CloseBracket.) { |
| 25 | p.advanceNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#advanceN().(3) |
| 26 | res = append(res, astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.SpreadExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/SpreadExpr#{}) |
| 27 | continue |
| 28 | } |
| 29 | |
| 30 | if p.peekNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#peekN().(1).IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.Starscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Star.) && p.peekNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#peekN().(2).IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.CloseBracketscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/CloseBracket.) { |
| 31 | p.advanceNscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#advanceN().(3) |
| 32 | res = append(res, astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.SpreadExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/SpreadExpr#{}) |
| 33 | continue |
| 34 | } |
| 35 | |
| 36 | e, err := parseIndexSquareBracketsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/parseIndexSquareBrackets().(p, false) |
| 37 | if err != nil { |
| 38 | return nil, err |
| 39 | } |
| 40 | switch ex := e.(type) { |
| 41 | case astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.RangeExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/RangeExpr#: |
| 42 | res = append(res, ex) |
| 43 | case astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.IndexExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/IndexExpr#: |
| 44 | // Convert this to a property expr. This property executor deals |
| 45 | // with maps + arrays. |
| 46 | res = append(res, astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.PropertyExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/PropertyExpr#{ |
| 47 | Propertyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/PropertyExpr#Property.: ex.Indexscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/IndexExpr#Index., |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | //e, err := p.parseExpressionsFromTo(lexer.OpenBracket, lexer.CloseBracket, nil, true, bpDefault) |
| 52 | //if err != nil { |
| 53 | // return nil, err |
| 54 | //} |
| 55 | //res = append(res, ast.PropertyExpr{ |
| 56 | // Property: e, |
| 57 | //}) |
| 58 | continue |
| 59 | } |
| 60 | |
| 61 | break |
| 62 | } |
| 63 | |
| 64 | return astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.ChainExprsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/ChainExprs().(res...), nil |
| 65 | } |
| 66 | |
| 67 | func parseSymbolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/parseSymbol().(p *Parserscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#, withFollowing bool, allowFunc bool) (astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.Exprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/Expr#, error) { |
| 68 | token := p.currentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#current().() |
| 69 | |
| 70 | next := p.peekscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#peek().() |
| 71 | |
| 72 | // Handle functions |
| 73 | if next.IsKindscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#IsKind().(lexerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/.OpenParenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/OpenParen.) && allowFunc { |
| 74 | return parseFuncscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/parseFunc().(p) |
| 75 | } |
| 76 | |
| 77 | prop := astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.PropertyExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/PropertyExpr#{ |
| 78 | Propertyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/PropertyExpr#Property.: astscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/.StringExprscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/StringExpr#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/ast`/StringExpr#Value.: token.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/lexer`/Token#Value.}, |
| 79 | } |
| 80 | |
| 81 | p.advancescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/Parser#advance().() |
| 82 | |
| 83 | if withFollowing { |
| 84 | res, err := parseFollowingSymbolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/selector/parser`/parseFollowingSymbol().(p, prop) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | return res, nil |
| 89 | } |
| 90 | |
| 91 | return prop, nil |
| 92 | } |