From e618d129030b10ddd55d76c3e451799c7dba3f8d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 10 Jan 2021 16:40:52 +0100 Subject: Replace SyntaxKind usage with T! macro where applicable --- crates/parser/src/grammar/expressions/atom.rs | 12 ++++++++++-- crates/parser/src/grammar/items.rs | 26 +++++++++++++------------- crates/parser/src/grammar/items/traits.rs | 2 +- crates/parser/src/grammar/patterns.rs | 2 +- crates/parser/src/grammar/type_params.rs | 4 ++-- 5 files changed, 27 insertions(+), 19 deletions(-) (limited to 'crates/parser') diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index c7a3556a7..d61950b96 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -15,8 +15,16 @@ use super::*; // let _ = b"e"; // let _ = br"f"; // } -pub(crate) const LITERAL_FIRST: TokenSet = - TokenSet::new(&[TRUE_KW, FALSE_KW, INT_NUMBER, FLOAT_NUMBER, BYTE, CHAR, STRING, BYTE_STRING]); +pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[ + T![true], + T![false], + INT_NUMBER, + FLOAT_NUMBER, + BYTE, + CHAR, + STRING, + BYTE_STRING, +]); pub(crate) fn literal(p: &mut Parser) -> Option { if !p.at_ts(LITERAL_FIRST) { diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index cf4168d32..2070ce163 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -27,19 +27,19 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { } pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[ - FN_KW, - STRUCT_KW, - ENUM_KW, - IMPL_KW, - TRAIT_KW, - CONST_KW, - STATIC_KW, - LET_KW, - MOD_KW, - PUB_KW, - CRATE_KW, - USE_KW, - MACRO_KW, + T![fn], + T![struct], + T![enum], + T![impl], + T![trait], + T![const], + T![static], + T![let], + T![mod], + T![pub], + T![crate], + T![use], + T![macro], T![;], ]); diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index ab9a12b4d..d076974ed 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs @@ -110,7 +110,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { if !p.at(T![<]) { return false; } - if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == CONST_KW { + if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == T![const] { return true; } (p.nth(1) == LIFETIME_IDENT || p.nth(1) == IDENT) diff --git a/crates/parser/src/grammar/patterns.rs b/crates/parser/src/grammar/patterns.rs index b53d5749f..da71498a8 100644 --- a/crates/parser/src/grammar/patterns.rs +++ b/crates/parser/src/grammar/patterns.rs @@ -83,7 +83,7 @@ fn pattern_single_r(p: &mut Parser, recovery_set: TokenSet) { } const PAT_RECOVERY_SET: TokenSet = - TokenSet::new(&[LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW, R_PAREN, COMMA]); + TokenSet::new(&[T![let], T![if], T![while], T![loop], T![match], T![')'], T![,]]); fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { let m = match p.nth(0) { diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/type_params.rs index 4aeccd193..3de5248da 100644 --- a/crates/parser/src/grammar/type_params.rs +++ b/crates/parser/src/grammar/type_params.rs @@ -25,7 +25,7 @@ fn generic_param_list(p: &mut Parser) { match p.current() { LIFETIME_IDENT => lifetime_param(p, m), IDENT => type_param(p, m), - CONST_KW => const_param(p, m), + T![const] => const_param(p, m), _ => { m.abandon(p); p.err_and_bump("expected type parameter") @@ -66,7 +66,7 @@ fn type_param(p: &mut Parser, m: Marker) { // test const_param // struct S; fn const_param(p: &mut Parser, m: Marker) { - assert!(p.at(CONST_KW)); + assert!(p.at(T![const])); p.bump(T![const]); name(p); types::ascription(p); -- cgit v1.2.3