Skip to content

Commit f9cf71a

Browse files
authored
fix parsing Issues from #45 (#46)
* fix parsing outer attributes on struct fields * fix parsing if expressions when condition include dereference expressions
1 parent bf23ead commit f9cf71a

File tree

6 files changed

+100
-708
lines changed

6 files changed

+100
-708
lines changed

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

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testTokens() {
6868

6969
@Test
7070
public void testParsing() {
71-
String sexpr = "let foo = &i|i;";
71+
String sexpr = "*bar == None { true };";
7272

7373
//Print out Ast node content for debugging purpose
7474

community-rust-frontend/src/test/java/org/sonar/rust/parser/expressions/ExpressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ExpressionTest {
2929

3030
@Test
3131
public void testScrutinee() {
32-
assertThat(RustGrammar.create().build().rule(RustGrammar.SCRUTINEE))
32+
assertThat(RustGrammar.create().build().rule(RustGrammar.EXPRESSION_EXCEPT_STRUCT))
3333
.matches("a")
3434
.matches("a || b")
3535
.matches("a() || b")

community-rust-frontend/src/test/java/org/sonar/rust/parser/expressions/IfExpressionTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,18 @@ public void tesIfExpression() {
130130
" \n" +
131131
" break;\n" +
132132
" }")
133-
/*TODO .matches("if next.iter().all(|&i| i == 42) {\n" +
133+
.matches("if next.iter().all(|&i| i == 42) {\n" +
134134
" \n" +
135135
" break;\n" +
136136
" }")
137137

138-
*/
138+
.matches("if *bar == None {\n" +
139+
" true\n" +
140+
" } else {\n" +
141+
" LOG_WARNING!(\"condition is false\");\n" +
142+
" false\n" +
143+
" }")
144+
139145

140146

141147
;

community-rust-frontend/src/test/java/org/sonar/rust/parser/items/StructTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ public void testStruct() {
3939
" pub granted_list: HashSet<T>,\n" +
4040
" pub denied_list: HashSet<T>,\n" +
4141
"}")
42-
42+
.matches("struct Message<'a> {\n" +
43+
" #[serde(rename = \"c\")]\n" +
44+
" command: Command,\n" +
45+
" #[serde(borrow)]\n" +
46+
" payload: Option<Cow<'a, str>>,\n" +
47+
" #[serde(rename = \"s\")]\n" +
48+
" identifier: Option<u16>,\n" +
49+
"}")
4350
;
4451

4552
}

0 commit comments

Comments
 (0)