This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Q# grammar in ANTLR format #45
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6bb1333
Add ANTLR grammar
7493d3e
Add note about actions/semantic predicates
1118ce6
Update formatting of callableDeclaration
9c2bb8f
Remove labels
62a7c78
Add comment about lookahead in DoubleLiteral
7535a77
Target-specific is contained in { }
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,191 @@ | ||
| lexer grammar QSharpLexer; | ||
|
|
||
| // Keywords | ||
|
|
||
| Adj : 'Adj'; | ||
| AdjointFunctor : 'Adjoint'; | ||
| AdjointGenerator : 'adjoint'; | ||
| And : 'and'; | ||
| Apply : 'apply'; | ||
| As : 'as'; | ||
| Auto : 'auto'; | ||
| BigInt : 'BigInt'; | ||
| Body : 'body'; | ||
| Bool : 'Bool'; | ||
| Borrowing : 'borrowing'; | ||
| ControlledFunctor : 'Controlled'; | ||
| ControlledGenerator : 'controlled'; | ||
| Ctl : 'Ctl'; | ||
| Distribute : 'distribute'; | ||
| Double : 'Double'; | ||
| Elif : 'elif'; | ||
| Else : 'else'; | ||
| Fail : 'fail'; | ||
| False : 'false'; | ||
| Fixup : 'fixup'; | ||
| For : 'for'; | ||
| Function : 'function'; | ||
| If : 'if'; | ||
| In : 'in'; | ||
| Int : 'Int'; | ||
| Internal : 'internal'; | ||
| Intrinsic : 'intrinsic'; | ||
| Invert : 'invert'; | ||
| Is : 'is'; | ||
| Let : 'let'; | ||
| Mutable : 'mutable'; | ||
| Namespace : 'namespace'; | ||
| New : 'new'; | ||
| Newtype : 'newtype'; | ||
| Not : 'not'; | ||
| One : 'One'; | ||
| Open : 'open'; | ||
| Operation : 'operation'; | ||
| Or : 'or'; | ||
| Pauli : 'Pauli'; | ||
| PauliI : 'PauliI'; | ||
| PauliX : 'PauliX'; | ||
| PauliY : 'PauliY'; | ||
| PauliZ : 'PauliZ'; | ||
| Qubit : 'Qubit'; | ||
| Range : 'Range'; | ||
| Repeat : 'repeat'; | ||
| Result : 'Result'; | ||
| Return : 'return'; | ||
| Self : 'self'; | ||
| Set : 'set'; | ||
| String : 'String'; | ||
| True : 'true'; | ||
| Unit : 'Unit'; | ||
| Until : 'until'; | ||
| Using : 'using'; | ||
| While : 'while'; | ||
| Within : 'within'; | ||
| Zero : 'Zero'; | ||
|
|
||
| // Operators | ||
|
|
||
| AndEqual : 'and='; | ||
| ArrowLeft : '<-'; | ||
| ArrowRight : '->'; | ||
| Asterisk : '*'; | ||
| AsteriskEqual : '*='; | ||
| At : '@'; | ||
| Bang : '!'; | ||
| BraceLeft : '{' -> pushMode(DEFAULT_MODE); | ||
| BraceRight : '}' { if (!_modeStack.isEmpty()) popMode(); }; | ||
| BracketLeft : '['; | ||
| BracketRight : ']'; | ||
| Caret : '^'; | ||
| CaretEqual : '^='; | ||
| Colon : ':'; | ||
| Comma : ','; | ||
| DollarQuote : '$"' -> pushMode(INTERPOLATED); | ||
| Dot : '.'; | ||
| DoubleColon : '::'; | ||
| DoubleDot : '..'; | ||
| DoubleEqual : '=='; | ||
| DoubleQuote : '"' -> pushMode(STRING); | ||
| Ellipsis : '...'; | ||
| Equal : '='; | ||
| FatArrowRight : '=>'; | ||
| Greater : '>'; | ||
| GreaterEqual : '>='; | ||
| Less : '<'; | ||
| LessEqual : '<='; | ||
| Minus : '-'; | ||
| MinusEqual : '-='; | ||
| NotEqual : '!='; | ||
| OrEqual : 'or='; | ||
| ParenLeft : '('; | ||
| ParenRight : ')'; | ||
| Percent : '%'; | ||
| PercentEqual : '%='; | ||
| Pipe : '|'; | ||
| Plus : '+'; | ||
| PlusEqual : '+='; | ||
| Question : '?'; | ||
| Semicolon : ';'; | ||
| Slash : '/'; | ||
| SlashEqual : '/='; | ||
| TripleAmpersand : '&&&'; | ||
| TripleAmpersandEqual : '&&&='; | ||
| TripleCaret : '^^^'; | ||
| TripleCaretEqual : '^^^='; | ||
| TripleGreater : '>>>'; | ||
| TripleGreaterEqual : '>>>='; | ||
| TripleLess : '<<<'; | ||
| TripleLessEqual : '<<<='; | ||
| TriplePipe : '|||'; | ||
| TriplePipeEqual : '|||='; | ||
| TripleTilde : '~~~'; | ||
| Underscore : '_'; | ||
| With : 'w/'; | ||
| WithEqual : 'w/='; | ||
|
|
||
| // Literals | ||
|
|
||
| fragment Digit : [0-9]; | ||
|
|
||
| IntegerLiteral | ||
| : Digit+ | ||
| | ('0x' | '0X') [0-9a-fA-F]+ | ||
| | ('0o' | '0O') [0-7]+ | ||
| | ('0b' | '0B') [0-1]+ | ||
| ; | ||
|
|
||
| BigIntegerLiteral : IntegerLiteral ('L' | 'l'); | ||
|
|
||
| DoubleLiteral | ||
| : Digit+ '.' Digit+ | ||
| | '.' Digit+ | ||
| // "n.." should be interpreted as an integer range, not the double "n." followed by a dot. | ||
| | Digit+ '.' { _input.LA(1) != '.' }? | ||
| | Digit+ ('e' | 'E') Digit+ | ||
| ; | ||
|
|
||
| Identifier : IdentifierStart IdentifierContinuation*; | ||
|
|
||
| IdentifierStart | ||
| : Underscore | ||
| | [\p{Letter}] | ||
| | [\p{Letter_Number}] | ||
| ; | ||
|
|
||
| IdentifierContinuation | ||
| : [\p{Connector_Punctuation}] | ||
| | [\p{Decimal_Number}] | ||
| | [\p{Format}] | ||
| | [\p{Letter}] | ||
| | [\p{Letter_Number}] | ||
| | [\p{Nonspacing_Mark}] | ||
| | [\p{Spacing_Mark}] | ||
| ; | ||
|
|
||
| TypeParameter : '\'' Identifier; | ||
|
|
||
| Whitespace : (' ' | '\n' | '\r' | '\t')+ -> channel(HIDDEN); | ||
|
|
||
| Comment : '//' ~('\n' | '\r')* -> channel(HIDDEN); | ||
|
|
||
| Invalid : . -> channel(HIDDEN); | ||
|
|
||
| // Strings | ||
|
|
||
| mode STRING; | ||
|
|
||
| StringEscape : '\\' .; | ||
|
|
||
| StringText : ~('"' | '\\')+; | ||
|
|
||
| StringDoubleQuote : '"' -> popMode; | ||
|
|
||
| mode INTERPOLATED; | ||
|
|
||
| InterpStringEscape : '\\' .; | ||
|
|
||
| InterpBraceLeft : '{' -> pushMode(DEFAULT_MODE); | ||
|
|
||
| InterpStringText : ~('\\' | '"' | '{')+; | ||
|
|
||
| InterpDoubleQuote : '"' -> popMode; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.