mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
28 lines
764 B
Go
28 lines
764 B
Go
|
package yqlib
|
||
|
|
||
|
import lex "github.com/timtadh/lexmachine"
|
||
|
|
||
|
func parseTree(tokens []*lex.Token, currentElement *PathElement, allElements []*PathElement) []*PathElement {
|
||
|
currentToken, remainingTokens := tokens[0], tokens[1:]
|
||
|
|
||
|
switch currentToken.Type {
|
||
|
case TokenIds["PATH_KEY"]:
|
||
|
currentElement.PathElementType = PathKey
|
||
|
currentElement.OperationType = None
|
||
|
currentElement.Value = currentToken.Value
|
||
|
}
|
||
|
|
||
|
if len(remainingTokens) == 0 {
|
||
|
return append(allElements, currentElement)
|
||
|
}
|
||
|
return parseTree(remainingTokens, &PathElement{}, append(allElements, currentElement))
|
||
|
|
||
|
}
|
||
|
|
||
|
func ParseTree(tokens []*lex.Token) []*PathElement {
|
||
|
if len(tokens) == 0 {
|
||
|
return make([]*PathElement, 0)
|
||
|
}
|
||
|
return parseTree(tokens, &PathElement{}, make([]*PathElement, 0))
|
||
|
}
|