Closed jannone closed 7 years ago
If there's not many of such keywords, the simplest solution I can think if is negative lookahead:
ident: /[a-zA-Z]+(?!(AND|OR|...))/,
operator: ['AND', 'OR', ...],
Otherwise, I think you'll have to make a custom tokenizer that does two passes or something. I'm not sure.
/[a-zA-Z]+(?!(AND|OR|...))/
That won't work. Try /(?:(?!AND|OR)[a-zA-Z])+/
.
That looks right to me! :-)
@deltaidea and @nathan It worked! Thanks!
Hello,
I have a use-case where the language allows the user to type without spaces. So, an expression like this: X=Y AND Z Might be typed like this: X=YANDZ
The problem is that I have a "ident" rule matching variable names, and I use the keyword feature to detect operators such as the "AND" in the example above.
However, I can't seem to find a way for the lexer to detect the AND without spaces. It can only read it as an ident of value "YANDZ".
How can I fix that?
Thanks