groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch GROOVY_2_5_X updated: GROOVY-9034: adjust Java grammar for underscore in numeric literals
Date Fri, 15 Mar 2019 02:43:47 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
     new 52f6146  GROOVY-9034: adjust Java grammar for underscore in numeric literals
52f6146 is described below

commit 52f61464e39af4dc015165eee8729b2ec4943af0
Author: Paul King <paulk@asert.com.au>
AuthorDate: Fri Mar 15 12:41:53 2019 +1000

    GROOVY-9034: adjust Java grammar for underscore in numeric literals
    
    (fixes some Groovydoc parse errors of Java files)
---
 .../antlr2/org/codehaus/groovy/antlr/java/java.g   | 32 ++++++++++++++++++++--
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g b/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
index 896c40b..2386ff3 100644
--- a/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
+++ b/src/main/antlr2/org/codehaus/groovy/antlr/java/java.g
@@ -1918,6 +1918,30 @@ IDENT
 		}
 	;
 
+protected
+DIGIT
+options {
+    paraphrase="a digit";
+}
+    :   '0'..'9'
+    // TODO:  Recognize all the Java identifier parts here (except '$').
+    ;
+
+protected
+DIGITS_WITH_UNDERSCORE
+options {
+    paraphrase="a sequence of digits and underscores, bordered by digits";
+}
+    :   DIGIT (DIGITS_WITH_UNDERSCORE_OPT)?
+    ;
+
+protected
+DIGITS_WITH_UNDERSCORE_OPT
+options {
+    paraphrase="a sequence of digits and underscores with maybe underscore starting";
+}
+    :   (DIGIT | '_')* DIGIT
+    ;
 
 // a numeric literal
 NUM_INT
@@ -1953,17 +1977,19 @@ NUM_INT
 				)+
 
 			|	//float or double with leading zero
-				(('0'..'9')+ ('.'|EXPONENT|FLOAT_SUFFIX)) => ('0'..'9')+
+                (   DIGITS_WITH_UNDERSCORE
+                    ( '.' DIGITS_WITH_UNDERSCORE | EXPONENT | FLOAT_SUFFIX)
+                ) => DIGITS_WITH_UNDERSCORE
 
 			|	('0'..'7')+									// octal
 			)?
-		|	('1'..'9') ('0'..'9')*  {isDecimal=true;}		// non-zero decimal
+		|	('1'..'9') (DIGITS_WITH_UNDERSCORE_OPT)?  {isDecimal=true;}		// non-zero decimal
 		)
 		(	('l'|'L') { _ttype = NUM_LONG; }
 
 		// only check to see if it's a float if looks like decimal so far
 		|	{isDecimal}?
-			(	'.' ('0'..'9')* (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
+			(	'.' DIGITS_WITH_UNDERSCORE (EXPONENT)? (f2:FLOAT_SUFFIX {t=f2;})?
 			|	EXPONENT (f3:FLOAT_SUFFIX {t=f3;})?
 			|	f4:FLOAT_SUFFIX {t=f4;}
 			)


Mime
View raw message