commit f3251c218f13961bf386c10feffee09ab1be4fa5
parent 36c4e8526d73e6cab4acf78ec6457c9c178592f3
Author: weetat <wtenison@protonmail.com>
Date: Sun, 2 Mar 2025 02:19:25 +0000
Fix out-of-range token peek at start of input
Guard the escape lookback when pos is 0, and restore the start-of-input
check the previous commit inverted.
Diffstat:
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/fmd/lexer.go b/src/fmd/lexer.go
@@ -80,7 +80,7 @@ func (l *lexer) Exec() []token {
l.tokens = append(l.tokens, token{tTab, "\t"})
l.pos++
case _currentSymbol == '\\':
- if l.peekTokenType(-1) == tEscape {
+ if l.pos != 0 && l.peekTokenType(-1) == tEscape {
l.tokens = append(l.tokens, token{tWord, "\\"})
} else {
l.tokens = append(l.tokens, token{tEscape, "\\"})
@@ -112,7 +112,7 @@ func (l *lexer) Exec() []token {
_tokenStr := string(l.input[_start:l.pos])
if slices.Contains(keywords, _tokenStr) && l.peekInput(1) == ':' {
- if _start != 0 && l.peekTokenType(-1) != tEscape {
+ if _start == 0 || l.peekTokenType(-1) != tEscape {
l.tokens = append(l.tokens, token{tKeyword, _tokenStr})
} else {
l.tokens = append(l.tokens, token{tWord, _tokenStr})
@@ -124,7 +124,6 @@ func (l *lexer) Exec() []token {
}
}
}
-
}
return l.tokens