mirror of
https://gitee.com/wa-lang/wa.git
synced 2025-12-06 17:19:15 +08:00
实验性支持中文关键字的乱序输入
This commit is contained in:
@@ -335,10 +335,14 @@ func (op Token) Precedence() int {
|
||||
return LowestPrec
|
||||
}
|
||||
|
||||
var keywords map[string]Token
|
||||
var (
|
||||
keywords map[string]Token
|
||||
keywords_中文乱序 map[string]Token
|
||||
)
|
||||
|
||||
func init() {
|
||||
keywords = make(map[string]Token)
|
||||
keywords_中文乱序 = make(map[string]Token)
|
||||
|
||||
for i := keyword_beg + 1; i < keyword_end; i++ {
|
||||
keywords[tokens[i]] = i
|
||||
@@ -347,6 +351,20 @@ func init() {
|
||||
for i := wz_keyword_beg + 1; i < wz_keyword_end; i++ {
|
||||
keywords[tokens[i]] = i
|
||||
}
|
||||
|
||||
// 中文乱序的关键字
|
||||
for i := wz_keyword_beg + 1; i < wz_keyword_end; i++ {
|
||||
keyword := 中文字符串逆序(tokens[i])
|
||||
keywords_中文乱序[keyword] = i
|
||||
}
|
||||
}
|
||||
|
||||
func 中文字符串逆序(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
||||
// Lookup maps an identifier to its keyword token or IDENT (if not a keyword).
|
||||
@@ -354,6 +372,9 @@ func Lookup(ident string) Token {
|
||||
if tok, is_keyword := keywords[ident]; is_keyword {
|
||||
return tok
|
||||
}
|
||||
if tok, is_keyword := keywords_中文乱序[ident]; is_keyword {
|
||||
return tok
|
||||
}
|
||||
return IDENT
|
||||
}
|
||||
|
||||
@@ -369,6 +390,17 @@ func LookupEx(ident string, useWzMode bool) Token {
|
||||
}
|
||||
}
|
||||
}
|
||||
if tok, is_keyword := keywords_中文乱序[ident]; is_keyword {
|
||||
if useWzMode {
|
||||
if tok.IsWzKeyword() {
|
||||
return tok
|
||||
}
|
||||
} else {
|
||||
if tok.IsKeyword() {
|
||||
return tok
|
||||
}
|
||||
}
|
||||
}
|
||||
return IDENT
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# 版本日志
|
||||
|
||||
- dev (2025-??-??)
|
||||
- 完善中文版的支持, 修复中英文错误接口不能互通的问题
|
||||
- 标准库增加中文版的“万国码/码八方”包
|
||||
- 实验性支持中文关键字的乱序输入
|
||||
- v1.4.0 (2025-11-10)
|
||||
- 修复 `wa init` 命令会卡死的问题
|
||||
- 凹语言中文版技术平权继续, 双向导出了错误接口, 增加了多个中文包
|
||||
|
||||
Reference in New Issue
Block a user