Skip to content

Commit 809d460

Browse files
committed
Resolves #240 through grammar.
It's not the cleanest solution but I don't see too many alternatives. Modify grammar to explicitly allow the color literal to appear in fully qualified name.
1 parent ba43e4d commit 809d460

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

java/src/processing/mode/java/preproc/Processing.g4

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* - changes main entry point to reflect sketch types 'static' | 'active'
55
* - adds support for type converter functions like "int()"
66
* - adds pseudo primitive type "color"
7-
* - adds HTML hex notation with hash symbol: #ff5522
7+
* - adds HTML hex notation with hash symbol: #ff5522
8+
* - allow color to appear as part of qualified names (like in imports)
89
*/
910

1011
grammar Processing;
@@ -47,8 +48,8 @@ variableDeclaratorId
4748
// https://github.com/processing/processing/issues/93
4849
// prevent from types being used as variable names
4950
warnTypeAsVariableName
50-
: primitiveType ('[' ']')* {
51-
notifyErrorListeners("Type names are not allowed as variable names: "+$primitiveType.text);
51+
: primitiveType ('[' ']')* {
52+
notifyErrorListeners("Type names are not allowed as variable names: "+$primitiveType.text);
5253
}
5354
;
5455

@@ -89,6 +90,10 @@ colorPrimitiveType
8990
: 'color'
9091
;
9192

93+
qualifiedName
94+
: (IDENTIFIER | colorPrimitiveType) ('.' (IDENTIFIER | colorPrimitiveType))*
95+
;
96+
9297
// added HexColorLiteral
9398
literal
9499
: integerLiteral
@@ -127,4 +132,3 @@ LINE_COMMENT
127132
;
128133

129134
CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence)* '\''; // A bit nasty but let JDT tackle invalid chars
130-

java/test/resources/colorimport.expected

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import processing.data.*;
33
import processing.event.*;
44
import processing.opengl.*;
55

6+
import test.color;
7+
68
import java.util.HashMap;
79
import java.util.ArrayList;
810
import java.io.File;
@@ -12,19 +14,18 @@ import java.io.InputStream;
1214
import java.io.OutputStream;
1315
import java.io.IOException;
1416

15-
import test.color;
16-
1717
public class colorimport extends PApplet {
1818

1919
public void setup() {
20+
21+
2022
boolean test = true;
21-
int c1 = color(255, 255, 255);
22-
int c2 = test ? 0xFFA011CD : 0xC0C0C0C0;
23-
noLoop();
23+
24+
noLoop();
2425
}
2526

2627
static public void main(String[] passedArgs) {
27-
String[] appletArgs = new String[] { "color" };
28+
String[] appletArgs = new String[] { "colorimport" };
2829
if (passedArgs != null) {
2930
PApplet.main(concat(appletArgs, passedArgs));
3031
} else {

java/test/resources/colorimport.pde

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import test.color;
22

33
boolean test = true;
4-
color c1 = color(255, 255, 255);
5-
color c2 = test ? #A011CD : #C0C0C0C0;

0 commit comments

Comments
 (0)