Skip to content

Commit b203921

Browse files
Lex annotation namespaces (#3)
* Lex annotation namespaces * Add release note * Fix lint
1 parent 2d9796c commit b203921

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Annotation keywords will now be correctly lexed as a single ``Token.Name.Decorator`` token.

src/openqasm_pygments/qasm3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _defcalgrammar_callback(self, match):
7575
tokens = {
7676
"root": [
7777
(r"^[ \t]*#?pragma", token.Comment.Preproc, "pragma"),
78-
(r"^[ \t]*@\w+", token.Name.Decorator, "annotation"),
78+
(r"^[ \t]*@\w+(\.\w+)*", token.Name.Decorator, "annotation"),
7979
(r"[ \r\n\t]+", token.Whitespace),
8080
(r"\bOPENQASM\b", token.Comment.Preproc, "version"),
8181
(r"//.*$", token.Comment.Single),

tests/test_qasm3_lexer.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ def test_for_loop_variable_not_callable(lexer_qasm3):
6868
]
6969

7070

71+
def test_annotation_namespace(lexer_qasm3):
72+
text = """\
73+
@annotation
74+
@namespace.annotation
75+
@namespace1.namespace2.annotation
76+
qubit q;
77+
"""
78+
assert _remove_whitespace(lexer_qasm3.get_tokens(text)) == [
79+
(token.Name.Decorator, "@annotation"),
80+
(token.Name.Decorator, "@namespace.annotation"),
81+
(token.Name.Decorator, "@namespace1.namespace2.annotation"),
82+
(token.Keyword.Type, "qubit"),
83+
(token.Name, "q"),
84+
(token.Punctuation, ";"),
85+
]
86+
87+
7188
class TestPulseLexerDelegation:
7289
def test_inferred_known_alias(self, lexer_qasm3):
7390
# This uses a very (!) non-standard pulse-grammar lexer to test delegation

0 commit comments

Comments
 (0)