From ad5c27ec42dc6f479c1c4cee2b119568ba8fa252 Mon Sep 17 00:00:00 2001 From: Stef Tervelde Date: Mon, 17 Mar 2025 15:11:24 +0100 Subject: [PATCH] Apply same parser & lexer fixes from before --- .gitignore | 1 + java/preprocessor/src/main/antlr/JavaLexer.g4 | 2 ++ java/preprocessor/src/main/antlr/JavaParser.g4 | 15 ++++++++++++++- .../processing/mode/java/preproc/Processing.g4 | 15 +++------------ .../src/main/java/processing/app/Preferences.java | 2 +- java/test/resources/bug1532.pde | 6 +++--- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 7faa26d70..0e321ec1a 100644 --- a/.gitignore +++ b/.gitignore @@ -108,6 +108,7 @@ java/build/ /java/libraries/svg/bin /java/preprocessor/build /java/lsp/build +/java/gradle/build /.kotlin/sessions /core/examples/build diff --git a/java/preprocessor/src/main/antlr/JavaLexer.g4 b/java/preprocessor/src/main/antlr/JavaLexer.g4 index b3de61fea..b924864ea 100644 --- a/java/preprocessor/src/main/antlr/JavaLexer.g4 +++ b/java/preprocessor/src/main/antlr/JavaLexer.g4 @@ -134,6 +134,8 @@ CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\''; STRING_LITERAL: '"' (~["\\\r\n] | EscapeSequence)* '"'; +MULTI_STRING_LIT: '"""' (~[\\] | EscapeSequence)*? '"""'; + TEXT_BLOCK: '"""' [ \t]* [\r\n] (. | EscapeSequence)*? '"""'; NULL_LITERAL: 'null'; diff --git a/java/preprocessor/src/main/antlr/JavaParser.g4 b/java/preprocessor/src/main/antlr/JavaParser.g4 index 1fa8ced28..d273fa888 100644 --- a/java/preprocessor/src/main/antlr/JavaParser.g4 +++ b/java/preprocessor/src/main/antlr/JavaParser.g4 @@ -314,11 +314,24 @@ qualifiedName : identifier ('.' identifier)* ; +baseStringLiteral + : STRING_LITERAL + ; + +multilineStringLiteral + : MULTI_STRING_LIT + ; + +stringLiteral + : baseStringLiteral + | multilineStringLiteral + ; + literal : integerLiteral | floatLiteral | CHAR_LITERAL - | STRING_LITERAL + | stringLiteral | BOOL_LITERAL | NULL_LITERAL | TEXT_BLOCK // Java17 diff --git a/java/preprocessor/src/main/antlr/processing/mode/java/preproc/Processing.g4 b/java/preprocessor/src/main/antlr/processing/mode/java/preproc/Processing.g4 index f16f5ba31..2d4edc041 100644 --- a/java/preprocessor/src/main/antlr/processing/mode/java/preproc/Processing.g4 +++ b/java/preprocessor/src/main/antlr/processing/mode/java/preproc/Processing.g4 @@ -27,7 +27,7 @@ processingSketch : staticProcessingSketch | javaProcessingSketch | activeProcessingSketch - | warnMixedModes +// | warnMixedModes ; // java mode, is a compilation unit @@ -111,7 +111,7 @@ literal : integerLiteral | floatLiteral | CHAR_LITERAL - | STRING_LITERAL + | stringLiteral | BOOL_LITERAL | NULL_LITERAL | hexColorLiteral @@ -144,13 +144,4 @@ LINE_COMMENT CHAR_LITERAL : '\'' (~['\\\r\n] | EscapeSequence)* '\'' // A bit nasty but let JDT tackle invalid chars - ; - -// Parser Rules -multilineStringLiteral - : MULTILINE_STRING_START .*? MULTILINE_STRING_END - ; - -// Lexer Rules -MULTILINE_STRING_START: '"""' '\r'? '\n'; -MULTILINE_STRING_END: '"""'; \ No newline at end of file + ; \ No newline at end of file diff --git a/java/preprocessor/src/main/java/processing/app/Preferences.java b/java/preprocessor/src/main/java/processing/app/Preferences.java index 7ce476fde..eab3a2397 100644 --- a/java/preprocessor/src/main/java/processing/app/Preferences.java +++ b/java/preprocessor/src/main/java/processing/app/Preferences.java @@ -58,7 +58,7 @@ public class Preferences { } } static public boolean getBoolean(String attribute) { - String value = get(attribute); //, null); + String value = get(attribute); return Boolean.parseBoolean(value); } static public int getInteger(String attribute /*, int defaultValue*/) { diff --git a/java/test/resources/bug1532.pde b/java/test/resources/bug1532.pde index 66b24b777..ae8ecdbf8 100644 --- a/java/test/resources/bug1532.pde +++ b/java/test/resources/bug1532.pde @@ -20,9 +20,9 @@ flatCube[][] grid; void setup() { try { - quicktime.QTSession.open(); - } - catch (quicktime.QTException qte) { + // quicktime.QTSession.open(); + } + catch (quicktime.QTException qte) { qte.printStackTrace(); }