When using a targeted language’s reserved words in rules, you may see the following error:Documentation Index
Fetch the complete documentation index at: https://docs.semgrep.dev/llms.txt
Use this file to discover all available pages before exploring further.
Background
Each programming language has a list of reserved words that cannot be used as identifiers, such as the names of variables or functions. If you write a rule that results in the following error when run, you are triggering a reserved word conflict:Resolution
Using a reserved word in your rule leads to parsing errors, so if you see this error, determine if the words cited in the error are reserved words. If they are, you can replace yourmetavariable-pattern with metavariable-regex.
This substitution works because metavariable-pattern tries to match the pattern within the captured metavariable, which is going to be affected by how reserved keywords are parsed, while metavariable-regex runs a regex on the text range associated with the metavariable, ignoring how its content would be parsed and bypassing the issue.