简体   繁体   中英

character 0: character set expected

I want to define a table name by regular expression definedhere such that:

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

But it returns me an error character 0: character set expected. . Could anyone help?

Here is the description of # from the manual:

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.

The description says the two sets must be character sets defined with [... ] but your definition of lex_valid_characters_0 is far more complex than that.

The idea of # is that it defines a pattern that matches exactly one character from a set specified as the difference of two one-character patterns. So it doesn't make sense to apply it to lex_valid_characters_0 , which matches strings of arbitrary length.

Update

Here is my thinking on the problem, for what it's worth. There are no extra restrictions on names that are 2 or more characters long (as I read the spec). So it shouldn't be too difficult to specify a regular expression for these names. And it also wouldn't be that hard to come up with a regular expression that defines all the valid 1-character names. The full set of names is the union of these two sets.

You could also use the fact that the longest, first match is the one that applies for ocamllex. Ie, you could have rules for the 4 special cases before the general rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM