@@ -14,8 +14,8 @@ lexer grammar qasm3Lexer;
1414/* Language keywords. */
1515
1616OPENQASM : ' OPENQASM' -> pushMode(VERSION_IDENTIFIER );
17- INCLUDE : ' include' ;
18- DEFCALGRAMMAR : ' defcalgrammar' ;
17+ INCLUDE : ' include' -> pushMode( ARBITRARY_STRING ) ;
18+ DEFCALGRAMMAR : ' defcalgrammar' -> pushMode( ARBITRARY_STRING ) ;
1919DEF : ' def' ;
2020CAL : ' cal' -> mode(CAL_PRELUDE );
2121DEFCAL : ' defcal' -> mode(DEFCAL_PRELUDE );
@@ -33,6 +33,9 @@ RETURN: 'return';
3333FOR : ' for' ;
3434WHILE : ' while' ;
3535IN : ' in' ;
36+ SWITCH : ' switch' ;
37+ CASE : ' case' ;
38+ DEFAULT : ' default' ;
3639
3740PRAGMA : ' #' ? ' pragma' -> pushMode(EAT_TO_LINE_END );
3841AnnotationKeyword : ' @' Identifier -> pushMode(EAT_TO_LINE_END );
@@ -123,7 +126,7 @@ ComparisonOperator: '>' | '<' | '>=' | '<=';
123126BitshiftOperator : ' >>' | ' <<' ;
124127
125128IMAG : ' im' ;
126- ImaginaryLiteral : (DecimalIntegerLiteral | FloatLiteral) ' ' * IMAG ;
129+ ImaginaryLiteral : (DecimalIntegerLiteral | FloatLiteral) [ \t] * IMAG ;
127130
128131BinaryIntegerLiteral : (' 0b' | ' 0B' ) ([01] ' _' ?)* [01];
129132OctalIntegerLiteral : ' 0o' ([0-7] ' _' ?)* [0-7];
@@ -149,15 +152,9 @@ FloatLiteral:
149152
150153fragment TimeUnit: ' dt' | ' ns' | ' us' | ' µs' | ' ms' | ' s' ;
151154// represents explicit time value in SI or backend units
152- TimingLiteral : (DecimalIntegerLiteral | FloatLiteral) TimeUnit;
153-
155+ TimingLiteral : (DecimalIntegerLiteral | FloatLiteral) [ \t]* TimeUnit;
154156
155157BitstringLiteral : ' "' ([01] ' _' ?)* [01] ' "' ;
156- // allow ``"str"`` and ``'str'``
157- StringLiteral
158- : ' "' ~[" \r\t\n ]+? '" '
159- | ' \' ' ~[' \r\t\n ]+? ' \' '
160- ;
161158
162159// Ignore whitespace between tokens, and define C++-style comments.
163160Whitespace : [ \t]+ -> skip ;
@@ -173,6 +170,13 @@ mode VERSION_IDENTIFIER;
173170 VERSION_IDENTIFER_WHITESPACE : [ \t\r\n]+ -> skip;
174171 VersionSpecifier: [0-9]+ (' .' [0-9]+)? -> popMode;
175172
173+ // An include statement's path or defcalgrammar target is potentially ambiguous
174+ // with `BitstringLiteral`.
175+ mode ARBITRARY_STRING ;
176+ ARBITRARY_STRING_WHITESPACE : [ \t\r\n]+ -> skip;
177+ // allow ``"str"`` and ``'str'``;
178+ StringLiteral: (' "' ~[" \r\t\n ]+? '" ' | ' \' ' ~[' \r\t\n ]+? ' \' ' ) -> popMode;
179+
176180
177181// A different lexer mode to swap to when we need handle tokens on a line basis
178182// rather than the default arbitrary-whitespace-based tokenisation. This is
0 commit comments