From b82fe73d1ab9727ff650382d9c86a231b06245be Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jan 2019 11:02:30 +0300 Subject: make token set a const-fn --- crates/ra_syntax/src/grammar/expressions.rs | 6 ++-- crates/ra_syntax/src/grammar/expressions/atom.rs | 45 +++++++++++------------- crates/ra_syntax/src/grammar/params.rs | 3 +- crates/ra_syntax/src/grammar/patterns.rs | 10 +++--- crates/ra_syntax/src/grammar/types.rs | 11 +++--- 5 files changed, 33 insertions(+), 42 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index 2d1f17491..2236555e0 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs @@ -211,10 +211,8 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike { BlockLike::NotBlock } -const LHS_FIRST: TokenSet = token_set_union![ - token_set![AMP, STAR, EXCL, DOTDOT, DOTDOTEQ, MINUS], - atom::ATOM_EXPR_FIRST, -]; +const LHS_FIRST: TokenSet = + atom::ATOM_EXPR_FIRST.union(token_set![AMP, STAR, EXCL, DOTDOT, DOTDOTEQ, MINUS]); fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> { let m; diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index 31b09ac5b..167a76551 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs @@ -36,29 +36,26 @@ pub(crate) fn literal(p: &mut Parser) -> Option { } // E.g. for after the break in `if break {}`, this should not match -pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ - LITERAL_FIRST, - token_set![ - L_PAREN, - L_CURLY, - L_BRACK, - PIPE, - MOVE_KW, - IF_KW, - WHILE_KW, - MATCH_KW, - UNSAFE_KW, - RETURN_KW, - IDENT, - SELF_KW, - SUPER_KW, - CRATE_KW, - COLONCOLON, - BREAK_KW, - CONTINUE_KW, - LIFETIME - ], -]; +pub(super) const ATOM_EXPR_FIRST: TokenSet = LITERAL_FIRST.union(token_set![ + L_PAREN, + L_CURLY, + L_BRACK, + PIPE, + MOVE_KW, + IF_KW, + WHILE_KW, + MATCH_KW, + UNSAFE_KW, + RETURN_KW, + IDENT, + SELF_KW, + SUPER_KW, + CRATE_KW, + COLONCOLON, + BREAK_KW, + CONTINUE_KW, + LIFETIME, +]); const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; @@ -363,7 +360,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) { fn match_arm(p: &mut Parser) -> BlockLike { let m = p.start(); p.eat(PIPE); - patterns::pattern_r(p, TokenSet::EMPTY); + patterns::pattern_r(p, TokenSet::empty()); while p.eat(PIPE) { patterns::pattern(p); } diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/grammar/params.rs index b71a72ca3..658fc5820 100644 --- a/crates/ra_syntax/src/grammar/params.rs +++ b/crates/ra_syntax/src/grammar/params.rs @@ -61,8 +61,7 @@ fn list_(p: &mut Parser, flavor: Flavor) { m.complete(p, PARAM_LIST); } -const VALUE_PARAMETER_FIRST: TokenSet = - token_set_union![patterns::PATTERN_FIRST, types::TYPE_FIRST,]; +const VALUE_PARAMETER_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST); fn value_parameter(p: &mut Parser, flavor: Flavor) { let m = p.start(); diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 692ffbb8c..7820c4e02 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -1,10 +1,10 @@ use super::*; -pub(super) const PATTERN_FIRST: TokenSet = token_set_union![ - token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE], - expressions::LITERAL_FIRST, - paths::PATH_FIRST, -]; +pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST + .union(paths::PATH_FIRST) + .union(token_set![ + REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE + ]); pub(super) fn pattern(p: &mut Parser) { pattern_r(p, PAT_RECOVERY_SET) diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs index a933b986b..21d89d83b 100644 --- a/crates/ra_syntax/src/grammar/types.rs +++ b/crates/ra_syntax/src/grammar/types.rs @@ -1,12 +1,9 @@ use super::*; -pub(super) const TYPE_FIRST: TokenSet = token_set_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, - ], - paths::PATH_FIRST, -]; +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, +]); const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA]; -- cgit v1.2.3