commit 36c4e8526d73e6cab4acf78ec6457c9c178592f3
parent 46cb98c0bbecb439ad744f61b53eed9c70455e33
Author: weetat <wtenison@protonmail.com>
Date: Sun, 2 Mar 2025 02:13:46 +0000
Keep the colon when a command is escaped
Keywords only count as commands when followed by a colon. The peek
helpers now panic on out-of-range access instead of logging.
Diffstat:
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/fmd/lexer.go b/src/fmd/lexer.go
@@ -1,7 +1,6 @@
package fmd
import (
- "log"
"slices"
)
@@ -112,11 +111,13 @@ func (l *lexer) Exec() []token {
_tokenStr := string(l.input[_start:l.pos])
- if slices.Contains(keywords, _tokenStr) {
- if _start == 0 || l.peekTokenType(-1) != tEscape {
+ if slices.Contains(keywords, _tokenStr) && l.peekInput(1) == ':' {
+ if _start != 0 && l.peekTokenType(-1) != tEscape {
l.tokens = append(l.tokens, token{tKeyword, _tokenStr})
} else {
l.tokens = append(l.tokens, token{tWord, _tokenStr})
+ l.tokens = append(l.tokens, token{tWord, ":"})
+ l.pos += 1
}
} else if _tokenStr != "" {
l.tokens = append(l.tokens, token{tWord, _tokenStr})
@@ -129,14 +130,17 @@ func (l *lexer) Exec() []token {
return l.tokens
}
-func (l *lexer) peekTokenType(posOffset int) tokenType {
+func (l *lexer) peekInput(posOffset int) byte {
+ if l.pos+posOffset > -1 && l.pos+posOffset < len(l.input) {
+ return l.input[l.pos]
+ }
+ panic("__PANIC:peekInput:check out of bounds")
+}
+func (l *lexer) peekTokenType(posOffset int) tokenType {
_index := len(l.tokens) + posOffset
-
if posOffset < 0 && _index > -1 {
return l.tokens[_index].tType
}
-
- log.Printf("_ERROR:peekTokenType %t, %t at %d", l.pos+posOffset > -1, l.pos+posOffset < len(l.tokens), l.pos+posOffset)
- return tError
+ panic("__PANIC:peekTokenType:check out of bounds")
}