How to only match full token? #96
-
I've been working on a library that parses Web IDL and I've hit an issue I'm not sure how to resolve. Here's a partial of the grammar.
I encountered the issue when I was parsing a type definition I based my grammar around the examples I saw so its using a
Is there any way to make it so the parser has to be surrounded by whitespace? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is a common problem when parsing keywords. One way to solve it is to add a negative lookahead make sure the keyword is not followed by more letter/digits: Parser bufferRelatedType() =>
ref(token, 'ArrayBuffer').seq(word().not()).pick(0) | ... Potentially you want to integrate that code into your token-builder, but often it is not needed for all tokens (or at all, depending on the language to parse). Here is an example where this is done for the |
Beta Was this translation helpful? Give feedback.
This is a common problem when parsing keywords. One way to solve it is to add a negative lookahead make sure the keyword is not followed by more letter/digits:
Potentially you want to integrate that code into your token-builder, but often it is not needed for all tokens (or at all, depending on the language to parse).
Here is an example where this is done for the
true
token, and to avoid running into a problem when trying to parse a variable liketrueBinding
.