Skip to content

Commit 19afaf1

Browse files
committed
Fix issue with num ranges
1 parent f6815e4 commit 19afaf1

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

community-rust-checks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.elegoff</groupId>
88
<artifactId>community-rust</artifactId>
9-
<version>0.3.0</version>
9+
<version>0.2.6</version>
1010
</parent>
1111

1212
<artifactId>community-rust-checks</artifactId>

community-rust-frontend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.elegoff</groupId>
88
<artifactId>community-rust</artifactId>
9-
<version>0.3.0</version>
9+
<version>0.2.6</version>
1010
</parent>
1111

1212
<artifactId>community-rust-frontend</artifactId>

community-rust-frontend/src/main/java/org/sonar/rust/RustGrammar.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,9 +908,14 @@ private static void patterns(LexerlessGrammarBuilder b) {
908908
PATTERN_NO_TOP_ALT, SPC,
909909
b.zeroOrMore(b.sequence(RustPunctuator.OR, SPC, PATTERN_NO_TOP_ALT, SPC)));
910910
b.rule(PATTERN_NO_TOP_ALT).is(b.firstOf(
911-
RANGE_PATTERN,
912-
PATTERN_WITHOUT_RANGE));
913-
911+
b.sequence(
912+
INTEGER_LITERAL,
913+
RustPunctuator.DOTDOT,
914+
INTEGER_LITERAL
915+
),
916+
RANGE_PATTERN,
917+
PATTERN_WITHOUT_RANGE
918+
));
914919
b.rule(PATTERN_WITHOUT_RANGE).is(b.firstOf(
915920
TUPLE_STRUCT_PATTERN,
916921
STRUCT_PATTERN,
@@ -961,7 +966,26 @@ private static void patterns(LexerlessGrammarBuilder b) {
961966
b.rule(WILDCARD_PATTERN).is(RustPunctuator.UNDERSCORE);
962967
b.rule(REST_PATTERN).is(RustPunctuator.DOTDOT);
963968

964-
b.rule(RANGE_PATTERN).is(b.firstOf(OBSOLETE_RANGE_PATTERN, INCLUSIVE_RANGE_PATTERN, HALF_OPEN_RANGE_PATTERN));
969+
b.rule(RANGE_PATTERN).is(b.firstOf(
970+
OBSOLETE_RANGE_PATTERN,
971+
INCLUSIVE_RANGE_PATTERN,
972+
HALF_OPEN_RANGE_PATTERN,
973+
b.sequence(
974+
INTEGER_LITERAL,
975+
RustPunctuator.DOTDOT,
976+
INTEGER_LITERAL
977+
),
978+
// Left-unbounded range: ..5
979+
b.sequence(
980+
RustPunctuator.DOTDOT,
981+
INTEGER_LITERAL
982+
),
983+
// Right-unbounded range: 5..
984+
b.sequence(
985+
INTEGER_LITERAL,
986+
RustPunctuator.DOTDOT
987+
)
988+
));
965989
b.rule(INCLUSIVE_RANGE_PATTERN).is(b.sequence(RANGE_PATTERN_BOUND, SPC, RustPunctuator.DOTDOTEQ, SPC, RANGE_PATTERN_BOUND));
966990
b.rule(HALF_OPEN_RANGE_PATTERN).is(b.sequence(RANGE_PATTERN_BOUND, SPC, RustPunctuator.DOTDOT));
967991
b.rule(OBSOLETE_RANGE_PATTERN).is(b.sequence(RANGE_PATTERN_BOUND, SPC, RustPunctuator.DOTDOTDOT, SPC, RANGE_PATTERN_BOUND));

community-rust-frontend/src/test/java/org/sonar/rust/RustLexerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,21 @@ private void testImportParsing(String filename) {
106106

107107
parser.parse(sexpr);
108108
}
109+
110+
@Test
111+
void testNumRange() {
112+
String sexpr = "\n" +
113+
"fn get_referral_tier(referrals_count: i64) -> Result<i64, CustomError> {\n" +
114+
" match referrals_count {\n" +
115+
" ..0 => Ok(0),\n" +
116+
" 1 => Ok(1),\n" +
117+
" 2..5 => Ok(2)\n" +
118+
" 5.. => Ok(3)\n" +
119+
" }\n" +
120+
"}";
121+
ParserAdapter<LexerlessGrammar> parser = new ParserAdapter<>(
122+
StandardCharsets.UTF_8, RustGrammar.create().build());
123+
124+
parser.parse(sexpr);
125+
}
109126
}

community-rust-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.elegoff</groupId>
99
<artifactId>community-rust</artifactId>
10-
<version>0.3.0</version>
10+
<version>0.2.6</version>
1111
</parent>
1212
<artifactId>community-rust-plugin</artifactId>
1313
<packaging>sonar-plugin</packaging>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.elegoff</groupId>
88
<artifactId>community-rust</artifactId>
9-
<version>0.3.0</version>
9+
<version>0.2.6</version>
1010

1111
<packaging>pom</packaging>
1212

@@ -62,7 +62,7 @@
6262
<properties>
6363
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6464
<sonar.version>10.7.0.96327</sonar.version>
65-
<sonar.plugin.api.version>11.1.0.2693</sonar.plugin.api.version>
65+
<sonar.plugin.api.version>10.11.0.2468</sonar.plugin.api.version>
6666

6767

6868
<!-- Advertise minimal required JRE version -->

0 commit comments

Comments
 (0)