summaryrefslogtreecommitdiff
path: root/parser/tokens.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2026-01-22 11:33:32 +0100
committerMarc Vertes <mvertes@free.fr>2026-01-22 11:33:32 +0100
commit9bf668e7114bb92a0b072db5d4e092c0b8f964c4 (patch)
tree0d35e544715a3f902550af2cb4d249e8fb1e33af /parser/tokens.go
parentc922c797204069f42a7abf88500c5708f68a8e43 (diff)
chore: refactor token types to avoid mutate scanner tokens
Mutating scanner tokens or reusing scanner token attributes to store other metadata is a hack. Introduce a new parser token type with arbitrary args. The next step will be to use the arg field instead of scanner token fields.
Diffstat (limited to 'parser/tokens.go')
-rw-r--r--parser/tokens.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/parser/tokens.go b/parser/tokens.go
index ac08e2b..9ae655b 100644
--- a/parser/tokens.go
+++ b/parser/tokens.go
@@ -7,8 +7,14 @@ import (
"github.com/mvertes/parscan/scanner"
)
+// Token represents a parser token.
+type Token struct {
+ scanner.Token
+ Arg []any
+}
+
// Tokens represents slice of tokens.
-type Tokens []scanner.Token
+type Tokens []Token
func (toks Tokens) String() (s string) {
var sb strings.Builder
@@ -62,3 +68,11 @@ func (toks Tokens) SplitStart(tok lang.Token) (result []Tokens) {
toks = toks[i+1:]
}
}
+
+func newIdent(name string, pos int, arg ...any) Token {
+ return Token{Token: scanner.Token{Tok: lang.Ident, Pos: pos, Str: name}, Arg: arg}
+}
+
+func newToken(tok lang.Token, pos int, arg ...any) Token {
+ return Token{Token: scanner.Token{Tok: tok, Pos: pos}, Arg: arg}
+}