aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/expressions.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-04-18 20:49:56 +0100
committerEdwin Cheng <[email protected]>2019-04-18 20:49:56 +0100
commitc0f19d70056fada5f381019694d893e0ffe8360a (patch)
tree4837619368155d49c7540f035c6eb76d8d50ea6b /crates/ra_parser/src/grammar/expressions.rs
parent3ff5440a503f090032136c37c3d44375d6107db1 (diff)
Add expr, pat, ty and macro_stmts
Diffstat (limited to 'crates/ra_parser/src/grammar/expressions.rs')
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs44
1 files changed, 34 insertions, 10 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 06f2b45b1..8df9035e9 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -4,6 +4,12 @@ pub(crate) use self::atom::match_arm_list;
4pub(super) use self::atom::{literal, LITERAL_FIRST}; 4pub(super) use self::atom::{literal, LITERAL_FIRST};
5use super::*; 5use super::*;
6 6
7pub(super) enum StmtWithSemi {
8 Yes,
9 No,
10 Optional,
11}
12
7const EXPR_FIRST: TokenSet = LHS_FIRST; 13const EXPR_FIRST: TokenSet = LHS_FIRST;
8 14
9pub(super) fn expr(p: &mut Parser) -> BlockLike { 15pub(super) fn expr(p: &mut Parser) -> BlockLike {
@@ -48,7 +54,7 @@ fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool {
48 } 54 }
49} 55}
50 56
51pub(super) fn stmt(p: &mut Parser, with_semi: bool) { 57pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
52 // test block_items 58 // test block_items
53 // fn a() { fn b() {} } 59 // fn a() { fn b() {} }
54 let m = p.start(); 60 let m = p.start();
@@ -111,13 +117,23 @@ pub(super) fn stmt(p: &mut Parser, with_semi: bool) {
111 // } 117 // }
112 // test!{} 118 // test!{}
113 // } 119 // }
114 if with_semi { 120
115 if blocklike.is_block() { 121 match with_semi {
116 p.eat(SEMI); 122 StmtWithSemi::Yes => {
117 } else { 123 if blocklike.is_block() {
118 p.expect(SEMI); 124 p.eat(SEMI);
125 } else {
126 p.expect(SEMI);
127 }
128 }
129 StmtWithSemi::No => {}
130 StmtWithSemi::Optional => {
131 if p.at(SEMI) {
132 p.eat(SEMI);
133 }
119 } 134 }
120 } 135 }
136
121 m.complete(p, EXPR_STMT); 137 m.complete(p, EXPR_STMT);
122 } 138 }
123 139
@@ -128,7 +144,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: bool) {
128 // let c = 92; 144 // let c = 92;
129 // let d: i32 = 92; 145 // let d: i32 = 92;
130 // } 146 // }
131 fn let_stmt(p: &mut Parser, m: Marker, with_semi: bool) { 147 fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) {
132 assert!(p.at(LET_KW)); 148 assert!(p.at(LET_KW));
133 p.bump(); 149 p.bump();
134 patterns::pattern(p); 150 patterns::pattern(p);
@@ -139,8 +155,16 @@ pub(super) fn stmt(p: &mut Parser, with_semi: bool) {
139 expressions::expr(p); 155 expressions::expr(p);
140 } 156 }
141 157
142 if with_semi { 158 match with_semi {
143 p.expect(SEMI); 159 StmtWithSemi::Yes => {
160 p.expect(SEMI);
161 }
162 StmtWithSemi::No => {}
163 StmtWithSemi::Optional => {
164 if p.at(SEMI) {
165 p.eat(SEMI);
166 }
167 }
144 } 168 }
145 m.complete(p, LET_STMT); 169 m.complete(p, LET_STMT);
146 } 170 }
@@ -160,7 +184,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
160 continue; 184 continue;
161 } 185 }
162 186
163 stmt(p, true) 187 stmt(p, StmtWithSemi::Yes)
164 } 188 }
165} 189}
166 190