aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-13 21:54:00 +0100
committerAleksey Kladov <[email protected]>2018-08-13 21:54:00 +0100
commit49ab44102496ac8c4a05b00c584adecf583f4d87 (patch)
tree853718de93f4c713a084fe728ee5035e57be2a40 /crates/libsyntax2/src/grammar
parentd9e86e574ad936f03a64c38dc7b7f39ddcc4eebd (diff)
Qualified paths
Diffstat (limited to 'crates/libsyntax2/src/grammar')
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs2
-rw-r--r--crates/libsyntax2/src/grammar/expressions/mod.rs2
-rw-r--r--crates/libsyntax2/src/grammar/paths.rs44
-rw-r--r--crates/libsyntax2/src/grammar/types.rs3
4 files changed, 32 insertions, 19 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs
index e62b16654..4f03862b1 100644
--- a/crates/libsyntax2/src/grammar/expressions/atom.rs
+++ b/crates/libsyntax2/src/grammar/expressions/atom.rs
@@ -38,7 +38,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
38 Some(m) => return Some(m), 38 Some(m) => return Some(m),
39 None => (), 39 None => (),
40 } 40 }
41 if paths::is_path_start(p) { 41 if paths::is_path_start(p) || p.at(L_ANGLE) {
42 return Some(path_expr(p, r)); 42 return Some(path_expr(p, r));
43 } 43 }
44 let la = p.nth(1); 44 let la = p.nth(1);
diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs
index 30a78d0c4..e56f3d30e 100644
--- a/crates/libsyntax2/src/grammar/expressions/mod.rs
+++ b/crates/libsyntax2/src/grammar/expressions/mod.rs
@@ -332,7 +332,7 @@ fn arg_list(p: &mut Parser) {
332// let _ = format!(); 332// let _ = format!();
333// } 333// }
334fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { 334fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
335 assert!(paths::is_path_start(p)); 335 assert!(paths::is_path_start(p) || p.at(L_ANGLE));
336 let m = p.start(); 336 let m = p.start();
337 paths::expr_path(p); 337 paths::expr_path(p);
338 match p.current() { 338 match p.current() {
diff --git a/crates/libsyntax2/src/grammar/paths.rs b/crates/libsyntax2/src/grammar/paths.rs
index aa5ecf4b8..97ab1880b 100644
--- a/crates/libsyntax2/src/grammar/paths.rs
+++ b/crates/libsyntax2/src/grammar/paths.rs
@@ -27,9 +27,6 @@ enum Mode {
27} 27}
28 28
29fn path(p: &mut Parser, mode: Mode) { 29fn path(p: &mut Parser, mode: Mode) {
30 if !is_path_start(p) {
31 return;
32 }
33 let path = p.start(); 30 let path = p.start();
34 path_segment(p, mode, true); 31 path_segment(p, mode, true);
35 let mut qual = path.complete(p, PATH); 32 let mut qual = path.complete(p, PATH);
@@ -51,21 +48,36 @@ fn path(p: &mut Parser, mode: Mode) {
51} 48}
52 49
53fn path_segment(p: &mut Parser, mode: Mode, first: bool) { 50fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
54 let segment = p.start(); 51 let m = p.start();
55 if first { 52 // test qual_paths
56 p.eat(COLONCOLON); 53 // type X = <A as B>::Output;
57 } 54 // fn foo() { <usize as Default>::default(); }
58 match p.current() { 55 if first && p.eat(L_ANGLE) {
59 IDENT => { 56 types::type_(p);
60 name_ref(p); 57 if p.eat(AS_KW) {
61 path_generic_args(p, mode); 58 if is_path_start(p) {
59 types::path_type(p);
60 } else {
61 p.error("expected a trait");
62 }
62 } 63 }
63 SELF_KW | SUPER_KW => p.bump(), 64 p.expect(R_ANGLE);
64 _ => { 65 } else {
65 p.err_and_bump("expected identifier"); 66 if first {
67 p.eat(COLONCOLON);
66 } 68 }
67 }; 69 match p.current() {
68 segment.complete(p, PATH_SEGMENT); 70 IDENT => {
71 name_ref(p);
72 path_generic_args(p, mode);
73 }
74 SELF_KW | SUPER_KW => p.bump(),
75 _ => {
76 p.err_and_bump("expected identifier");
77 }
78 };
79 }
80 m.complete(p, PATH_SEGMENT);
69} 81}
70 82
71fn path_generic_args(p: &mut Parser, mode: Mode) { 83fn path_generic_args(p: &mut Parser, mode: Mode) {
diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs
index 88631fefe..f58b545c7 100644
--- a/crates/libsyntax2/src/grammar/types.rs
+++ b/crates/libsyntax2/src/grammar/types.rs
@@ -12,6 +12,7 @@ pub(super) fn type_(p: &mut Parser) {
12 FOR_KW => for_type(p), 12 FOR_KW => for_type(p),
13 IMPL_KW => impl_trait_type(p), 13 IMPL_KW => impl_trait_type(p),
14 DYN_KW => dyn_trait_type(p), 14 DYN_KW => dyn_trait_type(p),
15 L_ANGLE => path_type(p),
15 _ if paths::is_path_start(p) => path_type(p), 16 _ if paths::is_path_start(p) => path_type(p),
16 _ => { 17 _ => {
17 p.err_and_bump("expected type"); 18 p.err_and_bump("expected type");
@@ -214,7 +215,7 @@ fn dyn_trait_type(p: &mut Parser) {
214// type C = self::Foo; 215// type C = self::Foo;
215// type D = super::Foo; 216// type D = super::Foo;
216pub(super) fn path_type(p: &mut Parser) { 217pub(super) fn path_type(p: &mut Parser) {
217 assert!(paths::is_path_start(p)); 218 assert!(paths::is_path_start(p) || p.at(L_ANGLE));
218 let m = p.start(); 219 let m = p.start();
219 paths::type_path(p); 220 paths::type_path(p);
220 // test path_type_with_bounds 221 // test path_type_with_bounds