Improved lexer performance!

This commit is contained in:
Mike Farah 2021-02-25 16:47:55 +11:00
parent 111c6e0be1
commit 2ed5b2ff59
2 changed files with 6 additions and 7 deletions

View File

@ -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
}

View File

@ -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
}