Error nodes produced even though other match seems possible #857
-
I am trying to parse a language with identifiers and also literals.
Here I have the following simplified grammar:
This produces the following match state:
I.e., I am able to parse constructs like I have experimented with I had previously asked this question on Stackoverflow, but here seems to be a better place. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think you may want the ‘b’ prefix to be part of the same token as the string, instead of being a separate token. Because if it’s a separate token, the lexer doesn’t have a way to distinguish it from an identifier. |
Beta Was this translation helpful? Give feedback.
-
Thanks for nudging me in the right direction @maxbrunsfeld. With the following change this toy example does indeed work: - literal: _ => seq('b', /\"[a-z]*\"/),
+ literal: _ => token(seq('b', /\"[a-z]*\"/)),
If the matcher for the quoted part of ident: _ => /[a-z]/,
literal: $ => token(seq('b', $.ident)), // WRONG.
|
Beta Was this translation helpful? Give feedback.
I think you may want the ‘b’ prefix to be part of the same token as the string, instead of being a separate token. Because if it’s a separate token, the lexer doesn’t have a way to distinguish it from an identifier.