Skip to content

Commit 62cd2d4

Browse files
committed
Refactor lexer
1 parent bf14f7f commit 62cd2d4

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

expr_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -2663,3 +2663,11 @@ func TestIssue_integer_truncated_by_compiler(t *testing.T) {
26632663
_, err = expr.Compile("fn(256)", expr.Env(env))
26642664
require.Error(t, err)
26652665
}
2666+
2667+
func TestExpr_crash(t *testing.T) {
2668+
content, err := os.ReadFile("testdata/crash.txt")
2669+
require.NoError(t, err)
2670+
2671+
_, err = expr.Compile(string(content))
2672+
require.Error(t, err)
2673+
}

parser/lexer/lexer.go

-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func Lex(source file.Source) ([]Token, error) {
3030
type lexer struct {
3131
source file.Source
3232
tokens []Token
33-
backed bool
3433
start, end int
3534
err *file.Error
3635
}
@@ -42,7 +41,6 @@ func (l *lexer) commit() {
4241
}
4342

4443
func (l *lexer) next() rune {
45-
l.backed = false
4644
if l.end >= len(l.source) {
4745
l.end++
4846
return eof
@@ -59,10 +57,6 @@ func (l *lexer) peek() rune {
5957
}
6058

6159
func (l *lexer) backup() {
62-
if l.backed {
63-
panic(fmt.Sprintf("lexer: cannot backup twice: %q", l.source[l.start:l.end]))
64-
}
65-
l.backed = true
6660
l.end--
6761
}
6862

testdata/crash.txt

6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)