使用规范中的 EBNF 语法:
upper ::= ‘A’ | ... | ‘Z’ | ‘$’ | ‘_’ and Unicode category Lu
lower ::= ‘a’ | ... | ‘z’ and Unicode category Ll
letter ::= upper | lower and Unicode categories Lo, Lt, Nl
digit ::= ‘0’ | ... | ‘9’
opchar ::= “all other characters in \u0020-007F and Unicode
categories Sm, So except parentheses ([]) and periods”
但也考虑到词法语法的最开始定义:
Parentheses ‘(’ | ‘)’ | ‘[’ | ‘]’ | ‘{’ | ‘}’.
Delimiter characters ‘‘’ | ‘’’ | ‘"’ | ‘.’ | ‘;’ | ‘,’
这是我想出的。通过消除\u0020-007F 范围内的工作,消除字母、数字、括号和分隔符,我们有 opchar...(鼓声):
! # % & * + - / : < = > ? @ \ ^ | ~
还有Sm 和So - 括号和句点除外。
(编辑:在此处添加有效示例:)。总之,这里有一些突出所有案例的有效示例 - 注意 REPL 中的 \,我不得不以 \\ 转义:
val !#%&*+-/:<=>?@\^|~ = 1 // all simple opchars
val simpleName = 1
val withDigitsAndUnderscores_ab_12_ab12 = 1
val wordEndingInOpChars_!#%&*+-/:<=>?@\^|~ = 1
val !^©® = 1 // opchars ans symbols
val abcαβγ_!^©® = 1 // mixing unicode letters and symbols
注1:
我找到了这个 Unicode category index 来找出Lu, Ll, Lo, Lt, Nl:
- Lu(大写字母)
- Ll(小写字母)
- Lo(其他字母)
- Lt(标题)
- Nl(字母数字,如罗马数字)
- Sm(符号数学)
- 所以(其他符号)
注2:
val #^ = 1 // legal - two opchars
val # = 1 // illegal - reserved word like class or => or @
val + = 1 // legal - opchar
val &+ = 1 // legal - two opchars
val &2 = 1 // illegal - opchar and letter do not mix arbitrarily
val £2 = 1 // working - £ is part of Sc (Symbol currency) - undefined by spec
val ¬ = 1 // legal - part of Sm
注3:
其他类似于运算符的保留字:_ : = => <- <: <% >: # @ 以及 \u21D2 ⇒ 和 \u2190 ←