Skip to content

Commit

Permalink
feat: add support for index expression, loop, while and for loops (#43)
Browse files Browse the repository at this point in the history
Part of #29.

---------

Signed-off-by: Sasha Pourcelot <[email protected]>
  • Loading branch information
scrabsha authored May 1, 2024
1 parent e7a796c commit a9d707f
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro_rules! js_concat {

This emits the following error [^error-message]:
```none
error: Potentially invalid expansion. Expected `::`, `break`, `if`, `return`, a `(`, a `[` or 3 others.
error: Potentially invalid expansion. Expected `::`, `break`, `for`, `if`, `loop`, `return` or 6 others.
--> tests/ui/fail/js_concat.rs:5:16
|
5 | $left ++ $right
Expand Down
33 changes: 33 additions & 0 deletions rust-grammar-dpdfa/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ fn expr_after_atom() {
} else if peek(LParen) {
expr_call();
expr_after_atom();
} else if peek(LBracket) {
// Index expression:
// https://doc.rust-lang.org/reference/expressions/array-expr.html#array-and-slice-indexing-expressions
bump(LBracket);
expr();
bump(RBracket);
} else if peek(Dot) {
expr_dot_expr();
expr_after_atom();
Expand All @@ -203,6 +209,12 @@ fn expr_atom() {
expr_array();
} else if peek(LBrace) {
block();
} else if peek(Loop) {
expr_loop();
} else if peek(While) {
expr_while();
} else if peek(For) {
expr_for();
} else {
error();
}
Expand Down Expand Up @@ -492,3 +504,24 @@ fn expr_tuple_() {
}
}
}

fn expr_loop() {
bump(Loop);
block();
}

fn expr_while() {
bump(While);
// TODO: we must not allow struct expressions here
expr();
block();
}

fn expr_for() {
bump(For);
pat();
bump(In);
// TODO: we must not allow struct expressions here
expr();
block();
}
Loading

0 comments on commit a9d707f

Please sign in to comment.