Skip to content

Commit 3cc4e7b

Browse files
alban-auzeillpynicolas
authored andcommitted
Fix ARGLIST grammar rule that was entirely optional
1 parent 1897b27 commit 3cc4e7b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

python-squid/src/main/java/org/sonar/python/api/PythonGrammar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static void grammar(LexerfulGrammarBuilder b) {
226226
b.firstOf(COMP_FOR, b.sequence(b.zeroOrMore(",", b.firstOf(b.sequence(TEST, ":", TEST), b.sequence("**", EXPR))), b.optional(",")))),
227227
b.sequence(b.firstOf(TEST, STAR_EXPR), b.firstOf(COMP_FOR, b.sequence(b.zeroOrMore(",", b.firstOf(TEST, STAR_EXPR)), b.optional(","))))));
228228

229-
b.rule(ARGLIST).is(b.optional(ARGUMENT, b.zeroOrMore(",", ARGUMENT), b.optional(",")));
229+
b.rule(ARGLIST).is(ARGUMENT, b.zeroOrMore(",", ARGUMENT), b.optional(","));
230230
b.rule(ARGUMENT).is(b.firstOf(
231231
b.sequence("*", TEST),
232232
b.sequence("**", TEST),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SonarQube Python Plugin
3+
* Copyright (C) 2011-2017 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonar.python.parser.expressions;
21+
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
import org.sonar.python.api.PythonGrammar;
25+
import org.sonar.python.parser.RuleTest;
26+
27+
import static org.sonar.sslr.tests.Assertions.assertThat;
28+
29+
public class ArgumentListTest extends RuleTest {
30+
31+
@Before
32+
public void init() {
33+
setRootRule(PythonGrammar.ARGLIST);
34+
}
35+
36+
@Test
37+
public void arg_list() {
38+
assertThat(p).matches("1");
39+
assertThat(p).matches("a, b");
40+
assertThat(p).notMatches("");
41+
}
42+
43+
}

0 commit comments

Comments
 (0)