diff options
author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2018-07-31 18:44:54 +0100 |
---|---|---|
committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2018-07-31 18:44:54 +0100 |
commit | 599ca1ad890f7b8e1e3919f1727c21dad353f595 (patch) | |
tree | 099b6ed3bd1075daa03594211f3f1246659a2467 | |
parent | ce3462ce8fed8bb86d887643479c73908fc326a3 (diff) |
dref-expr
-rw-r--r-- | src/grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/grammar/expressions.rs | 13 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0062_deref_expr.rs | 3 | ||||
-rw-r--r-- | tests/data/parser/inline/0062_deref_expr.txt | 26 |
5 files changed, 45 insertions, 0 deletions
diff --git a/src/grammar.ron b/src/grammar.ron index 564249200..aa01cb205 100644 --- a/src/grammar.ron +++ b/src/grammar.ron | |||
@@ -129,6 +129,7 @@ Grammar( | |||
129 | "METHOD_CALL_EXPR", | 129 | "METHOD_CALL_EXPR", |
130 | "FIELD_EXPR", | 130 | "FIELD_EXPR", |
131 | "REF_EXPR", | 131 | "REF_EXPR", |
132 | "DEREF_EXPR", | ||
132 | "STRUCT_LIT", | 133 | "STRUCT_LIT", |
133 | "STRUCT_LIT_FIELD", | 134 | "STRUCT_LIT_FIELD", |
134 | 135 | ||
diff --git a/src/parser/grammar/expressions.rs b/src/parser/grammar/expressions.rs index 5b18e2294..881d947ac 100644 --- a/src/parser/grammar/expressions.rs +++ b/src/parser/grammar/expressions.rs | |||
@@ -48,6 +48,7 @@ pub(super) fn expr(p: &mut Parser) { | |||
48 | fn prefix_expr(p: &mut Parser) -> Option<CompletedMarker> { | 48 | fn prefix_expr(p: &mut Parser) -> Option<CompletedMarker> { |
49 | match p.current() { | 49 | match p.current() { |
50 | AMPERSAND => Some(ref_expr(p)), | 50 | AMPERSAND => Some(ref_expr(p)), |
51 | STAR => Some(deref_expr(p)), | ||
51 | _ => atom_expr(p), | 52 | _ => atom_expr(p), |
52 | } | 53 | } |
53 | } | 54 | } |
@@ -66,6 +67,18 @@ fn ref_expr(p: &mut Parser) -> CompletedMarker { | |||
66 | m.complete(p, REF_EXPR) | 67 | m.complete(p, REF_EXPR) |
67 | } | 68 | } |
68 | 69 | ||
70 | // test deref_expr | ||
71 | // fn foo() { | ||
72 | // **&1; | ||
73 | // } | ||
74 | fn deref_expr(p: &mut Parser) -> CompletedMarker { | ||
75 | assert!(p.at(STAR)); | ||
76 | let m = p.start(); | ||
77 | p.bump(); | ||
78 | expr(p); | ||
79 | m.complete(p, DEREF_EXPR) | ||
80 | } | ||
81 | |||
69 | fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> { | 82 | fn atom_expr(p: &mut Parser) -> Option<CompletedMarker> { |
70 | match literal(p) { | 83 | match literal(p) { |
71 | Some(m) => return Some(m), | 84 | Some(m) => return Some(m), |
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index 655764528..a37fdea0b 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs | |||
@@ -120,6 +120,7 @@ pub enum SyntaxKind { | |||
120 | METHOD_CALL_EXPR, | 120 | METHOD_CALL_EXPR, |
121 | FIELD_EXPR, | 121 | FIELD_EXPR, |
122 | REF_EXPR, | 122 | REF_EXPR, |
123 | DEREF_EXPR, | ||
123 | STRUCT_LIT, | 124 | STRUCT_LIT, |
124 | STRUCT_LIT_FIELD, | 125 | STRUCT_LIT_FIELD, |
125 | EXTERN_BLOCK, | 126 | EXTERN_BLOCK, |
@@ -279,6 +280,7 @@ impl SyntaxKind { | |||
279 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, | 280 | METHOD_CALL_EXPR => &SyntaxInfo { name: "METHOD_CALL_EXPR" }, |
280 | FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" }, | 281 | FIELD_EXPR => &SyntaxInfo { name: "FIELD_EXPR" }, |
281 | REF_EXPR => &SyntaxInfo { name: "REF_EXPR" }, | 282 | REF_EXPR => &SyntaxInfo { name: "REF_EXPR" }, |
283 | DEREF_EXPR => &SyntaxInfo { name: "DEREF_EXPR" }, | ||
282 | STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" }, | 284 | STRUCT_LIT => &SyntaxInfo { name: "STRUCT_LIT" }, |
283 | STRUCT_LIT_FIELD => &SyntaxInfo { name: "STRUCT_LIT_FIELD" }, | 285 | STRUCT_LIT_FIELD => &SyntaxInfo { name: "STRUCT_LIT_FIELD" }, |
284 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 286 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
diff --git a/tests/data/parser/inline/0062_deref_expr.rs b/tests/data/parser/inline/0062_deref_expr.rs new file mode 100644 index 000000000..b1e35defc --- /dev/null +++ b/tests/data/parser/inline/0062_deref_expr.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | fn foo() { | ||
2 | **&1; | ||
3 | } | ||
diff --git a/tests/data/parser/inline/0062_deref_expr.txt b/tests/data/parser/inline/0062_deref_expr.txt new file mode 100644 index 000000000..62e8e6778 --- /dev/null +++ b/tests/data/parser/inline/0062_deref_expr.txt | |||
@@ -0,0 +1,26 @@ | |||
1 | FILE@[0; 23) | ||
2 | FN_ITEM@[0; 23) | ||
3 | FN_KW@[0; 2) | ||
4 | NAME@[2; 6) | ||
5 | WHITESPACE@[2; 3) | ||
6 | IDENT@[3; 6) "foo" | ||
7 | PARAM_LIST@[6; 9) | ||
8 | L_PAREN@[6; 7) | ||
9 | R_PAREN@[7; 8) | ||
10 | WHITESPACE@[8; 9) | ||
11 | BLOCK@[9; 23) | ||
12 | L_CURLY@[9; 10) | ||
13 | EXPR_STMT@[10; 21) | ||
14 | DEREF_EXPR@[10; 19) | ||
15 | WHITESPACE@[10; 15) | ||
16 | STAR@[15; 16) | ||
17 | DEREF_EXPR@[16; 19) | ||
18 | STAR@[16; 17) | ||
19 | REF_EXPR@[17; 19) | ||
20 | AMPERSAND@[17; 18) | ||
21 | LITERAL@[18; 19) | ||
22 | INT_NUMBER@[18; 19) | ||
23 | SEMI@[19; 20) | ||
24 | WHITESPACE@[20; 21) | ||
25 | R_CURLY@[21; 22) | ||
26 | WHITESPACE@[22; 23) | ||