Skip to content

Lex annotation namespaces #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openqasm_pygments/qasm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _defcalgrammar_callback(self, match):
tokens = {
"root": [
(r"^[ \t]*#?pragma", token.Comment.Preproc, "pragma"),
(r"^[ \t]*@\w+", token.Name.Decorator, "annotation"),
(r"^[ \t]*@\w+(\.\w+)*", token.Name.Decorator, "annotation"),
(r"[ \r\n\t]+", token.Whitespace),
(r"\bOPENQASM\b", token.Comment.Preproc, "version"),
(r"//.*$", token.Comment.Single),
Expand Down
17 changes: 17 additions & 0 deletions tests/test_qasm3_lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ def test_for_loop_variable_not_callable(lexer_qasm3):
]


def test_annotation_namespace(lexer_qasm3):
text = """\
@annotation
@namespace.annotation
@namespace1.namespace2.annotation
qubit q;
"""
assert _remove_whitespace(lexer_qasm3.get_tokens(text)) == [
(token.Name.Decorator, "@annotation"),
(token.Name.Decorator, "@namespace.annotation"),
(token.Name.Decorator, "@namespace1.namespace2.annotation"),
(token.Keyword.Type, "qubit"),
(token.Name, "q"),
(token.Punctuation, ";")
]


class TestPulseLexerDelegation:
def test_inferred_known_alias(self, lexer_qasm3):
# This uses a very (!) non-standard pulse-grammar lexer to test delegation
Expand Down
Loading