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.
Figured out a hack to address this.
The new second rule in
valid_identifiertakes care of matching with the valid case which the first one rejects. Note I have madevalid_identifieratomic so that whitespaces are not inserted and the parse output is not likethisandBat, but a singlethisBat.