aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/grammar
diff options
context:
space:
mode:
authorJosh Robson Chase <[email protected]>2019-01-23 17:15:47 +0000
committerJosh Robson Chase <[email protected]>2019-01-23 18:17:41 +0000
commit1cd6d6539a9d85bc44db364bb9165e6d9253790d (patch)
tree9700b48ecbf34496d45c5e08e27c113698fb1452 /crates/ra_syntax/src/grammar
parent0b942cbcb071811a811aa35feaa80950c2415075 (diff)
Add raw idents to lexer and parser
Diffstat (limited to 'crates/ra_syntax/src/grammar')
-rw-r--r--crates/ra_syntax/src/grammar/expressions.rs8
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs1
-rw-r--r--crates/ra_syntax/src/grammar/items.rs10
-rw-r--r--crates/ra_syntax/src/grammar/items/nominal.rs4
-rw-r--r--crates/ra_syntax/src/grammar/items/traits.rs2
-rw-r--r--crates/ra_syntax/src/grammar/params.rs6
-rw-r--r--crates/ra_syntax/src/grammar/paths.rs6
-rw-r--r--crates/ra_syntax/src/grammar/patterns.rs6
-rw-r--r--crates/ra_syntax/src/grammar/type_args.rs2
-rw-r--r--crates/ra_syntax/src/grammar/type_params.rs4
10 files changed, 25 insertions, 24 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs
index 2236555e0..107b7cda4 100644
--- a/crates/ra_syntax/src/grammar/expressions.rs
+++ b/crates/ra_syntax/src/grammar/expressions.rs
@@ -281,7 +281,7 @@ fn postfix_expr(
281 // } 281 // }
282 L_PAREN if allow_calls => call_expr(p, lhs), 282 L_PAREN if allow_calls => call_expr(p, lhs),
283 L_BRACK if allow_calls => index_expr(p, lhs), 283 L_BRACK if allow_calls => index_expr(p, lhs),
284 DOT if p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON) => { 284 DOT if p.nth(1).is_ident() && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON) => {
285 method_call_expr(p, lhs) 285 method_call_expr(p, lhs)
286 } 286 }
287 DOT => field_expr(p, lhs), 287 DOT => field_expr(p, lhs),
@@ -332,7 +332,7 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
332// y.bar::<T>(1, 2,); 332// y.bar::<T>(1, 2,);
333// } 333// }
334fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { 334fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
335 assert!(p.at(DOT) && p.nth(1) == IDENT && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON)); 335 assert!(p.at(DOT) && p.nth(1).is_ident() && (p.nth(2) == L_PAREN || p.nth(2) == COLONCOLON));
336 let m = lhs.precede(p); 336 let m = lhs.precede(p);
337 p.bump(); 337 p.bump();
338 name_ref(p); 338 name_ref(p);
@@ -352,7 +352,7 @@ fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
352 assert!(p.at(DOT)); 352 assert!(p.at(DOT));
353 let m = lhs.precede(p); 353 let m = lhs.precede(p);
354 p.bump(); 354 p.bump();
355 if p.at(IDENT) { 355 if p.current().is_ident() {
356 name_ref(p) 356 name_ref(p)
357 } else if p.at(INT_NUMBER) { 357 } else if p.at(INT_NUMBER) {
358 p.bump() 358 p.bump()
@@ -443,7 +443,7 @@ pub(crate) fn named_field_list(p: &mut Parser) {
443 p.bump(); 443 p.bump();
444 while !p.at(EOF) && !p.at(R_CURLY) { 444 while !p.at(EOF) && !p.at(R_CURLY) {
445 match p.current() { 445 match p.current() {
446 IDENT => { 446 IDENT | RAW_IDENT => {
447 let m = p.start(); 447 let m = p.start();
448 name_ref(p); 448 name_ref(p);
449 if p.eat(COLON) { 449 if p.eat(COLON) {
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs
index 167a76551..3fbe22856 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/grammar/expressions/atom.rs
@@ -48,6 +48,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = LITERAL_FIRST.union(token_set![
48 UNSAFE_KW, 48 UNSAFE_KW,
49 RETURN_KW, 49 RETURN_KW,
50 IDENT, 50 IDENT,
51 RAW_IDENT,
51 SELF_KW, 52 SELF_KW,
52 SUPER_KW, 53 SUPER_KW,
53 CRATE_KW, 54 CRATE_KW,
diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs
index 265e84570..c49798444 100644
--- a/crates/ra_syntax/src/grammar/items.rs
+++ b/crates/ra_syntax/src/grammar/items.rs
@@ -99,11 +99,11 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
99 has_mods = true; 99 has_mods = true;
100 abi(p); 100 abi(p);
101 } 101 }
102 if p.at(IDENT) && p.at_contextual_kw("auto") && p.nth(1) == TRAIT_KW { 102 if p.current().is_ident() && p.at_contextual_kw("auto") && p.nth(1) == TRAIT_KW {
103 p.bump_remap(AUTO_KW); 103 p.bump_remap(AUTO_KW);
104 has_mods = true; 104 has_mods = true;
105 } 105 }
106 if p.at(IDENT) && p.at_contextual_kw("default") && p.nth(1) == IMPL_KW { 106 if p.current().is_ident() && p.at_contextual_kw("default") && p.nth(1) == IMPL_KW {
107 p.bump_remap(DEFAULT_KW); 107 p.bump_remap(DEFAULT_KW);
108 has_mods = true; 108 has_mods = true;
109 } 109 }
@@ -202,7 +202,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
202 } 202 }
203 STRUCT_DEF 203 STRUCT_DEF
204 } 204 }
205 IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => { 205 IDENT | RAW_IDENT if p.at_contextual_kw("union") && p.nth(1).is_ident() => {
206 // test union_items 206 // test union_items
207 // union Foo {} 207 // union Foo {}
208 // union Foo { 208 // union Foo {
@@ -220,7 +220,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
220 use_item::use_item(p); 220 use_item::use_item(p);
221 USE_ITEM 221 USE_ITEM
222 } 222 }
223 CONST_KW if (la == IDENT || la == MUT_KW) => { 223 CONST_KW if (la.is_ident() || la == MUT_KW) => {
224 consts::const_def(p); 224 consts::const_def(p);
225 CONST_DEF 225 CONST_DEF
226 } 226 }
@@ -351,7 +351,7 @@ fn macro_call(p: &mut Parser) -> BlockLike {
351 351
352pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { 352pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
353 p.expect(EXCL); 353 p.expect(EXCL);
354 p.eat(IDENT); 354 p.eat_one(&[IDENT, RAW_IDENT]);
355 match p.current() { 355 match p.current() {
356 L_CURLY => { 356 L_CURLY => {
357 token_tree(p); 357 token_tree(p);
diff --git a/crates/ra_syntax/src/grammar/items/nominal.rs b/crates/ra_syntax/src/grammar/items/nominal.rs
index 0784fb7b1..897306883 100644
--- a/crates/ra_syntax/src/grammar/items/nominal.rs
+++ b/crates/ra_syntax/src/grammar/items/nominal.rs
@@ -70,7 +70,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) {
70 } 70 }
71 let var = p.start(); 71 let var = p.start();
72 attributes::outer_attributes(p); 72 attributes::outer_attributes(p);
73 if p.at(IDENT) { 73 if p.current().is_ident() {
74 name(p); 74 name(p);
75 match p.current() { 75 match p.current() {
76 L_CURLY => named_field_def_list(p), 76 L_CURLY => named_field_def_list(p),
@@ -120,7 +120,7 @@ pub(crate) fn named_field_def_list(p: &mut Parser) {
120 // } 120 // }
121 attributes::outer_attributes(p); 121 attributes::outer_attributes(p);
122 opt_visibility(p); 122 opt_visibility(p);
123 if p.at(IDENT) { 123 if p.current().is_ident() {
124 name(p); 124 name(p);
125 p.expect(COLON); 125 p.expect(COLON);
126 types::type_(p); 126 types::type_(p);
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs
index 0a0621753..a78bbba2b 100644
--- a/crates/ra_syntax/src/grammar/items/traits.rs
+++ b/crates/ra_syntax/src/grammar/items/traits.rs
@@ -112,7 +112,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
112 if p.nth(1) == POUND || p.nth(1) == R_ANGLE { 112 if p.nth(1) == POUND || p.nth(1) == R_ANGLE {
113 return true; 113 return true;
114 } 114 }
115 (p.nth(1) == LIFETIME || p.nth(1) == IDENT) 115 (p.nth(1) == LIFETIME || p.nth(1).is_ident())
116 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) 116 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ)
117} 117}
118 118
diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/grammar/params.rs
index 13158429a..ada07c17e 100644
--- a/crates/ra_syntax/src/grammar/params.rs
+++ b/crates/ra_syntax/src/grammar/params.rs
@@ -84,9 +84,9 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
84 // trait Foo { 84 // trait Foo {
85 // fn bar(_: u64); 85 // fn bar(_: u64);
86 // } 86 // }
87 if (la0 == IDENT || la0 == UNDERSCORE) && la1 == COLON 87 if (la0.is_ident() || la0 == UNDERSCORE) && la1 == COLON
88 || la0 == AMP && la1 == IDENT && la2 == COLON 88 || la0 == AMP && la1.is_ident() && la2 == COLON
89 || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON 89 || la0 == AMP && la1 == MUT_KW && la2.is_ident() && la3 == COLON
90 { 90 {
91 patterns::pattern(p); 91 patterns::pattern(p);
92 types::ascription(p); 92 types::ascription(p);
diff --git a/crates/ra_syntax/src/grammar/paths.rs b/crates/ra_syntax/src/grammar/paths.rs
index 33a11886c..0e1c1d334 100644
--- a/crates/ra_syntax/src/grammar/paths.rs
+++ b/crates/ra_syntax/src/grammar/paths.rs
@@ -1,11 +1,11 @@
1use super::*; 1use super::*;
2 2
3pub(super) const PATH_FIRST: TokenSet = 3pub(super) const PATH_FIRST: TokenSet =
4 token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE]; 4 token_set![IDENT, RAW_IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE];
5 5
6pub(super) fn is_path_start(p: &Parser) -> bool { 6pub(super) fn is_path_start(p: &Parser) -> bool {
7 match p.current() { 7 match p.current() {
8 IDENT | SELF_KW | SUPER_KW | CRATE_KW | COLONCOLON => true, 8 IDENT | RAW_IDENT | SELF_KW | SUPER_KW | CRATE_KW | COLONCOLON => true,
9 _ => false, 9 _ => false,
10 } 10 }
11} 11}
@@ -70,7 +70,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
70 p.eat(COLONCOLON); 70 p.eat(COLONCOLON);
71 } 71 }
72 match p.current() { 72 match p.current() {
73 IDENT => { 73 IDENT | RAW_IDENT => {
74 name_ref(p); 74 name_ref(p);
75 opt_path_type_args(p, mode); 75 opt_path_type_args(p, mode);
76 } 76 }
diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs
index 1ac5efdf6..925eabe1b 100644
--- a/crates/ra_syntax/src/grammar/patterns.rs
+++ b/crates/ra_syntax/src/grammar/patterns.rs
@@ -37,7 +37,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
37 let la1 = p.nth(1); 37 let la1 = p.nth(1);
38 if la0 == REF_KW 38 if la0 == REF_KW
39 || la0 == MUT_KW 39 || la0 == MUT_KW
40 || (la0 == IDENT && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY)) 40 || (la0.is_ident() && !(la1 == COLONCOLON || la1 == L_PAREN || la1 == L_CURLY))
41 { 41 {
42 return Some(bind_pat(p, true)); 42 return Some(bind_pat(p, true));
43 } 43 }
@@ -128,7 +128,7 @@ fn field_pat_list(p: &mut Parser) {
128 while !p.at(EOF) && !p.at(R_CURLY) { 128 while !p.at(EOF) && !p.at(R_CURLY) {
129 match p.current() { 129 match p.current() {
130 DOTDOT => p.bump(), 130 DOTDOT => p.bump(),
131 IDENT if p.nth(1) == COLON => field_pat(p), 131 IDENT | RAW_IDENT if p.nth(1) == COLON => field_pat(p),
132 L_CURLY => error_block(p, "expected ident"), 132 L_CURLY => error_block(p, "expected ident"),
133 _ => { 133 _ => {
134 bind_pat(p, false); 134 bind_pat(p, false);
@@ -143,7 +143,7 @@ fn field_pat_list(p: &mut Parser) {
143} 143}
144 144
145fn field_pat(p: &mut Parser) { 145fn field_pat(p: &mut Parser) {
146 assert!(p.at(IDENT)); 146 assert!(p.current().is_ident());
147 assert!(p.nth(1) == COLON); 147 assert!(p.nth(1) == COLON);
148 148
149 let m = p.start(); 149 let m = p.start();
diff --git a/crates/ra_syntax/src/grammar/type_args.rs b/crates/ra_syntax/src/grammar/type_args.rs
index f889419c5..469595d71 100644
--- a/crates/ra_syntax/src/grammar/type_args.rs
+++ b/crates/ra_syntax/src/grammar/type_args.rs
@@ -34,7 +34,7 @@ fn type_arg(p: &mut Parser) {
34 p.bump(); 34 p.bump();
35 m.complete(p, LIFETIME_ARG); 35 m.complete(p, LIFETIME_ARG);
36 } 36 }
37 IDENT if p.nth(1) == EQ => { 37 IDENT | RAW_IDENT if p.nth(1) == EQ => {
38 name_ref(p); 38 name_ref(p);
39 p.bump(); 39 p.bump();
40 types::type_(p); 40 types::type_(p);
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs
index 1ec813b3e..3cebd0675 100644
--- a/crates/ra_syntax/src/grammar/type_params.rs
+++ b/crates/ra_syntax/src/grammar/type_params.rs
@@ -15,7 +15,7 @@ fn type_param_list(p: &mut Parser) {
15 while !p.at(EOF) && !p.at(R_ANGLE) { 15 while !p.at(EOF) && !p.at(R_ANGLE) {
16 match p.current() { 16 match p.current() {
17 LIFETIME => lifetime_param(p), 17 LIFETIME => lifetime_param(p),
18 IDENT => type_param(p), 18 IDENT | RAW_IDENT => type_param(p),
19 _ => p.err_and_bump("expected type parameter"), 19 _ => p.err_and_bump("expected type parameter"),
20 } 20 }
21 if !p.at(R_ANGLE) && !p.expect(COMMA) { 21 if !p.at(R_ANGLE) && !p.expect(COMMA) {
@@ -37,7 +37,7 @@ fn lifetime_param(p: &mut Parser) {
37} 37}
38 38
39fn type_param(p: &mut Parser) { 39fn type_param(p: &mut Parser) {
40 assert!(p.at(IDENT)); 40 assert!(p.current().is_ident());
41 let m = p.start(); 41 let m = p.start();
42 name(p); 42 name(p);
43 if p.at(COLON) { 43 if p.at(COLON) {