fix: don`t overlap "close"
This commit is contained in:
@@ -72,11 +72,11 @@ func ParseExpression(i *iterator.Iterator[tokenizer.Token]) (lambda.Expression,
|
|||||||
args = append(args, arg)
|
args = append(args, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
close, closeErr := i.Next()
|
closing, closingErr := i.Next()
|
||||||
if closeErr != nil {
|
if closingErr != nil {
|
||||||
return nil, fmt.Errorf("could not parse call terminating parenthesis: %w", closeErr)
|
return nil, fmt.Errorf("could not parse call terminating parenthesis: %w", closingErr)
|
||||||
} else if close.Type != tokenizer.TokenCloseParen {
|
} else if closing.Type != tokenizer.TokenCloseParen {
|
||||||
return nil, fmt.Errorf("expected call terminating parenthesis, got '%v' (column %v)", close.Value, close.Index)
|
return nil, fmt.Errorf("expected call terminating parenthesis, got '%v' (column %v)", closing.Value, closing.Index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construction.
|
// Construction.
|
||||||
|
|||||||
@@ -2,11 +2,16 @@ package tokenizer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"git.maximhutz.com/max/lambda/pkg/iterator"
|
"git.maximhutz.com/max/lambda/pkg/iterator"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func isVariable(r rune) bool {
|
||||||
|
return unicode.IsLetter(r) || unicode.IsNumber(r)
|
||||||
|
}
|
||||||
|
|
||||||
func getToken(i *iterator.Iterator[rune]) (*Token, error) {
|
func getToken(i *iterator.Iterator[rune]) (*Token, error) {
|
||||||
if i.IsDone() {
|
if i.IsDone() {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -51,29 +56,25 @@ func getToken(i *iterator.Iterator[rune]) (*Token, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, it is an atom.
|
// Otherwise, it is an atom.
|
||||||
atom := string(letter)
|
atom := strings.Builder{}
|
||||||
index := i.Index()
|
index := i.Index()
|
||||||
for {
|
for !i.IsDone() {
|
||||||
if i.IsDone() {
|
|
||||||
return &Token{
|
|
||||||
Index: index,
|
|
||||||
Type: TokenVariable,
|
|
||||||
Value: atom,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
pop, err := i.Peek()
|
pop, err := i.Peek()
|
||||||
if err != nil || unicode.IsSpace(pop) || unicode.IsPunct(pop) {
|
if err != nil || !isVariable(pop) {
|
||||||
return &Token{
|
break
|
||||||
Index: index,
|
|
||||||
Type: TokenVariable,
|
|
||||||
Value: atom,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i.Next()
|
atom.WriteRune(pop)
|
||||||
atom += string(pop)
|
if _, err := i.Next(); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &Token{
|
||||||
|
Index: index,
|
||||||
|
Type: TokenVariable,
|
||||||
|
Value: atom.String(),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTokens(input []rune) ([]Token, []error) {
|
func GetTokens(input []rune) ([]Token, []error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user