mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 14:45:39 +00:00
Improved lexer performance!
This commit is contained in:
parent
111c6e0be1
commit
2ed5b2ff59
@ -5,9 +5,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var myPathTokeniser = newExpressionTokeniser()
|
||||
var myPathPostfixer = newExpressionPostFixer()
|
||||
|
||||
type ExpressionNode struct {
|
||||
Operation *Operation
|
||||
Lhs *ExpressionNode
|
||||
@ -19,19 +16,21 @@ type ExpressionParser interface {
|
||||
}
|
||||
|
||||
type expressionParserImpl struct {
|
||||
pathTokeniser expressionTokeniser
|
||||
pathPostFixer expressionPostFixer
|
||||
}
|
||||
|
||||
func NewExpressionParser() ExpressionParser {
|
||||
return &expressionParserImpl{}
|
||||
return &expressionParserImpl{newExpressionTokeniser(), newExpressionPostFixer()}
|
||||
}
|
||||
|
||||
func (p *expressionParserImpl) ParseExpression(expression string) (*ExpressionNode, error) {
|
||||
tokens, err := myPathTokeniser.Tokenise(expression)
|
||||
tokens, err := p.pathTokeniser.Tokenise(expression)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var Operations []*Operation
|
||||
Operations, err = myPathPostfixer.ConvertToPostfix(tokens)
|
||||
Operations, err = p.pathPostFixer.ConvertToPostfix(tokens)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ func initLexer() (*lex.Lexer, error) {
|
||||
lexer.Add([]byte(`\$[a-zA-Z_-0-9]+`), getVariableOpToken())
|
||||
lexer.Add([]byte(`as`), opToken(assignVariableOpType))
|
||||
|
||||
err := lexer.Compile()
|
||||
err := lexer.CompileNFA()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user