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