1
0
mirror of https://github.com/kataras/iris.git synced 2026-07-30 16:09:51 +00:00

feat(token): add String() method to token Type

Add String() method to the token Type that returns the human-readable name
of the token (e.g., "LBRACE" for '{'), with fallback to numeric value for
unknown types. Also add typeNames map for token type name lookups.
This commit is contained in:
Gerasimos (Makis) Maropoulos
2026-07-27 12:34:01 +03:00
parent 5082f0ac7f
commit 7bedaf55a0
3 changed files with 29 additions and 3 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ require (
github.com/iris-contrib/schema v0.0.6
github.com/json-iterator/go v1.1.12
github.com/kataras/blocks v0.0.8
github.com/kataras/golog v0.1.15
github.com/kataras/golog v0.1.12
github.com/kataras/jwt v0.1.17
github.com/kataras/neffos v0.0.24
github.com/kataras/pio v0.0.13
Generated
+2 -2
View File
@@ -95,8 +95,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kataras/blocks v0.0.8 h1:MrpVhoFTCR2v1iOOfGng5VJSILKeZZI+7NGfxEh3SUM=
github.com/kataras/blocks v0.0.8/go.mod h1:9Jm5zx6BB+06NwA+OhTbHW1xkMOYxahnqTN5DveZ2Yg=
github.com/kataras/golog v0.1.15 h1:gDNOENbbn+6me98UW1f9Cs5MRUlAkabnNvmgLFM58Xw=
github.com/kataras/golog v0.1.15/go.mod h1:Ozu1TDa+OKC7fFe7OG64In71yLxjda+6kPl+Rg3v1hA=
github.com/kataras/golog v0.1.12 h1:Bu7I/G4ilJlbfzjmU39O9N+2uO1pBcMK045fzZ4ytNg=
github.com/kataras/golog v0.1.12/go.mod h1:wrGSbOiBqbQSQznleVNX4epWM8rl9SJ/rmEacl0yqy4=
github.com/kataras/jwt v0.1.17 h1:dYjemzcdYqA4ylwq9/56MslCr/pNOyVUZ2bl3hYNHgc=
github.com/kataras/jwt v0.1.17/go.mod h1:HUnU5HDBCDanVF8zrPVSE2VK8HicospKefZDD4DzOKU=
github.com/kataras/neffos v0.0.24 h1:S3lHqJopCfXN285VdlbGeOj+Id83u4xdQKToa+w1vW0=
+26
View File
@@ -1,8 +1,20 @@
package token
import "strconv"
// Type is a specific type of int which describes the symbols.
type Type int
// String returns the name of the token type, e.g. "LBRACE" for the '{' symbol.
// It returns the numeric value of an unknown type as it is.
func (t Type) String() string {
if name, ok := typeNames[t]; ok {
return name
}
return strconv.Itoa(int(t))
}
// Token describes the letter(s) or symbol, is a result of the lexer.
type Token struct {
Type Type
@@ -37,6 +49,20 @@ const (
INT // 42
)
var typeNames = map[Type]string{
EOF: "EOF",
ILLEGAL: "ILLEGAL",
LBRACE: "LBRACE",
RBRACE: "RBRACE",
COLON: "COLON",
LPAREN: "LPAREN",
RPAREN: "RPAREN",
COMMA: "COMMA",
IDENT: "IDENT",
ELSE: "ELSE",
INT: "INT",
}
var keywords = map[string]Type{
"else": ELSE,
}