Skip to content

Commit

Permalink
Unsafe blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Sep 2, 2017
1 parent a8df6d0 commit 3022be4
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 144 deletions.
12 changes: 11 additions & 1 deletion lang/rust/src/rust.fall
Expand Up @@ -32,6 +32,7 @@ tokenizer {
match 'match'
return 'return'
in 'in'
unsafe 'unsafe'

l_paren '('
r_paren ')'
Expand Down Expand Up @@ -645,7 +646,7 @@ fn main() { return; return (); }
#[atom]
pub rule block_expr {
<without_restrictions
<block {block_form* expr?}>
{'unsafe'? <block {block_form* expr?}>}
>
}

Expand All @@ -665,6 +666,15 @@ pub rule expr_stmt {
>
}

test r"
fn main() {
{1};
{1}
{1;}
unsafe { let _ = (); }
}
"

#[atom]
pub rule if_expr {
'if' <commit>
Expand Down
289 changes: 146 additions & 143 deletions lang/rust/src/rust.rs

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions lang/rust/tests/inline.txt
Expand Up @@ -915,6 +915,59 @@ FILE
SEMI ";"
R_CURLY "}"

----------------------------------------
fn main() {
{1};
{1}
{1;}
unsafe { let _ = (); }
}

FILE
FN_DEF
FN "fn"
IDENT "main"
L_PAREN "("
R_PAREN ")"
BLOCK_EXPR
L_CURLY "{"
EXPR_STMT
BLOCK_EXPR
L_CURLY "{"
LITERAL
NUMBER "1"
R_CURLY "}"
EMPTY_STMT
SEMI ";"
EXPR_STMT
BLOCK_EXPR
L_CURLY "{"
LITERAL
NUMBER "1"
R_CURLY "}"
EXPR_STMT
BLOCK_EXPR
L_CURLY "{"
EXPR_STMT
LITERAL
NUMBER "1"
SEMI ";"
R_CURLY "}"
BLOCK_EXPR
UNSAFE "unsafe"
L_CURLY "{"
LET_STMT
LET "let"
WILDCARD_PATTERN
UNDERSCORE "_"
EQ "="
UNIT_EXPR
L_PAREN "("
R_PAREN ")"
SEMI ";"
R_CURLY "}"
R_CURLY "}"

----------------------------------------
fn main() {
if true { foo } else { bar }
Expand Down

0 comments on commit 3022be4

Please sign in to comment.