11/* *
2- * Based on Java 1.7 grammar for ANTLR 4, see Java.g4
2+ * Based on Java 1.7 grammar for ANTLR 4, see Java.g4
33 *
4- * - changes main entry point to reflect sketch types 'static' | 'active'
5- * - adds support for type converter functions like "int()"
6- * - adds pseudo primitive type "color"
7- * - adds HTML hex notation with hash symbol: #ff5522
4+ * - changes main entry point to reflect sketch types 'static' | 'active'
5+ * - adds support for type converter functions like "int()"
6+ * - adds pseudo primitive type "color"
7+ * - adds HTML hex notation with hash symbol: #ff5522
88 * - allow color to appear as part of qualified names (like in imports)
99 */
1010
1111grammar Processing;
1212
1313@lexer::members {
14- public static final int WHITESPACE = 1 ;
15- public static final int COMMENTS = 2 ;
14+ public static final int WHITESPACE = 1 ;
15+ public static final int COMMENTS = 2 ;
1616}
1717
1818// import Java grammar
1919import JavaParser;
2020
2121// main entry point, select sketch type
2222processingSketch
23- : javaProcessingSketch
24- | staticProcessingSketch
25- | activeProcessingSketch
26- | warnMixedModes
23+ : javaProcessingSketch
24+ | staticProcessingSketch
25+ | activeProcessingSketch
26+ | warnMixedModes
2727 ;
2828
2929// java mode, is a compilation unit
3030javaProcessingSketch
31- : packageDeclaration? importDeclaration* typeDeclaration+ EOF
31+ : packageDeclaration? importDeclaration* typeDeclaration+ EOF
3232 ;
3333
3434// No method declarations, just statements
3535staticProcessingSketch
36- : (importDeclaration | blockStatement)* EOF
36+ : (importDeclaration | blockStatement)* EOF
3737 ;
3838
3939// active mode, has function definitions
4040activeProcessingSketch
41- : (importDeclaration | classBodyDeclaration)* EOF
42- ;
41+ : (importDeclaration | classBodyDeclaration)* EOF
42+ ;
4343
4444// User incorrectly mixing modes. Included to allow for kind error message.
4545warnMixedModes
46- : (importDeclaration | classBodyDeclaration | blockStatement)* blockStatement classBodyDeclaration (importDeclaration | classBodyDeclaration | blockStatement)*
47- | (importDeclaration | classBodyDeclaration | blockStatement)* classBodyDeclaration blockStatement (importDeclaration | classBodyDeclaration | blockStatement)*
46+ : (importDeclaration | classBodyDeclaration | blockStatement)* blockStatement classBodyDeclaration (importDeclaration | classBodyDeclaration | blockStatement)*
47+ | (importDeclaration | classBodyDeclaration | blockStatement)* classBodyDeclaration blockStatement (importDeclaration | classBodyDeclaration | blockStatement)*
4848 ;
4949
5050variableDeclaratorId
51- : warnTypeAsVariableName
52- | IDENTIFIER (' [' ' ]' )*
51+ : warnTypeAsVariableName
52+ | IDENTIFIER (' [' ' ]' )*
5353 ;
5454
5555// bug #93
5656// https://github.com/processing/processing/issues/93
5757// prevent from types being used as variable names
5858warnTypeAsVariableName
59- : primitiveType (' [' ' ]' )* {
60- notifyErrorListeners(" Type names are not allowed as variable names: " +$primitiveType.text);
61- }
59+ : primitiveType (' [' ' ]' )* {
60+ notifyErrorListeners(" Type names are not allowed as variable names: " +$primitiveType.text);
61+ }
6262 ;
6363
6464// catch special API function calls that we are interested in
@@ -72,30 +72,30 @@ methodCall
7272// these are primitive type names plus "()"
7373// "color" is a special Processing primitive (== int)
7474functionWithPrimitiveTypeName
75- : ( ' boolean'
76- | ' byte'
77- | ' char'
78- | ' float'
79- | ' int'
80- | ' color'
81- ) ' (' expressionList? ' )'
82- ;
75+ : ( ' boolean'
76+ | ' byte'
77+ | ' char'
78+ | ' float'
79+ | ' int'
80+ | ' color'
81+ ) ' (' expressionList? ' )'
82+ ;
8383
8484// adding support for "color" primitive
8585primitiveType
86- : BOOLEAN
87- | CHAR
88- | BYTE
89- | SHORT
90- | INT
91- | LONG
92- | FLOAT
93- | DOUBLE
94- | colorPrimitiveType
95- ;
86+ : BOOLEAN
87+ | CHAR
88+ | BYTE
89+ | SHORT
90+ | INT
91+ | LONG
92+ | FLOAT
93+ | DOUBLE
94+ | colorPrimitiveType
95+ ;
9696
9797colorPrimitiveType
98- : ' color'
98+ : ' color'
9999 ;
100100
101101qualifiedName
@@ -116,27 +116,29 @@ literal
116116// As parser rule so this produces a separate listener
117117// for us to alter its value.
118118hexColorLiteral
119- : HexColorLiteral
120- ;
119+ : HexColorLiteral
120+ ;
121121
122122// add color literal notations for
123123// #ff5522
124124HexColorLiteral
125- : ' #' (HexDigit HexDigit)? HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit
126- ;
125+ : ' #' (HexDigit HexDigit)? HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit
126+ ;
127127
128128
129129// hide but do not remove whitespace and comments
130130
131- WS : [ \t\r\n\u000C]+ -> channel(1)
131+ WS : [ \t\r\n\u000C]+ -> channel(1)
132132 ;
133133
134134COMMENT
135- : ' /*' .*? ' */' -> channel(2)
135+ : ' /*' .*? ' */' -> channel(2)
136136 ;
137137
138138LINE_COMMENT
139- : ' //' ~[\r\n]* -> channel(2)
139+ : ' //' ~[\r\n]* -> channel(2)
140140 ;
141141
142- CHAR_LITERAL : ' \' ' (~[' \\\r\n ] | EscapeSequence)* ' \' ' ; // A bit nasty but let JDT tackle invalid chars
142+ CHAR_LITERAL
143+ : ' \' ' (~[' \\\r\n ] | EscapeSequence)* ' \' ' // A bit nasty but let JDT tackle invalid chars
144+ ;
0 commit comments