字符 0:预期的字符集

character 0: character set expected

我想通过定义 here 的正则表达式定义一个 table 名称,这样:

Always begin a name with a letter, an underscore character (_), or a backslash (). Use letters, numbers, periods, and underscore characters for the rest of the name.

Exceptions: You can’t use "C", "c", "R", or "r" for the name, because they’re already designated as a shortcut for selecting the column or row for the active cell when you enter them in the Name or Go To box.

let lex_valid_characters_0 = ['a'-'z' 'A'-'Z' '_' '\x5C'] ['a'-'z' 'A'-'Z' '0'-'9' '.' '_']+
let haha = ['C' 'c' 'R' 'r']
let lex_table_name = lex_valid_characters_0 # haha

但它 returns 我出错了 character 0: character set expected.。有人可以帮忙吗?

这是手册中对 # 的描述:

regexp1 # regexp2

(difference of character sets) Regular expressions regexp1 and regexp2 must be character sets defined with [… ] (or a single character expression or underscore _). Match the difference of the two specified character sets.

描述说这两个集合必须是用[ ... ]定义的字符集,但你定义的lex_valid_characters_0远比那复杂得多。

# 的想法是它定义了一个模式,该模式与指定为两个 one-character 模式的差异的集合中的一个字符完全匹配。所以把它应用到 lex_valid_characters_0 是没有意义的,它匹配任意长度的字符串。

更新

这是我对这个问题的看法,以及它的价值。对于长度为 2 个或更多字符的名称没有额外限制(正如我阅读的规范)。因此,为这些名称指定正则表达式应该不会太困难。想出一个定义所有有效的 1 字符名称的正则表达式也不难。完整的名称集是这两个集的并集。

您还可以利用这样一个事实,即最长的第一个匹配项是适用于 ocamllex 的匹配项。也就是说,您可以在一般规则之前为 4 种特殊情况制定规则。