diff options
Diffstat (limited to 'crates/parser/src')
-rw-r--r-- | crates/parser/src/event.rs | 5 | ||||
-rw-r--r-- | crates/parser/src/grammar/items.rs | 28 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/consts.rs | 2 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/traits.rs | 4 |
4 files changed, 37 insertions, 2 deletions
diff --git a/crates/parser/src/event.rs b/crates/parser/src/event.rs index a7d06a815..903668892 100644 --- a/crates/parser/src/event.rs +++ b/crates/parser/src/event.rs | |||
@@ -38,14 +38,16 @@ pub(crate) enum Event { | |||
38 | /// | 38 | /// |
39 | /// The events for it would look like this: | 39 | /// The events for it would look like this: |
40 | /// | 40 | /// |
41 | /// | 41 | /// ```text |
42 | /// START(PATH) IDENT('foo') FINISH START(PATH) T![::] IDENT('bar') FINISH | 42 | /// START(PATH) IDENT('foo') FINISH START(PATH) T![::] IDENT('bar') FINISH |
43 | /// | /\ | 43 | /// | /\ |
44 | /// | | | 44 | /// | | |
45 | /// +------forward-parent------+ | 45 | /// +------forward-parent------+ |
46 | /// ``` | ||
46 | /// | 47 | /// |
47 | /// And the tree would look like this | 48 | /// And the tree would look like this |
48 | /// | 49 | /// |
50 | /// ```text | ||
49 | /// +--PATH---------+ | 51 | /// +--PATH---------+ |
50 | /// | | | | 52 | /// | | | |
51 | /// | | | | 53 | /// | | | |
@@ -54,6 +56,7 @@ pub(crate) enum Event { | |||
54 | /// PATH | 56 | /// PATH |
55 | /// | | 57 | /// | |
56 | /// 'foo' | 58 | /// 'foo' |
59 | /// ``` | ||
57 | /// | 60 | /// |
58 | /// See also `CompletedMarker::precede`. | 61 | /// See also `CompletedMarker::precede`. |
59 | Start { | 62 | Start { |
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 1d894e907..adec74ef3 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs | |||
@@ -83,6 +83,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { | |||
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | /// Try to parse an item, completing `m` in case of success. | ||
86 | pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { | 87 | pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { |
87 | // test_err pub_expr | 88 | // test_err pub_expr |
88 | // fn foo() { pub 92; } | 89 | // fn foo() { pub 92; } |
@@ -143,6 +144,33 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { | |||
143 | has_mods = true; | 144 | has_mods = true; |
144 | } | 145 | } |
145 | } | 146 | } |
147 | T![async] => { | ||
148 | // test default_async_fn | ||
149 | // impl T for Foo { | ||
150 | // default async fn foo() {} | ||
151 | // } | ||
152 | |||
153 | // test default_async_unsafe_fn | ||
154 | // impl T for Foo { | ||
155 | // default async unsafe fn foo() {} | ||
156 | // } | ||
157 | let mut maybe_fn = p.nth(2); | ||
158 | let is_unsafe = if matches!(maybe_fn, T![unsafe]) { | ||
159 | maybe_fn = p.nth(3); | ||
160 | true | ||
161 | } else { | ||
162 | false | ||
163 | }; | ||
164 | |||
165 | if matches!(maybe_fn, T![fn]) { | ||
166 | p.bump_remap(T![default]); | ||
167 | p.bump(T![async]); | ||
168 | if is_unsafe { | ||
169 | p.bump(T![unsafe]) | ||
170 | } | ||
171 | has_mods = true; | ||
172 | } | ||
173 | } | ||
146 | _ => (), | 174 | _ => (), |
147 | } | 175 | } |
148 | } | 176 | } |
diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs index eb7d1f828..12130df40 100644 --- a/crates/parser/src/grammar/items/consts.rs +++ b/crates/parser/src/grammar/items/consts.rs | |||
@@ -13,7 +13,7 @@ pub(super) fn konst(p: &mut Parser, m: Marker) { | |||
13 | fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { | 13 | fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { |
14 | assert!(p.at(kw)); | 14 | assert!(p.at(kw)); |
15 | p.bump(kw); | 15 | p.bump(kw); |
16 | p.eat(T![mut]); // FIXME: validator to forbid const mut | 16 | p.eat(T![mut]); |
17 | 17 | ||
18 | // Allow `_` in place of an identifier in a `const`. | 18 | // Allow `_` in place of an identifier in a `const`. |
19 | let is_const_underscore = kw == T![const] && p.eat(T![_]); | 19 | let is_const_underscore = kw == T![const] && p.eat(T![_]); |
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index d076974ed..d3327271c 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs | |||
@@ -40,6 +40,10 @@ pub(super) fn impl_(p: &mut Parser) { | |||
40 | type_params::opt_generic_param_list(p); | 40 | type_params::opt_generic_param_list(p); |
41 | } | 41 | } |
42 | 42 | ||
43 | // test impl_def_const | ||
44 | // impl const Send for X {} | ||
45 | p.eat(T![const]); | ||
46 | |||
43 | // FIXME: never type | 47 | // FIXME: never type |
44 | // impl ! {} | 48 | // impl ! {} |
45 | 49 | ||