forked from marcohu/rules_antlr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format grammar files with Antlr4Formatter
- Loading branch information
1 parent
f8fbbb7
commit c01bba7
Showing
35 changed files
with
2,008 additions
and
1,328 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,180 @@ | ||
lexer grammar TLexer; | ||
|
||
// These are all supported lexer sections: | ||
|
||
// Lexer file header. Appears at the top of h + cpp files. Use e.g. for copyrights. | ||
@lexer::header {/* lexer header section */} | ||
|
||
@ lexer :: header | ||
{/* lexer header section */} | ||
// Appears before any #include in h + cpp files. | ||
@lexer::preinclude {/* lexer precinclude section */} | ||
|
||
@ lexer :: preinclude | ||
{/* lexer precinclude section */} | ||
// Follows directly after the standard #includes in h + cpp files. | ||
@lexer::postinclude { | ||
|
||
@ lexer :: postinclude | ||
{ | ||
/* lexer postinclude section */ | ||
#ifndef _WIN32 | ||
#pragma GCC diagnostic ignored "-Wunused-parameter" | ||
#endif | ||
} | ||
|
||
// Directly preceds the lexer class declaration in the h file (e.g. for additional types etc.). | ||
@lexer::context {/* lexer context section */} | ||
|
||
@ lexer :: context | ||
{/* lexer context section */} | ||
// Appears in the public part of the lexer in the h file. | ||
@lexer::members {/* public lexer declarations section */ | ||
|
||
@ lexer :: members | ||
{/* public lexer declarations section */ | ||
bool canTestFoo() { return true; } | ||
bool isItFoo() { return true; } | ||
bool isItBar() { return true; } | ||
|
||
void myFooLexerAction() { /* do something*/ }; | ||
void myBarLexerAction() { /* do something*/ }; | ||
} | ||
|
||
// Appears in the private part of the lexer in the h file. | ||
@lexer::declarations {/* private lexer declarations/members section */} | ||
|
||
@ lexer :: declarations | ||
{/* private lexer declarations/members section */} | ||
// Appears in line with the other class member definitions in the cpp file. | ||
@lexer::definitions {/* lexer definitions section */} | ||
|
||
channels { CommentsChannel, DirectiveChannel } | ||
|
||
tokens { | ||
DUMMY | ||
} | ||
|
||
Return: 'return'; | ||
Continue: 'continue'; | ||
|
||
INT: Digit+; | ||
Digit: [0-9]; | ||
|
||
ID: LETTER (LETTER | '0'..'9')*; | ||
fragment LETTER : [a-zA-Z\u0080-\u{10FFFF}]; | ||
|
||
LessThan: '<'; | ||
GreaterThan: '>'; | ||
Equal: '='; | ||
And: 'and'; | ||
|
||
Colon: ':'; | ||
Semicolon: ';'; | ||
Plus: '+'; | ||
Minus: '-'; | ||
Star: '*'; | ||
OpenPar: '('; | ||
ClosePar: ')'; | ||
OpenCurly: '{' -> pushMode(Mode1); | ||
CloseCurly: '}' -> popMode; | ||
QuestionMark: '?'; | ||
Comma: ',' -> skip; | ||
Dollar: '$' -> more, mode(Mode1); | ||
Ampersand: '&' -> type(DUMMY); | ||
|
||
String: '"' .*? '"'; | ||
Foo: {canTestFoo()}? 'foo' {isItFoo()}? { myFooLexerAction(); }; | ||
Bar: 'bar' {isItBar()}? { myBarLexerAction(); }; | ||
Any: Foo Dot Bar? DotDot Baz; | ||
|
||
Comment : '#' ~[\r\n]* '\r'? '\n' -> channel(CommentsChannel); | ||
WS: [ \t\r\n]+ -> channel(99); | ||
@ lexer :: definitions | ||
{/* lexer definitions section */} | ||
channels { CommentsChannel , DirectiveChannel } | ||
tokens { DUMMY } | ||
Return | ||
: 'return' | ||
; | ||
|
||
Continue | ||
: 'continue' | ||
; | ||
|
||
INT | ||
: Digit+ | ||
; | ||
|
||
Digit | ||
: [0-9] | ||
; | ||
|
||
ID | ||
: LETTER (LETTER | '0' .. '9')* | ||
; | ||
|
||
fragment LETTER | ||
: [a-zA-Z\u0080-\u{10FFFF}] | ||
; | ||
|
||
LessThan | ||
: '<' | ||
; | ||
|
||
GreaterThan | ||
: '>' | ||
; | ||
|
||
Equal | ||
: '=' | ||
; | ||
|
||
And | ||
: 'and' | ||
; | ||
|
||
Colon | ||
: ':' | ||
; | ||
|
||
Semicolon | ||
: ';' | ||
; | ||
|
||
Plus | ||
: '+' | ||
; | ||
|
||
Minus | ||
: '-' | ||
; | ||
|
||
Star | ||
: '*' | ||
; | ||
|
||
OpenPar | ||
: '(' | ||
; | ||
|
||
ClosePar | ||
: ')' | ||
; | ||
|
||
OpenCurly | ||
: '{' -> pushMode (Mode1) | ||
; | ||
|
||
CloseCurly | ||
: '}' -> popMode | ||
; | ||
|
||
QuestionMark | ||
: '?' | ||
; | ||
|
||
Comma | ||
: ',' -> skip | ||
; | ||
|
||
Dollar | ||
: '$' -> more , mode (Mode1) | ||
; | ||
|
||
Ampersand | ||
: '&' -> type (DUMMY) | ||
; | ||
|
||
String | ||
: '"' .*? '"' | ||
; | ||
|
||
Foo | ||
: | ||
{canTestFoo()}? 'foo' | ||
{isItFoo()}? | ||
{ myFooLexerAction(); } | ||
; | ||
|
||
fragment Baz: 'Baz'; | ||
Bar | ||
: 'bar' | ||
{isItBar()}? | ||
{ myBarLexerAction(); } | ||
; | ||
|
||
Any | ||
: Foo Dot Bar? DotDot Baz | ||
; | ||
|
||
Comment | ||
: '#' ~ [\r\n]* '\r'? '\n' -> channel (CommentsChannel) | ||
; | ||
|
||
WS | ||
: [ \t\r\n]+ -> channel (99) | ||
; | ||
|
||
fragment Baz | ||
: 'Baz' | ||
; | ||
|
||
mode Mode1; | ||
Dot: '.'; | ||
Dot | ||
: '.' | ||
; | ||
|
||
mode Mode2; | ||
DotDot: '..'; | ||
DotDot | ||
: '..' | ||
; | ||
|
Oops, something went wrong.