From 76075c74103b3204ebc1bde54a330629d9e00811 Mon Sep 17 00:00:00 2001 From: pcpthm Date: Mon, 18 Mar 2019 14:34:08 +0900 Subject: Use Marker argument for item parsers - Fix pub_expr - Fix incorrect parsing of crate::path --- crates/ra_parser/src/grammar/items/consts.rs | 11 ++++++----- crates/ra_parser/src/grammar/items/nominal.rs | 11 ++++------- crates/ra_parser/src/grammar/items/use_item.rs | 3 ++- 3 files changed, 12 insertions(+), 13 deletions(-) (limited to 'crates/ra_parser/src/grammar/items') diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs index 5a5852f83..e6e6011c6 100644 --- a/crates/ra_parser/src/grammar/items/consts.rs +++ b/crates/ra_parser/src/grammar/items/consts.rs @@ -1,14 +1,14 @@ use super::*; -pub(super) fn static_def(p: &mut Parser) { - const_or_static(p, STATIC_KW) +pub(super) fn static_def(p: &mut Parser, m: Marker) { + const_or_static(p, m, STATIC_KW, STATIC_DEF) } -pub(super) fn const_def(p: &mut Parser) { - const_or_static(p, CONST_KW) +pub(super) fn const_def(p: &mut Parser, m: Marker) { + const_or_static(p, m, CONST_KW, CONST_DEF) } -fn const_or_static(p: &mut Parser, kw: SyntaxKind) { +fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { assert!(p.at(kw)); p.bump(); p.eat(MUT_KW); // TODO: validator to forbid const mut @@ -18,4 +18,5 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { expressions::expr(p); } p.expect(SEMI); + m.complete(p, def); } diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/nominal.rs index ff9b38f9c..a3579eebd 100644 --- a/crates/ra_parser/src/grammar/items/nominal.rs +++ b/crates/ra_parser/src/grammar/items/nominal.rs @@ -1,6 +1,6 @@ use super::*; -pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) { +pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { assert!(p.at(STRUCT_KW) || p.at_contextual_kw("union")); p.bump_remap(kind); @@ -12,19 +12,16 @@ pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) { match p.current() { SEMI => { p.bump(); - return; } L_CURLY => named_field_def_list(p), _ => { //TODO: special case `(` error message p.error("expected `;` or `{`"); - return; } } } SEMI if kind == STRUCT_KW => { p.bump(); - return; } L_CURLY => named_field_def_list(p), L_PAREN if kind == STRUCT_KW => { @@ -37,16 +34,15 @@ pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) { } _ if kind == STRUCT_KW => { p.error("expected `;`, `{`, or `(`"); - return; } _ => { p.error("expected `{`"); - return; } } + m.complete(p, STRUCT_DEF); } -pub(super) fn enum_def(p: &mut Parser) { +pub(super) fn enum_def(p: &mut Parser, m: Marker) { assert!(p.at(ENUM_KW)); p.bump(); name_r(p, ITEM_RECOVERY_SET); @@ -57,6 +53,7 @@ pub(super) fn enum_def(p: &mut Parser) { } else { p.error("expected `{`") } + m.complete(p, ENUM_DEF); } pub(crate) fn enum_variant_list(p: &mut Parser) { diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index b36612726..ea2f94604 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs @@ -1,10 +1,11 @@ use super::*; -pub(super) fn use_item(p: &mut Parser) { +pub(super) fn use_item(p: &mut Parser, m: Marker) { assert!(p.at(USE_KW)); p.bump(); use_tree(p); p.expect(SEMI); + m.complete(p, USE_ITEM); } /// Parse a use 'tree', such as `some::path` in `use some::path;` -- cgit v1.2.3