-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix: Append '_' to the variable names that are reserved keywords 1. Fixed few existing test cases that got affected due to this change 2. Added reserved keyword list * Add test to verify name mangling works for reserved keywords 1. Created a new file for the reserved keywords * Change return type to tuple * Change function signature to return new name * Separate keywords using comments * turn into single-liner Co-authored-by: Lauren Capelluto <laurecap@amazon.com> --------- Co-authored-by: Jean-Christophe Jaskula <99367153+jcjaskula-aws@users.noreply.github.com> Co-authored-by: Ryan Shaffer <3620100+rmshaffer@users.noreply.github.com> Co-authored-by: Lauren Capelluto <laurecap@amazon.com>
- Loading branch information
1 parent
360cab1
commit f83bb15
Showing
6 changed files
with
132 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Copied from: | ||
# https://github.com/openqasm/openqasm/blob/main/source/grammar/qasm3Lexer.g4 | ||
# https://github.com/openqasm/openpulse-python/blob/main/source/grammar/openpulseLexer.g4 | ||
|
||
reserved_keywords = { | ||
# openQASM keywords | ||
"angle", | ||
"array", | ||
"barrier", | ||
"bit", | ||
"bool", | ||
"box", | ||
"cal", | ||
"case", | ||
"complex", | ||
"const", | ||
"creg", | ||
"ctrl", | ||
"default", | ||
"defcal", | ||
"defcalgrammar", | ||
"delay", | ||
"duration", | ||
"durationof", | ||
"end", | ||
"euler", | ||
"extern", | ||
"false", | ||
"float", | ||
"gate", | ||
"gphase", | ||
"im", | ||
"include", | ||
"input", | ||
"int", | ||
"inv", | ||
"let", | ||
"OPENQASM", | ||
"measure", | ||
"mutable", | ||
"negctrl", | ||
"output", | ||
"pi", | ||
"pragma", | ||
"qreg", | ||
"qubit", | ||
"readonly", | ||
"reset", | ||
"return", | ||
"sizeof", | ||
"stretch", | ||
"switch", | ||
"tau", | ||
"true", | ||
"U", | ||
"uint", | ||
"void", | ||
# openpulse keywords | ||
"frame", | ||
"port", | ||
"waveform", | ||
} | ||
|
||
|
||
def sanitize_parameter_name(name: str) -> str: | ||
""" | ||
Method to modify the variable name if it is a | ||
reserved keyword | ||
Args: | ||
name (str): Name of the variable to be checked | ||
Returns: | ||
str: Returns a modified 'name' that has an underscore ('_') appended to it; | ||
otherwise, it returns the original 'name' unchanged | ||
""" | ||
return f"{name}_" if name in reserved_keywords else name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters