I am using Pest.rs for parsing. I need to parse identifiers but reject them if they happen to be a reserved keyword. For example, bat is a valid identifier name but this is not since that has a specific meaning. My simplified grammar is as below.
keyword = {"this" | "function"}
identifier = {ASCII+}
valid_identifier = { !keyword ~ identifier }
This works but it also rejects identifier names like thisBat. So basically it checks if that the prefix is not a keyword, but I want to check against the full identifier.
Supposing that identifiers are composed of alphanumeric characters, another option is:
!(keyword ~ !ASCII_ALPHANUMERIC)rejects any identifier that starts with a keyword, as long as the character following the keyword can't be part of the identifier itself. This means thatthisBatis an acceptable identifier, butthisis not.