You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/06/11 12:51:58 UTC
[groovy] branch master updated: GROOVY-8678: allow floating point
literals without leading zeroes
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 80895bc GROOVY-8678: allow floating point literals without leading zeroes
new 8ad3f0e Merge pull request #1588 from nineninesevenfour/GROOVY-8678
80895bc is described below
commit 80895bc72a3706454de294be75ee8b183b2b65f8
Author: Harald Fassler <ha...@gmail.com>
AuthorDate: Sat Jun 5 11:13:37 2021 +0200
GROOVY-8678: allow floating point literals without leading zeroes
fixes https://issues.apache.org/jira/browse/GROOVY-8678
Signed-off-by: Harald Fassler <ha...@gmail.com>
---
src/antlr/GroovyLexer.g4 | 2 +-
src/spec/test/SyntaxTest.groovy | 1 +
src/test/groovy/bugs/Groovy8678.groovy | 38 ++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/src/antlr/GroovyLexer.g4 b/src/antlr/GroovyLexer.g4
index 6eda984..e74acac 100644
--- a/src/antlr/GroovyLexer.g4
+++ b/src/antlr/GroovyLexer.g4
@@ -633,7 +633,7 @@ FloatingPointLiteral
fragment
DecimalFloatingPointLiteral
- : Digits Dot Digits ExponentPart? FloatTypeSuffix?
+ : Digits? Dot Digits ExponentPart? FloatTypeSuffix?
| Digits ExponentPart FloatTypeSuffix?
| Digits FloatTypeSuffix
;
diff --git a/src/spec/test/SyntaxTest.groovy b/src/spec/test/SyntaxTest.groovy
index 694d74c..be9b661 100644
--- a/src/spec/test/SyntaxTest.groovy
+++ b/src/spec/test/SyntaxTest.groovy
@@ -111,6 +111,7 @@ class SyntaxTest extends CompilableTestSupport {
assert 456G == new BigInteger('456')
assert 456g == new BigInteger('456')
assert 123.45 == new BigDecimal('123.45') // default BigDecimal type used
+ assert .321 == new BigDecimal('.321')
assert 1.200065D == new Double('1.200065')
assert 1.234F == new Float('1.234')
assert 1.23E23D == new Double('1.23E23')
diff --git a/src/test/groovy/bugs/Groovy8678.groovy b/src/test/groovy/bugs/Groovy8678.groovy
new file mode 100644
index 0000000..71975f1
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8678.groovy
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs
+
+import groovy.transform.CompileStatic
+import org.junit.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+@CompileStatic
+final class Groovy8678 {
+
+ @Test
+ void testFloatingPointLiteralWithoutLeadingZero() {
+ assertScript '''
+ def aFloat = .42
+ assert (aFloat as String) == '0.42'
+ assert aFloat / .21 == 2
+ assert aFloat / 2 == .21
+ '''
+ }
+}