-
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.
Add test to verify name mangling works for reserved keywords
1. Created a new file for the reserved keywords
- Loading branch information
1 parent
54ff709
commit 3d477b0
Showing
3 changed files
with
110 additions
and
75 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,74 @@ | ||
# Permalink: https://github.com/openqasm/openqasm/blob/main/source/grammar/qasm3Lexer.g4 | ||
reserved_keywords = { | ||
"angle", | ||
"array", | ||
"barrier", | ||
"bit", | ||
"bool", | ||
"box", | ||
"cal", | ||
"case", | ||
"complex", | ||
"const", | ||
"creg", | ||
"ctrl", | ||
"default", | ||
"defcal", | ||
"defcalgrammar", | ||
"delay", | ||
"duration", | ||
"durationof", | ||
"end", | ||
"euler", | ||
"extern", | ||
"false", | ||
"float", | ||
"frame", | ||
"gate", | ||
"gphase", | ||
"im", | ||
"include", | ||
"input", | ||
"int", | ||
"inv", | ||
"let", | ||
"OPENQASM", | ||
"measure", | ||
"mutable", | ||
"negctrl", | ||
"output", | ||
"pi", | ||
"port", | ||
"pragma", | ||
"qreg", | ||
"qubit", | ||
"readonly", | ||
"reset", | ||
"return", | ||
"sizeof", | ||
"stretch", | ||
"switch", | ||
"tau", | ||
"true", | ||
"U", | ||
"uint", | ||
"void", | ||
"waveform", | ||
} | ||
|
||
|
||
def is_reserved_keyword(name: str) -> bool: | ||
""" | ||
Method to check whether or not 'name' is a reserved keyword | ||
Args: | ||
name (str): Name of the variable to be checked | ||
Returns: | ||
tuple[bool, str]: Returns a tuple containing a boolean indicating | ||
whether the input 'name' is a reserved keyword and the modified name. | ||
If 'name' is a reserved keyword, the modified name has an underscore | ||
('_') appended to it; otherwise, it remains unchanged. | ||
""" | ||
is_keyword = name in reserved_keywords | ||
return (is_keyword, f"{name}_" if is_keyword 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