提交 b09fe43b 编写于 作者: chai2010's avatar chai2010

token: 增加 WaGo 模式的 func 关键字映射

上级 cd146ef2
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册