From 809d460f443b8b6de9bc195ff8f525bb5a584158 Mon Sep 17 00:00:00 2001 From: A Pottinger Date: Wed, 11 Aug 2021 08:45:19 -0700 Subject: [PATCH] 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. --- java/src/processing/mode/java/preproc/Processing.g4 | 12 ++++++++---- java/test/resources/colorimport.expected | 13 +++++++------ java/test/resources/colorimport.pde | 2 -- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/java/src/processing/mode/java/preproc/Processing.g4 b/java/src/processing/mode/java/preproc/Processing.g4 index 2b822f9d9..713f28ba5 100644 --- a/java/src/processing/mode/java/preproc/Processing.g4 +++ b/java/src/processing/mode/java/preproc/Processing.g4 @@ -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; @@ -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); } ; @@ -89,6 +90,10 @@ colorPrimitiveType : 'color' ; +qualifiedName + : (IDENTIFIER | colorPrimitiveType) ('.' (IDENTIFIER | colorPrimitiveType))* + ; + // added HexColorLiteral literal : integerLiteral @@ -127,4 +132,3 @@ LINE_COMMENT ; CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence)* '\''; // A bit nasty but let JDT tackle invalid chars - diff --git a/java/test/resources/colorimport.expected b/java/test/resources/colorimport.expected index 97c801b27..9933cc2aa 100644 --- a/java/test/resources/colorimport.expected +++ b/java/test/resources/colorimport.expected @@ -3,6 +3,8 @@ import processing.data.*; import processing.event.*; import processing.opengl.*; +import test.color; + import java.util.HashMap; import java.util.ArrayList; import java.io.File; @@ -12,19 +14,18 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; -import test.color; - public class colorimport extends PApplet { public void setup() { + + boolean test = true; -int c1 = color(255, 255, 255); -int c2 = test ? 0xFFA011CD : 0xC0C0C0C0; - noLoop(); + + noLoop(); } static public void main(String[] passedArgs) { - String[] appletArgs = new String[] { "color" }; + String[] appletArgs = new String[] { "colorimport" }; if (passedArgs != null) { PApplet.main(concat(appletArgs, passedArgs)); } else { diff --git a/java/test/resources/colorimport.pde b/java/test/resources/colorimport.pde index 2da84c3a1..0b9321052 100644 --- a/java/test/resources/colorimport.pde +++ b/java/test/resources/colorimport.pde @@ -1,5 +1,3 @@ import test.color; boolean test = true; -color c1 = color(255, 255, 255); -color c2 = test ? #A011CD : #C0C0C0C0;