Repository: groovy Updated Branches: refs/heads/master 0e0e650c2 -> 7a2cdd26b
GROOVY-8312: Deprecate useless features of unicode sequences Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7a2cdd26 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7a2cdd26 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7a2cdd26 Branch: refs/heads/master Commit: 7a2cdd26b7e960d580732dad4470dc2e5fcba9e1 Parents: 0e0e650 Author: sunlan <sun...@apache.org> Authored: Sat Sep 9 02:56:50 2017 +0800 Committer: sunlan <sun...@apache.org> Committed: Sat Sep 9 02:56:50 2017 +0800 ---------------------------------------------------------------------- src/main/antlr/GroovyLexer.g4 | 8 +------- src/tck/test/gls/ch03/s01/Unicode2.groovy | 2 ++ src/tck/test/gls/ch03/s03/UnicodeEscapes1.groovy | 2 ++ src/tck/test/gls/ch03/s03/UnicodeEscapes2.groovy | 4 ++++ .../org/apache/groovy/parser/antlr4/AstBuilder.java | 16 ++-------------- .../groovy/parser/antlr4/util/StringUtils.java | 2 +- .../groovy/parser/antlr4/GroovyParserTest.groovy | 2 ++ 7 files changed, 14 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/src/main/antlr/GroovyLexer.g4 ---------------------------------------------------------------------- diff --git a/src/main/antlr/GroovyLexer.g4 b/src/main/antlr/GroovyLexer.g4 index 9e44ae3..05fb767 100644 --- a/src/main/antlr/GroovyLexer.g4 +++ b/src/main/antlr/GroovyLexer.g4 @@ -677,7 +677,7 @@ OctalEscape // Groovy allows 1 or more u's after the backslash fragment UnicodeEscape - : Backslash 'u'+ HexDigit HexDigit HexDigit HexDigit + : Backslash 'u' HexDigit HexDigit HexDigit HexDigit ; fragment @@ -842,16 +842,10 @@ ELVIS_ASSIGN : '?='; // §3.8 Identifiers (must appear after all keywords in the grammar) CapitalizedIdentifier : [A-Z] JavaLetterOrDigit* - - // FIXME REMOVE THE FOLLOWING ALTERNATIVE. Groovy's identifier can be unicode escape(e.g. def \u4e00\u9fa5 = '123'), which will impact the performance and is pointless to support IMO - | [A-Z] (JavaLetterOrDigit | UnicodeEscape)* ; Identifier : JavaLetter JavaLetterOrDigit* - - // FIXME REMOVE THE FOLLOWING ALTERNATIVE. Groovy's identifier can be unicode escape(e.g. def \u4e00\u9fa5 = '123'), which will impact the performance and is pointless to support IMO - | (JavaLetter | UnicodeEscape) (JavaLetterOrDigit | UnicodeEscape)* ; fragment http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/src/tck/test/gls/ch03/s01/Unicode2.groovy ---------------------------------------------------------------------- diff --git a/src/tck/test/gls/ch03/s01/Unicode2.groovy b/src/tck/test/gls/ch03/s01/Unicode2.groovy index 35fbf72..b845366 100644 --- a/src/tck/test/gls/ch03/s01/Unicode2.groovy +++ b/src/tck/test/gls/ch03/s01/Unicode2.groovy @@ -30,9 +30,11 @@ class Unicode2 extends GroovyTestCase { assert 1 == s.codePointCount(0, s.length()) // number of Unicode code points } + /* void testIdentifiers() { def foo\u0044 = 12 assert 20 == foo\u0044 + 8 } + */ } http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/src/tck/test/gls/ch03/s03/UnicodeEscapes1.groovy ---------------------------------------------------------------------- diff --git a/src/tck/test/gls/ch03/s03/UnicodeEscapes1.groovy b/src/tck/test/gls/ch03/s03/UnicodeEscapes1.groovy index 6411c34..3f23dfd 100644 --- a/src/tck/test/gls/ch03/s03/UnicodeEscapes1.groovy +++ b/src/tck/test/gls/ch03/s03/UnicodeEscapes1.groovy @@ -39,11 +39,13 @@ class UnicodeEscapes1 extends GroovyTestCase { } // There can be 1 or more u's after the backslash + /* void testMultipleUs() { assert "\uu0061" == "a" assert "\uuu0061" == "a" assert "\uuuuu0061" == "a" } + */ void testOtherVariations() { // Capital 'U' not allowed http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/src/tck/test/gls/ch03/s03/UnicodeEscapes2.groovy ---------------------------------------------------------------------- diff --git a/src/tck/test/gls/ch03/s03/UnicodeEscapes2.groovy b/src/tck/test/gls/ch03/s03/UnicodeEscapes2.groovy index 58eafbe..e78a3d7 100644 --- a/src/tck/test/gls/ch03/s03/UnicodeEscapes2.groovy +++ b/src/tck/test/gls/ch03/s03/UnicodeEscapes2.groovy @@ -29,6 +29,7 @@ class UnicodeEscapes2 extends GroovyTestCase { // GLS: If an even number of backslashes precede the 'u', it is not // an escape + /* void testCountBackslash() { def a = 1 assert \u0061 == 1 // char 61 is 'a' @@ -42,10 +43,12 @@ class UnicodeEscapes2 extends GroovyTestCase { assert "\\\u0061".length() == 2 } + */ // GLS: If an eligible \ is followed by u, or more than one u, and the last u // is not followed by four hexadecimal digits, then a compile-time error // occurs. + /* void testFourHexDigits() { // If five digits, only the first four count def \u00610 = 2 @@ -57,6 +60,7 @@ class UnicodeEscapes2 extends GroovyTestCase { // def /u61 = 2 //@fail:parse // def /u061 = 2 //@fail:parse } + */ void testInvalidHexDigits() { // Subsequent lines won't work. The backslash has been replaced by a forward slash http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java index ff7b5e9..521d7aa 100644 --- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -3795,24 +3795,12 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov @Override public String visitClassName(ClassNameContext ctx) { - String text = ctx.getText(); - - if (!text.contains("\\")) { - return text; - } - - return StringUtils.replaceHexEscapes(text); + return ctx.getText(); } @Override public String visitIdentifier(IdentifierContext ctx) { - String text = ctx.getText(); - - if (!text.contains("\\")) { - return text; - } - - return StringUtils.replaceHexEscapes(text); + return ctx.getText(); } http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java index b6e75aa..928f8ab 100644 --- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java +++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; */ public class StringUtils { public static String replaceHexEscapes(String text) { - Pattern p = Pattern.compile("(\\\\*)\\\\u+([0-9abcdefABCDEF]{4})"); + Pattern p = Pattern.compile("(\\\\*)\\\\u([0-9abcdefABCDEF]{4})"); return StringGroovyMethods.replaceAll((CharSequence) text, p, new Closure<Void>(null, null) { Object doCall(String _0, String _1, String _2) { if (isLengthOdd(_1)) { http://git-wip-us.apache.org/repos/asf/groovy/blob/7a2cdd26/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy index 1241112..2d31097 100644 --- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy +++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/GroovyParserTest.groovy @@ -334,9 +334,11 @@ class GroovyParserTest extends GroovyTestCase { doRunAndTest('core/Command_06x.groovy') } + /* void "test groovy core - Unicode"() { doTest('core/Unicode_01.groovy'); } + */ void "test groovy core - BreakingChanges"() { doRunAndTest('core/BreakingChange_01x.groovy');