Skip to content

Commit d816afe

Browse files
committed
Fix issue with continue_* names
1 parent 674f906 commit d816afe

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,8 @@ private static void loops(LexerlessGrammarBuilder b) {
15061506
b.rule(BREAK_EXPRESSION).is(RustKeyword.KW_BREAK, SPC, b.optional(LIFETIME_OR_LABEL, SPC), b.optional(EXPRESSION, SPC));
15071507
b.rule(BOX_EXPRESSION).is(RustKeyword.KW_BOX, SPC, EXPRESSION);
15081508
b.rule(CONTINUE_EXPRESSION).is(
1509-
RustKeyword.KW_CONTINUE, b.optional(SPC, LIFETIME_OR_LABEL));
1509+
RustKeyword.KW_CONTINUE, b.optional(SPC, LIFETIME_OR_LABEL),
1510+
b.nextNot(IDENTIFIER));
15101511

15111512
}
15121513

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,39 @@ void testNumRange() {
123123

124124
parser.parse(sexpr);
125125
}
126+
127+
@Test
128+
void testContinueProcessingCondition() {
129+
String source =
130+
"fn process_event() {\n" +
131+
" let reward_fut = client.transfer_rewards(process_reward_rx);\n" +
132+
" let (_res1, _res2) = tokio::join!(process_event_fut, reward_fut);\n" +
133+
"\n" +
134+
" if let Err(err) = super::state::del(\"quest\", \".\", redis_pool.clone()).await {\n" +
135+
" tracing::error!(\"fail to remove quest from queue due to {err}\");\n" +
136+
" }\n" +
137+
"\n" +
138+
" tracing::info!(\"process event sleep for 15 sec\");\n" +
139+
" tokio::time::sleep(std::time::Duration::from_secs(15)).await;\n" +
140+
"\n" +
141+
" let continue_processing = true;\n" +
142+
" if !continue_processing {\n" +
143+
" println!(\"Stopping processing\");\n" +
144+
" }\n" +
145+
"}";
146+
147+
ParserAdapter parser = new ParserAdapter<>(
148+
StandardCharsets.UTF_8, RustGrammar.create().build()
149+
);
150+
151+
// Expect this to be parsed successfully or reproduce the issue
152+
AstNode rootNode = parser.parse(source);
153+
154+
// Debug output
155+
System.out.println(AstXmlPrinter.print(rootNode));
156+
157+
// Ensure parsing is successful
158+
assertThat(rootNode).isNotNull();
159+
}
160+
126161
}

0 commit comments

Comments
 (0)