diff --git a/internal/token/token.go b/internal/token/token.go index 2310114c565bec74469eb0c05b47ca2b19244ecf..f5ac025cfaf5ae68ce92398676938be0a8b7ea36 100644 --- a/internal/token/token.go +++ b/internal/token/token.go @@ -224,6 +224,11 @@ var tokens = [...]string{ ENUM: "enum", } +// WaGo 关键字补丁 +var tokens_wago = map[Token]string{ + FN: "func", +} + // 中文关键字(最终通过海选选择前几名, 凹开发者最终决定) var tokens_zh = map[Token]string{ IMPORT: "导入", @@ -273,6 +278,17 @@ func (tok Token) String() string { return s } +// 返回 WaGo 关键字名字 +func (tok Token) WaGoKeykword() string { + if tok.IsKeyword() { + if x, ok := tokens_wago[tok]; ok { + return x + } + return tokens[tok] + } + return "" +} + // 返回中文关键字名字 func (tok Token) ZhKeykword() string { if tok.IsKeyword() { @@ -323,9 +339,6 @@ func init() { for k, name := range tokens_zh { keywords[name] = k } - - // TODO: import 改为 require? - keywords["require"] = IMPORT } // Lookup maps an identifier to its keyword token or IDENT (if not a keyword). @@ -337,6 +350,20 @@ func Lookup(ident string) Token { return IDENT } +// 解析 WaGo 关键字 +func LookupWaGo(ident string) Token { + if ident == "fn" { + return IDENT + } + if ident == "func" { + return FN + } + if tok, is_keyword := keywords[ident]; is_keyword { + return tok + } + return IDENT +} + // Predicates // IsLiteral returns true for tokens corresponding to identifiers