From 8d71a6bf0ca51ae099a5b470afdb957bca321441 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 11:49:13 +0200 Subject: Scale token generation back --- crates/ra_parser/src/syntax_kind/generated.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 004f4e564..1dd4ce34a 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -655,4 +655,10 @@ macro_rules! T { ( raw ) => { $crate::SyntaxKind::RAW_KW }; + ( lifetime ) => { + $crate::SyntaxKind::LIFETIME + }; + ( ident ) => { + $crate::SyntaxKind::IDENT + }; } -- cgit v1.2.3 From 5c5bde47fb759440d007c90fd83021de538120b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 17:06:57 +0200 Subject: Rename some tokens --- crates/ra_parser/src/grammar/expressions.rs | 3 +- crates/ra_parser/src/grammar/types.rs | 15 +- crates/ra_parser/src/syntax_kind/generated.rs | 334 ++------------------------ 3 files changed, 33 insertions(+), 319 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index c486c0211..a1bd53063 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -339,7 +339,8 @@ fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option Option<(CompletedMarker, BlockLike)> { let m; diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs index 386969d2d..fe1a039cb 100644 --- a/crates/ra_parser/src/grammar/types.rs +++ b/crates/ra_parser/src/grammar/types.rs @@ -3,8 +3,19 @@ use super::*; pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![ - L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW, IMPL_KW, - DYN_KW, L_ANGLE, + T!['('], + T!['['], + T![<], + T![!], + T![*], + T![&], + T![_], + T![fn], + T![unsafe], + T![extern], + T![for], + T![impl], + T![dyn], ]); const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA, L_DOLLAR]; diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 1dd4ce34a..524e7d784 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -9,7 +9,7 @@ pub enum SyntaxKind { TOMBSTONE, #[doc(hidden)] EOF, - SEMI, + SEMICOLON, COMMA, L_PAREN, R_PAREN, @@ -33,15 +33,15 @@ pub enum SyntaxKind { PERCENT, UNDERSCORE, DOT, - DOTDOT, - DOTDOTDOT, - DOTDOTEQ, + DOT2, + DOT3, + DOT2EQ, COLON, - COLONCOLON, + COLON2, EQ, - EQEQ, + EQ2, FAT_ARROW, - EXCL, + BANG, NEQ, MINUS, THIN_ARROW, @@ -55,8 +55,8 @@ pub enum SyntaxKind { SLASHEQ, STAREQ, PERCENTEQ, - AMPAMP, - PIPEPIPE, + AMP2, + PIPE2, SHL, SHR, SHLEQ, @@ -265,12 +265,12 @@ impl SyntaxKind { } pub fn is_punct(self) -> bool { match self { - SEMI | COMMA | L_PAREN | R_PAREN | L_CURLY | R_CURLY | L_BRACK | R_BRACK | L_ANGLE - | R_ANGLE | AT | POUND | TILDE | QUESTION | DOLLAR | AMP | PIPE | PLUS | STAR - | SLASH | CARET | PERCENT | UNDERSCORE | DOT | DOTDOT | DOTDOTDOT | DOTDOTEQ - | COLON | COLONCOLON | EQ | EQEQ | FAT_ARROW | EXCL | NEQ | MINUS | THIN_ARROW - | LTEQ | GTEQ | PLUSEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ | SLASHEQ | STAREQ - | PERCENTEQ | AMPAMP | PIPEPIPE | SHL | SHR | SHLEQ | SHREQ => true, + SEMICOLON | COMMA | L_PAREN | R_PAREN | L_CURLY | R_CURLY | L_BRACK | R_BRACK + | L_ANGLE | R_ANGLE | AT | POUND | TILDE | QUESTION | DOLLAR | AMP | PIPE | PLUS + | STAR | SLASH | CARET | PERCENT | UNDERSCORE | DOT | DOT2 | DOT3 | DOT2EQ | COLON + | COLON2 | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | THIN_ARROW | LTEQ | GTEQ + | PLUSEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ | SLASHEQ | STAREQ | PERCENTEQ | AMP2 + | PIPE2 | SHL | SHR | SHLEQ | SHREQ => true, _ => false, } } @@ -329,7 +329,7 @@ impl SyntaxKind { } pub fn from_char(c: char) -> Option { let tok = match c { - ';' => SEMI, + ';' => SEMICOLON, ',' => COMMA, '(' => L_PAREN, ')' => R_PAREN, @@ -355,7 +355,7 @@ impl SyntaxKind { '.' => DOT, ':' => COLON, '=' => EQ, - '!' => EXCL, + '!' => BANG, '-' => MINUS, _ => return None, }; @@ -363,302 +363,4 @@ impl SyntaxKind { } } #[macro_export] -macro_rules! T { - ( ; ) => { - $crate::SyntaxKind::SEMI - }; - ( , ) => { - $crate::SyntaxKind::COMMA - }; - ( '(' ) => { - $crate::SyntaxKind::L_PAREN - }; - ( ')' ) => { - $crate::SyntaxKind::R_PAREN - }; - ( '{' ) => { - $crate::SyntaxKind::L_CURLY - }; - ( '}' ) => { - $crate::SyntaxKind::R_CURLY - }; - ( '[' ) => { - $crate::SyntaxKind::L_BRACK - }; - ( ']' ) => { - $crate::SyntaxKind::R_BRACK - }; - ( < ) => { - $crate::SyntaxKind::L_ANGLE - }; - ( > ) => { - $crate::SyntaxKind::R_ANGLE - }; - ( @ ) => { - $crate::SyntaxKind::AT - }; - ( # ) => { - $crate::SyntaxKind::POUND - }; - ( ~ ) => { - $crate::SyntaxKind::TILDE - }; - ( ? ) => { - $crate::SyntaxKind::QUESTION - }; - ( $ ) => { - $crate::SyntaxKind::DOLLAR - }; - ( & ) => { - $crate::SyntaxKind::AMP - }; - ( | ) => { - $crate::SyntaxKind::PIPE - }; - ( + ) => { - $crate::SyntaxKind::PLUS - }; - ( * ) => { - $crate::SyntaxKind::STAR - }; - ( / ) => { - $crate::SyntaxKind::SLASH - }; - ( ^ ) => { - $crate::SyntaxKind::CARET - }; - ( % ) => { - $crate::SyntaxKind::PERCENT - }; - ( _ ) => { - $crate::SyntaxKind::UNDERSCORE - }; - ( . ) => { - $crate::SyntaxKind::DOT - }; - ( .. ) => { - $crate::SyntaxKind::DOTDOT - }; - ( ... ) => { - $crate::SyntaxKind::DOTDOTDOT - }; - ( ..= ) => { - $crate::SyntaxKind::DOTDOTEQ - }; - ( : ) => { - $crate::SyntaxKind::COLON - }; - ( :: ) => { - $crate::SyntaxKind::COLONCOLON - }; - ( = ) => { - $crate::SyntaxKind::EQ - }; - ( == ) => { - $crate::SyntaxKind::EQEQ - }; - ( => ) => { - $crate::SyntaxKind::FAT_ARROW - }; - ( ! ) => { - $crate::SyntaxKind::EXCL - }; - ( != ) => { - $crate::SyntaxKind::NEQ - }; - ( - ) => { - $crate::SyntaxKind::MINUS - }; - ( -> ) => { - $crate::SyntaxKind::THIN_ARROW - }; - ( <= ) => { - $crate::SyntaxKind::LTEQ - }; - ( >= ) => { - $crate::SyntaxKind::GTEQ - }; - ( += ) => { - $crate::SyntaxKind::PLUSEQ - }; - ( -= ) => { - $crate::SyntaxKind::MINUSEQ - }; - ( |= ) => { - $crate::SyntaxKind::PIPEEQ - }; - ( &= ) => { - $crate::SyntaxKind::AMPEQ - }; - ( ^= ) => { - $crate::SyntaxKind::CARETEQ - }; - ( /= ) => { - $crate::SyntaxKind::SLASHEQ - }; - ( *= ) => { - $crate::SyntaxKind::STAREQ - }; - ( %= ) => { - $crate::SyntaxKind::PERCENTEQ - }; - ( && ) => { - $crate::SyntaxKind::AMPAMP - }; - ( || ) => { - $crate::SyntaxKind::PIPEPIPE - }; - ( << ) => { - $crate::SyntaxKind::SHL - }; - ( >> ) => { - $crate::SyntaxKind::SHR - }; - ( <<= ) => { - $crate::SyntaxKind::SHLEQ - }; - ( >>= ) => { - $crate::SyntaxKind::SHREQ - }; - ( as ) => { - $crate::SyntaxKind::AS_KW - }; - ( async ) => { - $crate::SyntaxKind::ASYNC_KW - }; - ( await ) => { - $crate::SyntaxKind::AWAIT_KW - }; - ( box ) => { - $crate::SyntaxKind::BOX_KW - }; - ( break ) => { - $crate::SyntaxKind::BREAK_KW - }; - ( const ) => { - $crate::SyntaxKind::CONST_KW - }; - ( continue ) => { - $crate::SyntaxKind::CONTINUE_KW - }; - ( crate ) => { - $crate::SyntaxKind::CRATE_KW - }; - ( dyn ) => { - $crate::SyntaxKind::DYN_KW - }; - ( else ) => { - $crate::SyntaxKind::ELSE_KW - }; - ( enum ) => { - $crate::SyntaxKind::ENUM_KW - }; - ( extern ) => { - $crate::SyntaxKind::EXTERN_KW - }; - ( false ) => { - $crate::SyntaxKind::FALSE_KW - }; - ( fn ) => { - $crate::SyntaxKind::FN_KW - }; - ( for ) => { - $crate::SyntaxKind::FOR_KW - }; - ( if ) => { - $crate::SyntaxKind::IF_KW - }; - ( impl ) => { - $crate::SyntaxKind::IMPL_KW - }; - ( in ) => { - $crate::SyntaxKind::IN_KW - }; - ( let ) => { - $crate::SyntaxKind::LET_KW - }; - ( loop ) => { - $crate::SyntaxKind::LOOP_KW - }; - ( macro ) => { - $crate::SyntaxKind::MACRO_KW - }; - ( match ) => { - $crate::SyntaxKind::MATCH_KW - }; - ( mod ) => { - $crate::SyntaxKind::MOD_KW - }; - ( move ) => { - $crate::SyntaxKind::MOVE_KW - }; - ( mut ) => { - $crate::SyntaxKind::MUT_KW - }; - ( pub ) => { - $crate::SyntaxKind::PUB_KW - }; - ( ref ) => { - $crate::SyntaxKind::REF_KW - }; - ( return ) => { - $crate::SyntaxKind::RETURN_KW - }; - ( self ) => { - $crate::SyntaxKind::SELF_KW - }; - ( static ) => { - $crate::SyntaxKind::STATIC_KW - }; - ( struct ) => { - $crate::SyntaxKind::STRUCT_KW - }; - ( super ) => { - $crate::SyntaxKind::SUPER_KW - }; - ( trait ) => { - $crate::SyntaxKind::TRAIT_KW - }; - ( true ) => { - $crate::SyntaxKind::TRUE_KW - }; - ( try ) => { - $crate::SyntaxKind::TRY_KW - }; - ( type ) => { - $crate::SyntaxKind::TYPE_KW - }; - ( unsafe ) => { - $crate::SyntaxKind::UNSAFE_KW - }; - ( use ) => { - $crate::SyntaxKind::USE_KW - }; - ( where ) => { - $crate::SyntaxKind::WHERE_KW - }; - ( while ) => { - $crate::SyntaxKind::WHILE_KW - }; - ( auto ) => { - $crate::SyntaxKind::AUTO_KW - }; - ( default ) => { - $crate::SyntaxKind::DEFAULT_KW - }; - ( existential ) => { - $crate::SyntaxKind::EXISTENTIAL_KW - }; - ( union ) => { - $crate::SyntaxKind::UNION_KW - }; - ( raw ) => { - $crate::SyntaxKind::RAW_KW - }; - ( lifetime ) => { - $crate::SyntaxKind::LIFETIME - }; - ( ident ) => { - $crate::SyntaxKind::IDENT - }; -} +macro_rules ! T { [ ; ] => { $ crate :: SyntaxKind :: SEMICOLON } ; [ , ] => { $ crate :: SyntaxKind :: COMMA } ; [ '(' ] => { $ crate :: SyntaxKind :: L_PAREN } ; [ ')' ] => { $ crate :: SyntaxKind :: R_PAREN } ; [ '{' ] => { $ crate :: SyntaxKind :: L_CURLY } ; [ '}' ] => { $ crate :: SyntaxKind :: R_CURLY } ; [ '[' ] => { $ crate :: SyntaxKind :: L_BRACK } ; [ ']' ] => { $ crate :: SyntaxKind :: R_BRACK } ; [ < ] => { $ crate :: SyntaxKind :: L_ANGLE } ; [ > ] => { $ crate :: SyntaxKind :: R_ANGLE } ; [ @ ] => { $ crate :: SyntaxKind :: AT } ; [ # ] => { $ crate :: SyntaxKind :: POUND } ; [ ~ ] => { $ crate :: SyntaxKind :: TILDE } ; [ ? ] => { $ crate :: SyntaxKind :: QUESTION } ; [ $ ] => { $ crate :: SyntaxKind :: DOLLAR } ; [ & ] => { $ crate :: SyntaxKind :: AMP } ; [ | ] => { $ crate :: SyntaxKind :: PIPE } ; [ + ] => { $ crate :: SyntaxKind :: PLUS } ; [ * ] => { $ crate :: SyntaxKind :: STAR } ; [ / ] => { $ crate :: SyntaxKind :: SLASH } ; [ ^ ] => { $ crate :: SyntaxKind :: CARET } ; [ % ] => { $ crate :: SyntaxKind :: PERCENT } ; [ _ ] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [ . ] => { $ crate :: SyntaxKind :: DOT } ; [ .. ] => { $ crate :: SyntaxKind :: DOT2 } ; [ ... ] => { $ crate :: SyntaxKind :: DOT3 } ; [ ..= ] => { $ crate :: SyntaxKind :: DOT2EQ } ; [ : ] => { $ crate :: SyntaxKind :: COLON } ; [ :: ] => { $ crate :: SyntaxKind :: COLON2 } ; [ = ] => { $ crate :: SyntaxKind :: EQ } ; [ == ] => { $ crate :: SyntaxKind :: EQ2 } ; [ => ] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [ ! ] => { $ crate :: SyntaxKind :: BANG } ; [ != ] => { $ crate :: SyntaxKind :: NEQ } ; [ - ] => { $ crate :: SyntaxKind :: MINUS } ; [ -> ] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [ <= ] => { $ crate :: SyntaxKind :: LTEQ } ; [ >= ] => { $ crate :: SyntaxKind :: GTEQ } ; [ += ] => { $ crate :: SyntaxKind :: PLUSEQ } ; [ -= ] => { $ crate :: SyntaxKind :: MINUSEQ } ; [ |= ] => { $ crate :: SyntaxKind :: PIPEEQ } ; [ &= ] => { $ crate :: SyntaxKind :: AMPEQ } ; [ ^= ] => { $ crate :: SyntaxKind :: CARETEQ } ; [ /= ] => { $ crate :: SyntaxKind :: SLASHEQ } ; [ *= ] => { $ crate :: SyntaxKind :: STAREQ } ; [ %= ] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [ && ] => { $ crate :: SyntaxKind :: AMP2 } ; [ || ] => { $ crate :: SyntaxKind :: PIPE2 } ; [ << ] => { $ crate :: SyntaxKind :: SHL } ; [ >> ] => { $ crate :: SyntaxKind :: SHR } ; [ <<= ] => { $ crate :: SyntaxKind :: SHLEQ } ; [ >>= ] => { $ crate :: SyntaxKind :: SHREQ } ; [ as ] => { $ crate :: SyntaxKind :: AS_KW } ; [ async ] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [ await ] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [ box ] => { $ crate :: SyntaxKind :: BOX_KW } ; [ break ] => { $ crate :: SyntaxKind :: BREAK_KW } ; [ const ] => { $ crate :: SyntaxKind :: CONST_KW } ; [ continue ] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [ crate ] => { $ crate :: SyntaxKind :: CRATE_KW } ; [ dyn ] => { $ crate :: SyntaxKind :: DYN_KW } ; [ else ] => { $ crate :: SyntaxKind :: ELSE_KW } ; [ enum ] => { $ crate :: SyntaxKind :: ENUM_KW } ; [ extern ] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [ false ] => { $ crate :: SyntaxKind :: FALSE_KW } ; [ fn ] => { $ crate :: SyntaxKind :: FN_KW } ; [ for ] => { $ crate :: SyntaxKind :: FOR_KW } ; [ if ] => { $ crate :: SyntaxKind :: IF_KW } ; [ impl ] => { $ crate :: SyntaxKind :: IMPL_KW } ; [ in ] => { $ crate :: SyntaxKind :: IN_KW } ; [ let ] => { $ crate :: SyntaxKind :: LET_KW } ; [ loop ] => { $ crate :: SyntaxKind :: LOOP_KW } ; [ macro ] => { $ crate :: SyntaxKind :: MACRO_KW } ; [ match ] => { $ crate :: SyntaxKind :: MATCH_KW } ; [ mod ] => { $ crate :: SyntaxKind :: MOD_KW } ; [ move ] => { $ crate :: SyntaxKind :: MOVE_KW } ; [ mut ] => { $ crate :: SyntaxKind :: MUT_KW } ; [ pub ] => { $ crate :: SyntaxKind :: PUB_KW } ; [ ref ] => { $ crate :: SyntaxKind :: REF_KW } ; [ return ] => { $ crate :: SyntaxKind :: RETURN_KW } ; [ self ] => { $ crate :: SyntaxKind :: SELF_KW } ; [ static ] => { $ crate :: SyntaxKind :: STATIC_KW } ; [ struct ] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [ super ] => { $ crate :: SyntaxKind :: SUPER_KW } ; [ trait ] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [ true ] => { $ crate :: SyntaxKind :: TRUE_KW } ; [ try ] => { $ crate :: SyntaxKind :: TRY_KW } ; [ type ] => { $ crate :: SyntaxKind :: TYPE_KW } ; [ unsafe ] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [ use ] => { $ crate :: SyntaxKind :: USE_KW } ; [ where ] => { $ crate :: SyntaxKind :: WHERE_KW } ; [ while ] => { $ crate :: SyntaxKind :: WHILE_KW } ; [ auto ] => { $ crate :: SyntaxKind :: AUTO_KW } ; [ default ] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [ existential ] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [ union ] => { $ crate :: SyntaxKind :: UNION_KW } ; [ raw ] => { $ crate :: SyntaxKind :: RAW_KW } ; [ lifetime ] => { $ crate :: SyntaxKind :: LIFETIME } ; [ ident ] => { $ crate :: SyntaxKind :: IDENT } ; } -- cgit v1.2.3 From 7a39bc3ba29351feabcd4a16e12568a9e12818ca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 16:42:24 +0200 Subject: Make records grammar more orthogonal We used name [: expr] grammar before, now it is [name :] expr which makes things simpler --- crates/ra_parser/src/grammar/expressions.rs | 37 +++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index a1bd53063..cb30b25a8 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -619,26 +619,39 @@ pub(crate) fn record_field_list(p: &mut Parser) { let m = p.start(); p.bump(T!['{']); while !p.at(EOF) && !p.at(T!['}']) { + let m = p.start(); + // test record_literal_field_with_attr + // fn main() { + // S { #[cfg(test)] field: 1 } + // } + attributes::outer_attributes(p); + match p.current() { - // test record_literal_field_with_attr - // fn main() { - // S { #[cfg(test)] field: 1 } - // } - IDENT | INT_NUMBER | T![#] => { - let m = p.start(); - attributes::outer_attributes(p); - name_ref_or_index(p); - if p.eat(T![:]) { - expr(p); + IDENT | INT_NUMBER => { + // test_err record_literal_before_ellipsis_recovery + // fn main() { + // S { field ..S::default() } + // } + if p.nth_at(1, T![:]) || p.nth_at(1, T![..]) { + name_ref_or_index(p); + p.expect(T![:]); } + expr(p); m.complete(p, RECORD_FIELD); } T![.] if p.at(T![..]) => { + m.abandon(p); p.bump(T![..]); expr(p); } - T!['{'] => error_block(p, "expected a field"), - _ => p.err_and_bump("expected identifier"), + T!['{'] => { + error_block(p, "expected a field"); + m.abandon(p); + } + _ => { + p.err_and_bump("expected identifier"); + m.abandon(p); + } } if !p.at(T!['}']) { p.expect(T![,]); -- cgit v1.2.3