Skip to content

Commit

Permalink
Reformatting all grammars (antlr#3843)
Browse files Browse the repository at this point in the history
* Ran all grammars through the formatter

With this patch we introduce a common set of rules for the grammars in this repository. All future changes in a grammar must follow these rules.

* Some fixes

* For now keep the antlr/example grammars as is

They serve special purposes and are not normal grammars.

* Fixed symbolic conflicts

These have been there for a while already, but were never detected due to a bug in ANTLR.

* Fix tests
  • Loading branch information
mike-lischke authored Nov 29, 2023
1 parent 6e78e18 commit 7535367
Show file tree
Hide file tree
Showing 495 changed files with 167,617 additions and 138,646 deletions.
143 changes: 115 additions & 28 deletions _scripts/templates/st.Arithmetic.g4
Original file line number Diff line number Diff line change
@@ -1,32 +1,119 @@
// Template generated code from trgen <version>

// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging

grammar Arithmetic;

file_ : expression (SEMI expression)* EOF;
expression : expression POW expression | expression (TIMES | DIV) expression | expression (PLUS | MINUS) expression | LPAREN expression RPAREN | (PLUS | MINUS)* atom ;
atom : scientific | variable ;
scientific : SCIENTIFIC_NUMBER ;
variable : VARIABLE ;

VARIABLE : VALID_ID_START VALID_ID_CHAR* ;
SCIENTIFIC_NUMBER : NUMBER (E SIGN? UNSIGNED_INTEGER)? ;
LPAREN : '(' ;
RPAREN : ')' ;
PLUS : '+' ;
MINUS : '-' ;
TIMES : '*' ;
DIV : '/' ;
GT : '>' ;
LT : '\<' ;
EQ : '=' ;
POINT : '.' ;
POW : '^' ;
SEMI : ';' ;
WS : [ \r\n\t] + -> channel(HIDDEN) ;

fragment VALID_ID_START : ('a' .. 'z') | ('A' .. 'Z') | '_' ;
fragment VALID_ID_CHAR : VALID_ID_START | ('0' .. '9') ;
fragment NUMBER : ('0' .. '9') + ('.' ('0' .. '9') +)? ;
fragment UNSIGNED_INTEGER : ('0' .. '9')+ ;
fragment E : 'E' | 'e' ;
fragment SIGN : ('+' | '-') ;
file_
: expression (SEMI expression)* EOF
;

expression
: expression POW expression
| expression (TIMES | DIV) expression
| expression (PLUS | MINUS) expression
| LPAREN expression RPAREN
| (PLUS | MINUS)* atom
;

atom
: scientific
| variable
;

scientific
: SCIENTIFIC_NUMBER
;

variable
: VARIABLE
;

VARIABLE
: VALID_ID_START VALID_ID_CHAR*
;

SCIENTIFIC_NUMBER
: NUMBER (E SIGN? UNSIGNED_INTEGER)?
;

LPAREN
: '('
;

RPAREN
: ')'
;

PLUS
: '+'
;

MINUS
: '-'
;

TIMES
: '*'
;

DIV
: '/'
;

GT
: '>'
;

LT
: '\<'
;

EQ
: '='
;

POINT
: '.'
;

POW
: '^'
;

SEMI
: ';'
;

WS
: [ \r\n\t]+ -> channel(HIDDEN)
;

fragment VALID_ID_START
: ('a' .. 'z')
| ('A' .. 'Z')
| '_'
;

fragment VALID_ID_CHAR
: VALID_ID_START
| ('0' .. '9')
;

fragment NUMBER
: ('0' .. '9')+ ('.' ('0' .. '9')+)?
;

fragment UNSIGNED_INTEGER
: ('0' .. '9')+
;

fragment E
: 'E'
| 'e'
;

fragment SIGN
: ('+' | '-')
;
225 changes: 105 additions & 120 deletions abb/abbLexer.g4
Original file line number Diff line number Diff line change
@@ -1,122 +1,107 @@
// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true

lexer grammar abbLexer;

options { caseInsensitive = true; }

MODULE : 'module' ;
ENDMODULE : 'endmodule' ;
PROC: 'PROC';
ENDPROC: 'ENDPROC';
LOCAL: 'LOCAL';
CONST: 'CONST';
PERS: 'PERS';
VAR: 'VAR';
TOOLDATA: 'TOOLDATA';
WOBJDATA: 'WOBJDATA';
SPEEDDATA: 'SPEEDDATA';
ZONEDATA: 'ZONEDATA';
CLOCK: 'CLOCK';
BOOL: 'BOOL';
ON_CALL: '\\ON';
OFF_CALL: '\\OFF';

SLASH : '/' ;
EQUALS : ':=' ;
COMMA : ',';
CURLY_OPEN : '{';
CURLY_CLOSE : '}';
COLON : ':';
SEMICOLON : ';';
BRACKET_OPEN : '(';
BRACKET_CLOSE : ')';
SQUARE_OPEN : '[';
SQUARE_CLOSE : ']';
DOT : '.';
DOUBLEDOT : '..';
REL_BIGGER : '>';
REL_BIGGER_OR_EQUAL : '>=';
REL_SMALLER : '<';
REL_SMALLER_OR_EQUAL: '<=';
REL_EQUAL : '==';
REL_NOTEQUAL : '<>';
PLUS : '+';
MINUS : '-';
MULTIPLY : '*';
PERCENT : '%';
HASH : '#';

WS
: (' ' | '\t' | '\u000C') -> skip
;

NEWLINE
: '\r'? '\n'
;

LINE_COMMENT
: '!' ~ ('\n' | '\r')* -> skip
;

BOOLLITERAL
: 'FALSE'
| 'TRUE'
;

CHARLITERAL
: '\'' (EscapeSequence | ~ ('\'' | '\\' | '\r' | '\n')) '\''
;

STRINGLITERAL
: '"' (EscapeSequence | ~ ('\\' | '"' | '\r' | '\n'))* '"'
;

fragment EscapeSequence
: '\\' ('b' | 't' | 'n' | 'f' | 'r' | '"' | '\'' | '\\' | '0' .. '3' '0' .. '7' '0' .. '7' | '0' .. '7' '0' .. '7' | '0' .. '7')
;

FLOATLITERAL
: ('0' .. '9') + '.' ('0' .. '9')* Exponent? | '.' ('0' .. '9') + Exponent? | ('0' .. '9') + Exponent
;

fragment Exponent
: 'E' ('+' | '-')? ('0' .. '9') +
;

INTLITERAL
: ('0' .. '9') + | HexPrefix HexDigit + HexSuffix | BinPrefix BinDigit + BinSuffix
;

fragment HexPrefix
: '\'' 'H'
;

fragment HexDigit
: '0' .. '9' | 'A' .. 'F'
;

fragment HexSuffix
: '\''
;

fragment BinPrefix
: '\'' 'B'
;

fragment BinDigit
: '0' | '1'
;

fragment BinSuffix
: '\''
;

IDENTIFIER
: IdentifierStart IdentifierPart*
;

fragment IdentifierStart
: 'A' .. 'Z' | '_'
;

fragment IdentifierPart
: IdentifierStart | '0' .. '9'
;
options {
caseInsensitive = true;
}

MODULE : 'module';
ENDMODULE : 'endmodule';
PROC : 'PROC';
ENDPROC : 'ENDPROC';
LOCAL : 'LOCAL';
CONST : 'CONST';
PERS : 'PERS';
VAR : 'VAR';
TOOLDATA : 'TOOLDATA';
WOBJDATA : 'WOBJDATA';
SPEEDDATA : 'SPEEDDATA';
ZONEDATA : 'ZONEDATA';
CLOCK : 'CLOCK';
BOOL : 'BOOL';
ON_CALL : '\\ON';
OFF_CALL : '\\OFF';

SLASH : '/';
EQUALS : ':=';
COMMA : ',';
CURLY_OPEN : '{';
CURLY_CLOSE : '}';
COLON : ':';
SEMICOLON : ';';
BRACKET_OPEN : '(';
BRACKET_CLOSE : ')';
SQUARE_OPEN : '[';
SQUARE_CLOSE : ']';
DOT : '.';
DOUBLEDOT : '..';
REL_BIGGER : '>';
REL_BIGGER_OR_EQUAL : '>=';
REL_SMALLER : '<';
REL_SMALLER_OR_EQUAL : '<=';
REL_EQUAL : '==';
REL_NOTEQUAL : '<>';
PLUS : '+';
MINUS : '-';
MULTIPLY : '*';
PERCENT : '%';
HASH : '#';

WS: (' ' | '\t' | '\u000C') -> skip;

NEWLINE: '\r'? '\n';

LINE_COMMENT: '!' ~ ('\n' | '\r')* -> skip;

BOOLLITERAL: 'FALSE' | 'TRUE';

CHARLITERAL: '\'' (EscapeSequence | ~ ('\'' | '\\' | '\r' | '\n')) '\'';

STRINGLITERAL: '"' (EscapeSequence | ~ ('\\' | '"' | '\r' | '\n'))* '"';

fragment EscapeSequence:
'\\' (
'b'
| 't'
| 'n'
| 'f'
| 'r'
| '"'
| '\''
| '\\'
| '0' .. '3' '0' .. '7' '0' .. '7'
| '0' .. '7' '0' .. '7'
| '0' .. '7'
)
;

FLOATLITERAL:
('0' .. '9')+ '.' ('0' .. '9')* Exponent?
| '.' ('0' .. '9')+ Exponent?
| ('0' .. '9')+ Exponent
;

fragment Exponent: 'E' ('+' | '-')? ('0' .. '9')+;

INTLITERAL: ('0' .. '9')+ | HexPrefix HexDigit+ HexSuffix | BinPrefix BinDigit+ BinSuffix;

fragment HexPrefix: '\'' 'H';

fragment HexDigit: '0' .. '9' | 'A' .. 'F';

fragment HexSuffix: '\'';

fragment BinPrefix: '\'' 'B';

fragment BinDigit: '0' | '1';

fragment BinSuffix: '\'';

IDENTIFIER: IdentifierStart IdentifierPart*;

fragment IdentifierStart: 'A' .. 'Z' | '_';

fragment IdentifierPart: IdentifierStart | '0' .. '9';
Loading

0 comments on commit 7535367

Please sign in to comment.