diff options
author | Aleksey Kladov <[email protected]> | 2018-08-04 15:17:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-04 15:17:20 +0100 |
commit | e4b84fbf36d04e54f68f914f724c8e804233d3aa (patch) | |
tree | 3e38d49ae28b0600c8c17de9488e7de77d8f9cec | |
parent | 82efdff34bf24680bef58eca399ec3f20748a96a (diff) |
Assignment expression
-rw-r--r-- | src/algo/walk.rs | 1 | ||||
-rw-r--r-- | src/grammar/expressions/mod.rs | 14 | ||||
-rw-r--r-- | tests/data/parser/inline/0074_expr_binding_power.rs | 3 | ||||
-rw-r--r-- | tests/data/parser/inline/0074_expr_binding_power.txt | 102 |
4 files changed, 74 insertions, 46 deletions
diff --git a/src/algo/walk.rs b/src/algo/walk.rs index ad0f2d8fb..a50ec2a09 100644 --- a/src/algo/walk.rs +++ b/src/algo/walk.rs | |||
@@ -6,6 +6,7 @@ pub fn preorder<'a>(root: SyntaxNodeRef<'a>) -> impl Iterator<Item = SyntaxNodeR | |||
6 | WalkEvent::Exit(_) => None, | 6 | WalkEvent::Exit(_) => None, |
7 | }) | 7 | }) |
8 | } | 8 | } |
9 | |||
9 | #[derive(Debug, Copy, Clone)] | 10 | #[derive(Debug, Copy, Clone)] |
10 | pub enum WalkEvent<'a> { | 11 | pub enum WalkEvent<'a> { |
11 | Enter(SyntaxNodeRef<'a>), | 12 | Enter(SyntaxNodeRef<'a>), |
diff --git a/src/grammar/expressions/mod.rs b/src/grammar/expressions/mod.rs index cedbc235f..6831aef66 100644 --- a/src/grammar/expressions/mod.rs +++ b/src/grammar/expressions/mod.rs | |||
@@ -35,13 +35,15 @@ struct Restrictions { | |||
35 | 35 | ||
36 | // test expr_binding_power | 36 | // test expr_binding_power |
37 | // fn foo() { | 37 | // fn foo() { |
38 | // 1 + 2 * 3 == 1 * 2 + 3 | 38 | // 1 + 2 * 3 == 1 * 2 + 3; |
39 | // *x = 1 + 1; | ||
39 | // } | 40 | // } |
40 | fn bp_of(op: SyntaxKind) -> u8 { | 41 | fn bp_of(op: SyntaxKind) -> u8 { |
41 | match op { | 42 | match op { |
42 | EQEQ | NEQ => 1, | 43 | EQ => 1, |
43 | MINUS | PLUS => 2, | 44 | EQEQ | NEQ => 2, |
44 | STAR | SLASH => 3, | 45 | MINUS | PLUS => 3, |
46 | STAR | SLASH => 4, | ||
45 | _ => 0 | 47 | _ => 0 |
46 | } | 48 | } |
47 | } | 49 | } |
@@ -106,7 +108,7 @@ fn unary_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { | |||
106 | return Some(postfix_expr(p, lhs)) | 108 | return Some(postfix_expr(p, lhs)) |
107 | } | 109 | } |
108 | }; | 110 | }; |
109 | expr(p); | 111 | unary_expr(p, r); |
110 | Some(m.complete(p, kind)) | 112 | Some(m.complete(p, kind)) |
111 | } | 113 | } |
112 | 114 | ||
@@ -247,7 +249,7 @@ fn struct_lit(p: &mut Parser) { | |||
247 | 249 | ||
248 | fn bin_expr(p: &mut Parser, r: Restrictions, lhs: CompletedMarker, bp: u8) -> CompletedMarker { | 250 | fn bin_expr(p: &mut Parser, r: Restrictions, lhs: CompletedMarker, bp: u8) -> CompletedMarker { |
249 | assert!(match p.current() { | 251 | assert!(match p.current() { |
250 | MINUS | PLUS | STAR | SLASH | EQEQ | NEQ => true, | 252 | MINUS | PLUS | STAR | SLASH | EQEQ | NEQ | EQ => true, |
251 | _ => false, | 253 | _ => false, |
252 | }); | 254 | }); |
253 | let m = lhs.precede(p); | 255 | let m = lhs.precede(p); |
diff --git a/tests/data/parser/inline/0074_expr_binding_power.rs b/tests/data/parser/inline/0074_expr_binding_power.rs index db855fd02..87afb036e 100644 --- a/tests/data/parser/inline/0074_expr_binding_power.rs +++ b/tests/data/parser/inline/0074_expr_binding_power.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | fn foo() { | 1 | fn foo() { |
2 | 1 + 2 * 3 == 1 * 2 + 3 | 2 | 1 + 2 * 3 == 1 * 2 + 3; |
3 | *x = 1 + 1; | ||
3 | } | 4 | } |
diff --git a/tests/data/parser/inline/0074_expr_binding_power.txt b/tests/data/parser/inline/0074_expr_binding_power.txt index 05aad25e9..384fd4354 100644 --- a/tests/data/parser/inline/0074_expr_binding_power.txt +++ b/tests/data/parser/inline/0074_expr_binding_power.txt | |||
@@ -1,5 +1,5 @@ | |||
1 | FILE@[0; 40) | 1 | FILE@[0; 57) |
2 | FN_ITEM@[0; 40) | 2 | FN_ITEM@[0; 57) |
3 | FN_KW@[0; 2) | 3 | FN_KW@[0; 2) |
4 | NAME@[2; 6) | 4 | NAME@[2; 6) |
5 | WHITESPACE@[2; 3) | 5 | WHITESPACE@[2; 3) |
@@ -8,41 +8,65 @@ FILE@[0; 40) | |||
8 | L_PAREN@[6; 7) | 8 | L_PAREN@[6; 7) |
9 | R_PAREN@[7; 8) | 9 | R_PAREN@[7; 8) |
10 | WHITESPACE@[8; 9) | 10 | WHITESPACE@[8; 9) |
11 | BLOCK_EXPR@[9; 40) | 11 | BLOCK_EXPR@[9; 57) |
12 | L_CURLY@[9; 10) | 12 | L_CURLY@[9; 10) |
13 | BIN_EXPR@[10; 38) | 13 | EXPR_STMT@[10; 43) |
14 | BIN_EXPR@[10; 25) | 14 | BIN_EXPR@[10; 37) |
15 | LITERAL@[10; 17) | 15 | BIN_EXPR@[10; 25) |
16 | WHITESPACE@[10; 15) | 16 | LITERAL@[10; 17) |
17 | INT_NUMBER@[15; 16) "1" | 17 | WHITESPACE@[10; 15) |
18 | WHITESPACE@[16; 17) | 18 | INT_NUMBER@[15; 16) "1" |
19 | PLUS@[17; 18) | 19 | WHITESPACE@[16; 17) |
20 | BIN_EXPR@[18; 25) | 20 | PLUS@[17; 18) |
21 | LITERAL@[18; 21) | 21 | BIN_EXPR@[18; 25) |
22 | WHITESPACE@[18; 19) | 22 | LITERAL@[18; 21) |
23 | INT_NUMBER@[19; 20) "2" | 23 | WHITESPACE@[18; 19) |
24 | WHITESPACE@[20; 21) | 24 | INT_NUMBER@[19; 20) "2" |
25 | STAR@[21; 22) | 25 | WHITESPACE@[20; 21) |
26 | LITERAL@[22; 25) | 26 | STAR@[21; 22) |
27 | WHITESPACE@[22; 23) | 27 | LITERAL@[22; 25) |
28 | INT_NUMBER@[23; 24) "3" | 28 | WHITESPACE@[22; 23) |
29 | WHITESPACE@[24; 25) | 29 | INT_NUMBER@[23; 24) "3" |
30 | EQEQ@[25; 27) | 30 | WHITESPACE@[24; 25) |
31 | BIN_EXPR@[27; 38) | 31 | EQEQ@[25; 27) |
32 | BIN_EXPR@[27; 34) | 32 | BIN_EXPR@[27; 37) |
33 | LITERAL@[27; 30) | 33 | BIN_EXPR@[27; 34) |
34 | WHITESPACE@[27; 28) | 34 | LITERAL@[27; 30) |
35 | INT_NUMBER@[28; 29) "1" | 35 | WHITESPACE@[27; 28) |
36 | WHITESPACE@[29; 30) | 36 | INT_NUMBER@[28; 29) "1" |
37 | STAR@[30; 31) | 37 | WHITESPACE@[29; 30) |
38 | LITERAL@[31; 34) | 38 | STAR@[30; 31) |
39 | WHITESPACE@[31; 32) | 39 | LITERAL@[31; 34) |
40 | INT_NUMBER@[32; 33) "2" | 40 | WHITESPACE@[31; 32) |
41 | WHITESPACE@[33; 34) | 41 | INT_NUMBER@[32; 33) "2" |
42 | PLUS@[34; 35) | 42 | WHITESPACE@[33; 34) |
43 | LITERAL@[35; 38) | 43 | PLUS@[34; 35) |
44 | WHITESPACE@[35; 36) | 44 | LITERAL@[35; 37) |
45 | INT_NUMBER@[36; 37) "3" | 45 | WHITESPACE@[35; 36) |
46 | WHITESPACE@[37; 38) | 46 | INT_NUMBER@[36; 37) "3" |
47 | R_CURLY@[38; 39) | 47 | SEMI@[37; 38) |
48 | WHITESPACE@[39; 40) | 48 | WHITESPACE@[38; 43) |
49 | EXPR_STMT@[43; 55) | ||
50 | BIN_EXPR@[43; 53) | ||
51 | DEREF_EXPR@[43; 46) | ||
52 | STAR@[43; 44) | ||
53 | PATH_EXPR@[44; 46) | ||
54 | PATH@[44; 46) | ||
55 | PATH_SEGMENT@[44; 46) | ||
56 | NAME_REF@[44; 46) | ||
57 | IDENT@[44; 45) "x" | ||
58 | WHITESPACE@[45; 46) | ||
59 | EQ@[46; 47) | ||
60 | BIN_EXPR@[47; 53) | ||
61 | LITERAL@[47; 50) | ||
62 | WHITESPACE@[47; 48) | ||
63 | INT_NUMBER@[48; 49) "1" | ||
64 | WHITESPACE@[49; 50) | ||
65 | PLUS@[50; 51) | ||
66 | LITERAL@[51; 53) | ||
67 | WHITESPACE@[51; 52) | ||
68 | INT_NUMBER@[52; 53) "1" | ||
69 | SEMI@[53; 54) | ||
70 | WHITESPACE@[54; 55) | ||
71 | R_CURLY@[55; 56) | ||
72 | WHITESPACE@[56; 57) | ||