Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix color in appearing in fully qualified names. #246

Merged
merged 5 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions java/src/processing/mode/java/preproc/Processing.g4
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* - changes main entry point to reflect sketch types 'static' | 'active'
* - adds support for type converter functions like "int()"
* - adds pseudo primitive type "color"
* - adds HTML hex notation with hash symbol: #ff5522
* - adds HTML hex notation with hash symbol: #ff5522
* - allow color to appear as part of qualified names (like in imports)
*/

grammar Processing;
Expand Down Expand Up @@ -47,8 +48,8 @@ variableDeclaratorId
// https://github.com/processing/processing/issues/93
// prevent from types being used as variable names
warnTypeAsVariableName
: primitiveType ('[' ']')* {
notifyErrorListeners("Type names are not allowed as variable names: "+$primitiveType.text);
: primitiveType ('[' ']')* {
notifyErrorListeners("Type names are not allowed as variable names: "+$primitiveType.text);
}
;

Expand Down Expand Up @@ -89,6 +90,10 @@ colorPrimitiveType
: 'color'
;

qualifiedName
: (IDENTIFIER | colorPrimitiveType) ('.' (IDENTIFIER | colorPrimitiveType))*
;

// added HexColorLiteral
literal
: integerLiteral
Expand Down Expand Up @@ -127,4 +132,3 @@ LINE_COMMENT
;

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

5 changes: 5 additions & 0 deletions java/test/processing/mode/java/ParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,9 @@ public void testSmoothWithParamStatic() {
expectGood("smoothparamstatic");
}

@Test
public void testColorInImport() {
expectGood("colorimport");
}

}
37 changes: 37 additions & 0 deletions java/test/resources/colorimport.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import test.color;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class colorimport extends PApplet {

public void setup() {


boolean test = true;
int c1 = color(255, 255, 255);
int c2 = test ? 0xFFA011CD : 0xC0C0C0C0;

noLoop();
}

static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "colorimport" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
5 changes: 5 additions & 0 deletions java/test/resources/colorimport.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test.color;

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