Replies: 1 comment 3 replies
-
I'm afraid I don't quite understand what you want to achieve. Maybe some example input and the tokens you'd expect but can't currently produce? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I do not have to much experience with lexers, so forgive me if I am doing it wrong.
In the lexer's rules, if one want to lex for keywords (and I am not sure one is supposed to do so?) I have a problem with the following:
Lets say this is a rule, among others,
{"Keywords", "ELSE|IF|TRUE|FALSE", nil},
this will match the string "ELSEIFTRUE" as three different products. In order to prevent this, one can apply the '\b" (boundry) syntax like this:
{"Keywords", "\b(ELSE|IF|TRUE|FALSE)\b", nil},
and the string "ELSEIFTRUE" won't match; now you need to write "ELSE IF TRUE" (with space)
but the string "ELSE#IF#TRUE" will still produce three different words, as the "#" are considered "boundries" by \b
\b is good to use since it is non-consuming, however, it doesn't match exactly what I want.
The reason one uses \b and not \s like this
{"Keywords", "\s+(ELSE|IF|TRUE|FALSE)\s+", nil}
, is that then the lexer consumes the space, and the result becomes " ELSE ", which is not what I want.So bottom line, can you write a regexp-rule that "checks" for spaces around the keyword, without consuming it?
or are there other tricks to solve this?
Beta Was this translation helpful? Give feedback.
All reactions