Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 393262330 -> 594c1d26d
Validate number with underscore (cherry picked from commit 9849ff1) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/594c1d26 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/594c1d26 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/594c1d26 Branch: refs/heads/GROOVY_2_6_X Commit: 594c1d26d4a59ea1868bf219a52a9220203f9e40 Parents: 3932623 Author: sunlan <sun...@apache.org> Authored: Sun Aug 6 23:54:35 2017 +0800 Committer: sunlan <sun...@apache.org> Committed: Sun Aug 6 23:55:55 2017 +0800 ---------------------------------------------------------------------- src/main/antlr/GroovyLexer.g4 | 14 ++++++++------ .../groovy/parser/antlr4/SyntaxErrorTest.groovy | 3 +++ .../src/test/resources/fail/Number_03x.groovy | 19 +++++++++++++++++++ .../src/test/resources/fail/Number_04x.groovy | 19 +++++++++++++++++++ .../src/test/resources/fail/Number_05x.groovy | 19 +++++++++++++++++++ 5 files changed, 68 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/594c1d26/src/main/antlr/GroovyLexer.g4 ---------------------------------------------------------------------- diff --git a/src/main/antlr/GroovyLexer.g4 b/src/main/antlr/GroovyLexer.g4 index c90302f..6fc7d02 100644 --- a/src/main/antlr/GroovyLexer.g4 +++ b/src/main/antlr/GroovyLexer.g4 @@ -441,10 +441,11 @@ WHILE : 'while'; // §3.10.1 Integer Literals IntegerLiteral - : DecimalIntegerLiteral - | HexIntegerLiteral - | OctalIntegerLiteral - | BinaryIntegerLiteral + : ( DecimalIntegerLiteral + | HexIntegerLiteral + | OctalIntegerLiteral + | BinaryIntegerLiteral + ) (Underscore { require(false, "Invalid number", -1, true); })? // !!! Error Alternative !!! | Zero ([0-9] { invalidDigitCount++; })+ { require(false, "Invalid octal number", -(invalidDigitCount + 1), true); } IntegerTypeSuffix? @@ -584,8 +585,9 @@ BinaryDigitOrUnderscore // §3.10.2 Floating-Point Literals FloatingPointLiteral - : DecimalFloatingPointLiteral - | HexadecimalFloatingPointLiteral + : ( DecimalFloatingPointLiteral + | HexadecimalFloatingPointLiteral + ) (Underscore { require(false, "Invalid number", -1, true); })? ; fragment http://git-wip-us.apache.org/repos/asf/groovy/blob/594c1d26/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy index f29c1e1..bb4aeac 100644 --- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy +++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy @@ -200,6 +200,9 @@ class SyntaxErrorTest extends GroovyTestCase { void "test groovy core - Number"() { TestUtils.doRunAndShouldFail('fail/Number_01x.groovy'); TestUtils.doRunAndShouldFail('fail/Number_02x.groovy'); + TestUtils.doRunAndShouldFail('fail/Number_03x.groovy'); + TestUtils.doRunAndShouldFail('fail/Number_04x.groovy'); + TestUtils.doRunAndShouldFail('fail/Number_05x.groovy'); } /**************************************/ http://git-wip-us.apache.org/repos/asf/groovy/blob/594c1d26/subprojects/parser-antlr4/src/test/resources/fail/Number_03x.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/resources/fail/Number_03x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/Number_03x.groovy new file mode 100644 index 0000000..d560dc7 --- /dev/null +++ b/subprojects/parser-antlr4/src/test/resources/fail/Number_03x.groovy @@ -0,0 +1,19 @@ +/* + * 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. + */ +10101_ http://git-wip-us.apache.org/repos/asf/groovy/blob/594c1d26/subprojects/parser-antlr4/src/test/resources/fail/Number_04x.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/resources/fail/Number_04x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/Number_04x.groovy new file mode 100644 index 0000000..ae41101 --- /dev/null +++ b/subprojects/parser-antlr4/src/test/resources/fail/Number_04x.groovy @@ -0,0 +1,19 @@ +/* + * 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. + */ +10101_.0 http://git-wip-us.apache.org/repos/asf/groovy/blob/594c1d26/subprojects/parser-antlr4/src/test/resources/fail/Number_05x.groovy ---------------------------------------------------------------------- diff --git a/subprojects/parser-antlr4/src/test/resources/fail/Number_05x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/Number_05x.groovy new file mode 100644 index 0000000..2ac3916 --- /dev/null +++ b/subprojects/parser-antlr4/src/test/resources/fail/Number_05x.groovy @@ -0,0 +1,19 @@ +/* + * 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. + */ +10101.0_