diff --git a/.cargo/config.toml b/.cargo/config.toml index 5b27f3b6ab..70299ad43b 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -6,4 +6,84 @@ incremental = true lto = true [build] -rustflags = ["--warn", "unused_crate_dependencies"] +rustflags = [ + "--warn", + "unused_crate_dependencies", + # This is a list of allowed Clippy rules for the purposes of gradual migration. + # See https://github.com/NomicFoundation/slang/pull/626 + "-A", + "clippy::bool_assert_comparison", + "-A", + "clippy::borrow_interior_mutable_const", + "-A", + "clippy::cmp_owned", + "-A", + "clippy::collapsible_if", + "-A", + "clippy::comparison_chain", + "-A", + "clippy::declare_interior_mutable_const", + "-A", + "clippy::enum_variant_names", + "-A", + "clippy::expect_fun_call", + "-A", + "clippy::explicit_auto_deref", + "-A", + "clippy::from_over_into", + "-A", + "clippy::inherent_to_string", + "-A", + "clippy::into_iter_on_ref", + "-A", + "clippy::len_without_is_empty", + "-A", + "clippy::len_zero", + "-A", + "clippy::manual_range_contains", + "-A", + "clippy::match_like_matches_macro", + "-A", + "clippy::needless_borrow", + "-A", + "clippy::needless_range_loop", + "-A", + "clippy::needless_return", + "-A", + "clippy::new_without_default", + "-A", + "clippy::println_empty_string", + "-A", + "clippy::ptr_arg", + "-A", + "clippy::redundant_closure", + "-A", + "clippy::redundant_pattern", + "-A", + "clippy::redundant_pattern_matching", + "-A", + "clippy::redundant_static_lifetimes", + "-A", + "clippy::should_implement_trait", + "-A", + "clippy::single_char_add_str", + "-A", + "clippy::single_char_pattern", + "-A", + "clippy::to_string_in_format_args", + "-A", + "clippy::upper_case_acronyms", + "-A", + "clippy::useless_asref", + "-A", + "clippy::useless_conversion", + "-A", + "clippy::useless_format", + "-A", + "clippy::write_literal", + "-A", + "clippy::writeln_empty_string", + "-A", + "clippy::wrong_self_convention", + +] diff --git a/.vscode/settings.json b/.vscode/settings.json index 62c552abe6..6fbeec0de3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,7 +7,9 @@ "**/generated/**": true }, "rust-analyzer.check.allTargets": true, + "rust-analyzer.check.command": "clippy", "rust-analyzer.check.features": "all", + "rust-analyzer.checkOnSave": true, "rust-analyzer.server.path": "${workspaceFolder}/bin/rust-analyzer", "search.exclude": { // Packages and Dependencies diff --git a/crates/codegen/parser/generator/src/parser_definition.rs b/crates/codegen/parser/generator/src/parser_definition.rs index 976e139b87..52d32382b5 100644 --- a/crates/codegen/parser/generator/src/parser_definition.rs +++ b/crates/codegen/parser/generator/src/parser_definition.rs @@ -33,6 +33,9 @@ pub trait ParserDefinitionNodeExtensions { impl ParserDefinitionNodeExtensions for ParserDefinitionNode { fn to_parser_code(&self, context_name: &'static str, is_trivia: bool) -> TokenStream { + let context = format_ident!("{context_name}"); + let lex_ctx = quote! { LexicalContextType::#context }; + match self { Self::Versioned(body, _, _) => body.to_parser_code(context_name, is_trivia), @@ -102,42 +105,37 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { Self::ScannerDefinition(scanner_definition, _) => { let kind = format_ident!("{name}", name = scanner_definition.name()); - if is_trivia { - let function_name = - format_ident!("{}_parse_token", context_name.to_snake_case()); - quote! { - self.#function_name(input, TokenKind::#kind) - } + + let parse_token = if is_trivia { + format_ident!("parse_token") } else { - let function_name = - format_ident!("{}_parse_token_with_trivia", context_name.to_snake_case()); - quote! { - self.#function_name(input, TokenKind::#kind) - } + format_ident!("parse_token_with_trivia") + }; + + quote! { + self.#parse_token::<#lex_ctx>(input, TokenKind::#kind) } } Self::TriviaParserDefinition(trivia_parser_definition, _) => { - let function_name = format_ident!( - "{snake_case}", - snake_case = trivia_parser_definition.name().to_snake_case() - ); + let function_name = + format_ident!("{}", trivia_parser_definition.name().to_snake_case()); + quote! { self.#function_name(input) } } Self::ParserDefinition(parser_definition, _) => { - if is_trivia { - unreachable!( - "Trivia productions can only reference trivia or token productions" - ) - } + assert!( + !is_trivia, + "Trivia productions can only reference trivia or token productions" + ); + if parser_definition.is_inline() { parser_definition.to_parser_code() } else { - let function_name = format_ident!( - "{snake_case}", - snake_case = parser_definition.name().to_snake_case() - ); + let function_name = + format_ident!("{}", parser_definition.name().to_snake_case()); + quote! { self.#function_name(input) } @@ -145,20 +143,19 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { } Self::PrecedenceParserDefinition(precedence_parser_definition, _) => { - if is_trivia { - unreachable!( - "Trivia productions can only reference trivia or token productions" - ) - } - let function_name = format_ident!( - "{snake_case}", - snake_case = precedence_parser_definition.name().to_snake_case() + assert!( + !is_trivia, + "Trivia productions can only reference trivia or token productions" ); + + let function_name = + format_ident!("{}", precedence_parser_definition.name().to_snake_case()); + quote! { self.#function_name(input) } } Self::DelimitedBy(open, body, close, _) => { - let [open_token, close_token] = match (open.as_ref(), close.as_ref()) { + let [open_delim, close_delim] = match (open.as_ref(), close.as_ref()) { ( ParserDefinitionNode::ScannerDefinition(open, ..), ParserDefinitionNode::ScannerDefinition(close, ..), @@ -166,27 +163,13 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { _ => unreachable!("Only tokens are permitted as delimiters"), }; - let parse_token = format_ident!( - "{context_name}_parse_token_with_trivia", - context_name = context_name.to_snake_case() - ); - - let delimiters = format_ident!( - "{context_name}_delimiters", - context_name = context_name.to_snake_case() - ); - - let context = format_ident!("{context_name}"); - let parser = body.to_parser_code(context_name, is_trivia); let body_parser = body.applicable_version_quality_ranges().wrap_code( quote! { seq.elem(#parser - .recover_until_with_nested_delims(input, - |input| Lexer::next_token::<{ LexicalContext::#context as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::#close_token, - Self::#delimiters(), + .recover_until_with_nested_delims::<_, #lex_ctx>(input, + self, + TokenKind::#close_delim, RecoverFromNoMatch::Yes, ) )?; @@ -196,67 +179,51 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { quote! { SequenceHelper::run(|mut seq| { - let mut delim_guard = input.open_delim(TokenKind::#close_token); + let mut delim_guard = input.open_delim(TokenKind::#close_delim); let input = delim_guard.ctx(); - seq.elem(self.#parse_token(input, TokenKind::#open_token))?; + seq.elem(self.parse_token_with_trivia::<#lex_ctx>(input, TokenKind::#open_delim))?; #body_parser - seq.elem(self.#parse_token(input, TokenKind::#close_token))?; + seq.elem(self.parse_token_with_trivia::<#lex_ctx>(input, TokenKind::#close_delim))?; seq.finish() }) } } Self::SeparatedBy(body, separator, _) => { - let separator_scanner = match separator.as_ref() { - ParserDefinitionNode::ScannerDefinition(scanner, ..) => scanner, + let separator = match separator.as_ref() { + ParserDefinitionNode::ScannerDefinition(scanner, ..) => { + format_ident!("{name}", name = scanner.name()) + } _ => unreachable!("Only tokens are permitted as separators"), }; - let separator_token_kind = format_ident!("{name}", name = separator_scanner.name()); - let context = format_ident!("{context_name}"); - let parser = body.to_parser_code(context_name, is_trivia); quote! { - SeparatedHelper::run::<{ LexicalContext::#context as u8}, Self>( + SeparatedHelper::run::<_, #lex_ctx>( input, - |input| #parser, - TokenKind::#separator_token_kind, self, + |input| #parser, + TokenKind::#separator, ) } } Self::TerminatedBy(body, terminator, _) => { - let terminator_scanner = match terminator.as_ref() { - ParserDefinitionNode::ScannerDefinition(scanner, ..) => scanner, + let terminator = match terminator.as_ref() { + ParserDefinitionNode::ScannerDefinition(scanner, ..) => { + format_ident!("{name}", name = scanner.name()) + } _ => unreachable!("Only tokens are permitted as terminators"), }; - let terminator_token_kind = - format_ident!("{name}", name = terminator_scanner.name()); - - let context = format_ident!("{context_name}"); - - let delimiters = format_ident!( - "{context_name}_delimiters", - context_name = context_name.to_snake_case() - ); - - let parse_token = format_ident!( - "{context_name}_parse_token_with_trivia", - context_name = context_name.to_snake_case() - ); - let parser = body.to_parser_code(context_name, is_trivia); let body_parser = body.applicable_version_quality_ranges().wrap_code( quote! { seq.elem(#parser - .recover_until_with_nested_delims(input, - |input| Lexer::next_token::<{ LexicalContext::#context as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::#terminator_token_kind, - Self::#delimiters(), + .recover_until_with_nested_delims::<_, #lex_ctx>(input, + self, + TokenKind::#terminator, RecoverFromNoMatch::No, ) )?; @@ -267,7 +234,7 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode { quote! { SequenceHelper::run(|mut seq| { #body_parser - seq.elem(self.#parse_token(input, TokenKind::#terminator_token_kind))?; + seq.elem(self.parse_token_with_trivia::<#lex_ctx>(input, TokenKind::#terminator))?; seq.finish() }) } diff --git a/crates/codegen/parser/runtime/src/kinds.rs b/crates/codegen/parser/runtime/src/kinds.rs index c040d46628..8991df4e30 100644 --- a/crates/codegen/parser/runtime/src/kinds.rs +++ b/crates/codegen/parser/runtime/src/kinds.rs @@ -63,7 +63,15 @@ pub enum ProductionKind { #[derive(strum_macros::FromRepr)] #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "language"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -#[repr(u8)] // This is used as a const fn argument, which only supports primitive types pub enum LexicalContext { XXX, } + +/// Marker trait for type-level [`LexicalContext`] variants. +pub trait IsLexicalContext { + /// Returns a run-time [`LexicalContext`] value. + fn value() -> LexicalContext; +} + +#[allow(non_snake_case)] +pub mod LexicalContextType {} diff --git a/crates/codegen/parser/runtime/src/lexer.rs b/crates/codegen/parser/runtime/src/lexer.rs index 3f75eedd27..38cbd7fd55 100644 --- a/crates/codegen/parser/runtime/src/lexer.rs +++ b/crates/codegen/parser/runtime/src/lexer.rs @@ -1,41 +1,52 @@ use crate::{ cst, - kinds::{LexicalContext, TokenKind}, + kinds::{IsLexicalContext, TokenKind}, support::{ParserContext, ParserResult}, }; -// Ensure that the `LexicalContext` enum is `repr(u8)`. -// Workaround until repr(u8) enums can be used as const params. -const _ASSERT_CONTEXT_IS_REPR_U8: fn() = || { - let _ = core::mem::transmute::; -}; - pub trait Lexer { // Generated by the templating engine #[doc(hidden)] - fn next_token(&self, input: &mut ParserContext) -> Option; + fn next_token(&self, input: &mut ParserContext) -> Option; // NOTE: These are context-insensitive #[doc(hidden)] fn leading_trivia(&self, input: &mut ParserContext) -> ParserResult; #[doc(hidden)] fn trailing_trivia(&self, input: &mut ParserContext) -> ParserResult; #[doc(hidden)] - fn delimiters() -> &'static [(TokenKind, TokenKind)]; + /// Returns valid grouping delimiters in the given lexical context. + fn delimiters() -> &'static [(TokenKind, TokenKind)]; - fn peek_token(&self, input: &mut ParserContext) -> Option { + /// Peeks the next token, including trivia. Does not advance the input. + fn peek_token(&self, input: &mut ParserContext) -> Option { let start = input.position(); - let token = self.next_token::(input); + let token = self.next_token::(input); + input.set_position(start); + token + } + + /// Peeks the next significant (i.e. non-trivia) token. Does not advance the input. + fn peek_token_with_trivia( + &self, + input: &mut ParserContext, + ) -> Option { + let start = input.position(); + + let _ = self.leading_trivia(input); + let token = self.next_token::(input); + input.set_position(start); token } - fn parse_token( + /// Attempts to consume the next expected token. Advances the input only if the token matches. + fn parse_token( &self, input: &mut ParserContext, kind: TokenKind, ) -> ParserResult { let start = input.position(); - if self.next_token::(input) != Some(kind) { + if self.next_token::(input) != Some(kind) { input.set_position(start); return ParserResult::no_match(vec![kind]); } @@ -47,7 +58,9 @@ pub trait Lexer { ) } - fn parse_token_with_trivia( + /// Attempts to consume the next significant token including both leading and trailing trivia. + /// Advances the input only if the token matches. + fn parse_token_with_trivia( &self, input: &mut ParserContext, kind: TokenKind, @@ -62,7 +75,7 @@ pub trait Lexer { } let start = input.position(); - if self.next_token::(input) != Some(kind) { + if self.next_token::(input) != Some(kind) { input.set_position(restore); return ParserResult::no_match(vec![kind]); } diff --git a/crates/codegen/parser/runtime/src/support/recovery.rs b/crates/codegen/parser/runtime/src/support/recovery.rs index dfa3f66bb3..b39bf10716 100644 --- a/crates/codegen/parser/runtime/src/support/recovery.rs +++ b/crates/codegen/parser/runtime/src/support/recovery.rs @@ -1,5 +1,6 @@ use crate::cst; -use crate::kinds::TokenKind; +use crate::kinds::{IsLexicalContext, TokenKind}; +use crate::lexer::Lexer; use crate::parse_error::ParseError; use crate::support::ParserResult; use crate::text_index::{TextRange, TextRangeExtensions as _}; @@ -39,27 +40,15 @@ impl ParserResult { /// /// Respects nested delimiters, i.e. the `expected` token is only accepted if it's not nested inside. /// Does not consume the `expected` token. - pub fn recover_until_with_nested_delims( + pub fn recover_until_with_nested_delims( self, input: &mut ParserContext, - next_token: impl Fn(&mut ParserContext) -> Option, - leading_trivia: impl Fn(&mut ParserContext) -> ParserResult, + lexer: &L, expected: TokenKind, - delims: &[(TokenKind, TokenKind)], recover_from_no_match: RecoverFromNoMatch, ) -> ParserResult { let before_recovery = input.position(); - let mut peek_token_after_trivia = || { - let start = input.position(); - - opt_parse(input, &leading_trivia); - let token = next_token(input); - - input.set_position(start); - token - }; - enum ParseResultKind { Match, Incomplete, @@ -72,7 +61,9 @@ impl ParserResult { result.expected_tokens, ParseResultKind::Incomplete, ), - ParserResult::Match(result) if peek_token_after_trivia() != Some(expected) => { + ParserResult::Match(result) + if lexer.peek_token_with_trivia::(input) != Some(expected) => + { (result.nodes, result.expected_tokens, ParseResultKind::Match) } ParserResult::NoMatch(result) if recover_from_no_match.as_bool() => { @@ -82,9 +73,9 @@ impl ParserResult { _ => return self, }; - let leading_trivia = opt_parse(input, &leading_trivia); + let leading_trivia = opt_parse(input, |input| lexer.leading_trivia(input)); - match skip_until_with_nested_delims(input, next_token, expected, delims) { + match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, expected) { Some((found, skipped_range)) => { nodes.extend(leading_trivia); if matches!(result_kind, ParseResultKind::Match) { @@ -98,24 +89,24 @@ impl ParserResult { tokens_that_would_have_allowed_more_progress: expected_tokens.clone(), }); - return ParserResult::SkippedUntil(SkippedUntil { + ParserResult::SkippedUntil(SkippedUntil { nodes, expected, skipped, found, - }); + }) } // Not found till EOF, revert any recovery attempt None => { input.set_position(before_recovery); - return match result_kind { + match result_kind { ParseResultKind::Match => ParserResult::r#match(nodes, expected_tokens), ParseResultKind::Incomplete => { ParserResult::incomplete_match(nodes, expected_tokens) } ParseResultKind::NoMatch => ParserResult::no_match(expected_tokens), - }; + } } } } @@ -126,18 +117,19 @@ impl ParserResult { /// Does not consume the `expected` token. /// /// Returns the found token and the range of skipped tokens on success. -pub fn skip_until_with_nested_delims( +pub fn skip_until_with_nested_delims( input: &mut ParserContext, - next_token: impl Fn(&mut ParserContext) -> Option, + lexer: &L, until: TokenKind, - delims: &[(TokenKind, TokenKind)], ) -> Option<(TokenKind, TextRange)> { + let delims = L::delimiters::(); + let start = input.position(); let mut local_delims = vec![]; loop { let save = input.position(); - match next_token(input) { + match lexer.next_token::(input) { // If we're not skipping past a local delimited group (delimiter stack is empty), // we can unwind on a token that's expected by us or by our ancestor. Some(token) diff --git a/crates/codegen/parser/runtime/src/support/separated_helper.rs b/crates/codegen/parser/runtime/src/support/separated_helper.rs index 47acc2281e..117067ef1d 100644 --- a/crates/codegen/parser/runtime/src/support/separated_helper.rs +++ b/crates/codegen/parser/runtime/src/support/separated_helper.rs @@ -1,19 +1,24 @@ use crate::{ - cst, kinds::TokenKind, lexer::Lexer, parse_error::ParseError, text_index::TextRangeExtensions, -}; - -use super::{ - parser_result::IncompleteMatch, skip_until_with_nested_delims, ParserContext, ParserResult, + cst, + kinds::{IsLexicalContext, TokenKind}, + lexer::Lexer, + parse_error::ParseError, + support::{ + parser_result::{ParserResult, SkippedUntil}, + recovery::skip_until_with_nested_delims, + ParserContext, + }, + text_index::TextRangeExtensions, }; pub struct SeparatedHelper; impl SeparatedHelper { - pub fn run( + pub fn run( input: &mut ParserContext, + lexer: &L, body_parser: impl Fn(&mut ParserContext) -> ParserResult, separator: TokenKind, - lexer: &L, ) -> ParserResult { let mut accum = vec![]; loop { @@ -21,16 +26,9 @@ impl SeparatedHelper { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); - // Parse the leading trivia so that we can peek the next significant token - if let ParserResult::Match(r#match) = lexer.leading_trivia(input) { - accum.extend(r#match.nodes); - } - - match lexer.peek_token::(input) { + match lexer.peek_token_with_trivia::(input) { Some(token) if token == separator => { - let separator = - lexer.parse_token_with_trivia::(input, separator); - match separator { + match lexer.parse_token_with_trivia::(input, separator) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); continue; @@ -38,21 +36,12 @@ impl SeparatedHelper { _ => unreachable!("We just checked that the separator matches"), } } - // Heuristic: lists (separated-by) are often in a delimited group, so if we - // see a closing delimiter, we assume that we're done and don't recover. - Some(token) if input.closing_delimiters().contains(&token) => { - return ParserResult::r#match(accum, vec![separator]); - } - // Otherwise, we try to recover from unexpected tokens until we see a separator - Some(..) => { - // TODO: Attempt recovery: sometimes the list is not in a delimited group, - // so don't attempt to recover for now to not risk misparses - return ParserResult::r#match(accum, vec![separator]); - } - // EOF - None => { - return ParserResult::r#match(accum, vec![separator]); - } + + // Unrecognized, return the accumulated matches. + // NOTE: We can't correctly attempt recovery until #600 lands, otherwise we'd risk misparses, + // as we need to stop at certain synchronizing tokens (and we can't reliably scan until + // a delimiter, as not every list is enclosed in a delimited group). + Some(..) | None => return ParserResult::r#match(accum, vec![separator]), } } // Body was partially parsed, so try to recover by skipping tokens until we see a separator @@ -61,14 +50,7 @@ impl SeparatedHelper { let start = input.position(); - let skipped = skip_until_with_nested_delims( - input, - |input| lexer.next_token::(input), - separator, - ::delimiters::(), - ); - - match skipped { + match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, separator) { // A separator was found, so we can recover the incomplete match Some((found, skipped_range)) if found == separator => { accum.push(cst::Node::token( @@ -81,7 +63,7 @@ impl SeparatedHelper { .expected_tokens, }); - match lexer.parse_token_with_trivia::(input, separator) { + match lexer.parse_token_with_trivia::(input, separator) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); continue; @@ -89,23 +71,17 @@ impl SeparatedHelper { _ => unreachable!("We just checked that the separator matches"), } } + // Didn't find a separator during recovery. It might've been the last of the // separatees, so we can't recover to not risk misparses. - Some(..) => { + Some(..) | None => { // Undo the recovery attempt input.set_position(start); - return ParserResult::IncompleteMatch(IncompleteMatch { - nodes: accum, - expected_tokens: incomplete.expected_tokens, - }); - } - // Separator wasn't found till EOF, so we can't recover - None => { - return ParserResult::IncompleteMatch(IncompleteMatch { - nodes: accum, - expected_tokens: incomplete.expected_tokens, - }); + return ParserResult::incomplete_match( + accum, + incomplete.expected_tokens, + ); } } } @@ -119,7 +95,8 @@ impl SeparatedHelper { ParserResult::SkippedUntil(skipped) => { accum.extend(skipped.nodes); - return ParserResult::SkippedUntil(super::parser_result::SkippedUntil { + + return ParserResult::SkippedUntil(SkippedUntil { nodes: accum, ..skipped }); diff --git a/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 b/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 index 888de7dcaf..3363b5326f 100644 --- a/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/templates/kinds.rs.jinja2 @@ -77,9 +77,28 @@ pub enum TokenKind { /// The lexical context of the scanner. #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "language"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -#[repr(u8)] // This is used as a const argument, which only supports primitive types pub enum LexicalContext { {%- for context in code.scanner_contexts %} {{ context.name }}, {%- endfor %} } + +/// Marker trait for type-level [`LexicalContext`] variants. +pub trait IsLexicalContext { + /// Returns a run-time [`LexicalContext`] value. + fn value() -> LexicalContext; +} + +#[allow(non_snake_case)] +pub mod LexicalContextType { + use super::*; + + {%- for context in code.scanner_contexts %} + pub struct {{ context.name }} {} + impl IsLexicalContext for {{ context.name }} { + fn value() -> LexicalContext { + LexicalContext::{{ context.name }} + } + } + {%- endfor %} +} diff --git a/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 b/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 index 7903a5f09e..e071b6370d 100644 --- a/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/templates/language.rs.jinja2 @@ -4,7 +4,7 @@ use {napi::bindgen_prelude::*, napi_derive::napi}; use semver::Version; use super::{ - kinds::{RuleKind, TokenKind, ProductionKind}, + kinds::{RuleKind, TokenKind, ProductionKind, IsLexicalContext, LexicalContextType}, lexer::Lexer, parse_output::ParseOutput, support::*, @@ -65,33 +65,6 @@ impl Language { &self.version } - {% for context in code.scanner_contexts %} - #[allow(dead_code)] - fn {{ context.name | snake_case }}_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult - { - Lexer::parse_token_with_trivia::<{ LexicalContext::{{ context.name }} as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn {{ context.name | snake_case }}_parse_token(&self, input: &mut ParserContext, kind: TokenKind) -> ParserResult - { - Lexer::parse_token::<{ LexicalContext::{{ context.name }} as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn {{ context.name | snake_case }}_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[ - {%- for open, close in context.delimiters %} - (TokenKind::{{ open }}, TokenKind::{{ close }}), - {%- endfor %} - ] - } - {% endfor %} - /******************************************** * Parser Functions ********************************************/ @@ -115,7 +88,7 @@ impl Language { match lexical_context { {%- for lexical_context in code.scanner_contexts -%} LexicalContext::{{ lexical_context.name }} => - Lexer::next_token::<{ LexicalContext::{{ lexical_context.name }} as u8 }>(self, &mut input), + Lexer::next_token::(self, &mut input), {%- endfor -%} } } @@ -138,20 +111,24 @@ impl Lexer for Language { Language::trailing_trivia(self, input) } - fn delimiters() -> &'static [(TokenKind, TokenKind)] { - match LexicalContext::from_repr(LEX_CTX).unwrap() { + fn delimiters() -> &'static [(TokenKind, TokenKind)] { + match LexCtx::value() { {%- for context in code.scanner_contexts %} - LexicalContext::{{ context.name }} => Self::{{ context.name | snake_case }}_delimiters(), + LexicalContext::{{ context.name }} => &[ + {%- for open, close in context.delimiters %} + (TokenKind::{{ open }}, TokenKind::{{ close }}), + {%- endfor %} + ], {%- endfor %} } } - fn next_token(&self, input: &mut ParserContext) -> Option { + fn next_token(&self, input: &mut ParserContext) -> Option { let save = input.position(); let mut furthest_position = input.position(); let mut longest_token = None; - match LexicalContext::from_repr(LEX_CTX).unwrap() { + match LexCtx::value() { {%- for context in code.scanner_contexts %} LexicalContext::{{ context.name }} => { macro_rules! longest_match { diff --git a/crates/infra/cli/generated/infra.zsh-completions b/crates/infra/cli/generated/infra.zsh-completions index bd1594f6df..a68dae217f 100644 --- a/crates/infra/cli/generated/infra.zsh-completions +++ b/crates/infra/cli/generated/infra.zsh-completions @@ -59,7 +59,8 @@ npm\:"Run '\''test'\'' scripts in each NPM package in the repository"))' \ _arguments "${_arguments_options[@]}" \ '-h[Print help (see more with '\''--help'\'')]' \ '--help[Print help (see more with '\''--help'\'')]' \ -'*::commands:((cargo-fmt\:"Format all Rust source files" +'*::commands:((clippy\:"Lints all Rust source files" +cargo-fmt\:"Format all Rust source files" cspell\:"Check for spelling issues in Markdown files" prettier\:"Format all non-Rust source files" markdown-link-check\:"Check for broken links in Markdown files" diff --git a/crates/infra/cli/src/commands/lint/mod.rs b/crates/infra/cli/src/commands/lint/mod.rs index d9fda491fc..7d2b998af0 100644 --- a/crates/infra/cli/src/commands/lint/mod.rs +++ b/crates/infra/cli/src/commands/lint/mod.rs @@ -25,6 +25,9 @@ impl LintController { #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, ValueEnum)] enum LintCommand { + /// Lints all Rust source files. + // Automatically applied lints may need to be formatted again, so we run this before formatting. + Clippy, /// Format all Rust source files. CargoFmt, /// Check for spelling issues in Markdown files. @@ -48,6 +51,7 @@ impl OrderedCommand for LintCommand { Terminal::step(format!("lint {name}", name = self.clap_name())); return match self { + LintCommand::Clippy => run_clippy(), LintCommand::CargoFmt => run_cargo_fmt(), LintCommand::Cspell => run_cspell(), LintCommand::Prettier => run_prettier(), @@ -60,6 +64,16 @@ impl OrderedCommand for LintCommand { } } +fn run_clippy() -> Result<()> { + let mut clippy = Command::new("cargo").flag("clippy").flag("--"); + + if GitHub::is_running_in_ci() { + clippy = clippy.property("-D", "warnings"); + } + + clippy.run() +} + fn run_cargo_fmt() -> Result<()> { let mut command = Command::new("cargo-fmt").flag("--all").flag("--verbose"); diff --git a/crates/solidity/outputs/cargo/crate/src/generated/kinds.rs b/crates/solidity/outputs/cargo/crate/src/generated/kinds.rs index 78e00cedda..2907502d19 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/kinds.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/kinds.rs @@ -533,9 +533,37 @@ pub enum TokenKind { /// The lexical context of the scanner. #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "language"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -#[repr(u8)] // This is used as a const argument, which only supports primitive types pub enum LexicalContext { Default, VersionPragma, YulBlock, } + +/// Marker trait for type-level [`LexicalContext`] variants. +pub trait IsLexicalContext { + /// Returns a run-time [`LexicalContext`] value. + fn value() -> LexicalContext; +} + +#[allow(non_snake_case)] +pub mod LexicalContextType { + use super::*; + pub struct Default {} + impl IsLexicalContext for Default { + fn value() -> LexicalContext { + LexicalContext::Default + } + } + pub struct VersionPragma {} + impl IsLexicalContext for VersionPragma { + fn value() -> LexicalContext { + LexicalContext::VersionPragma + } + } + pub struct YulBlock {} + impl IsLexicalContext for YulBlock { + fn value() -> LexicalContext { + LexicalContext::YulBlock + } + } +} diff --git a/crates/solidity/outputs/cargo/crate/src/generated/language.rs b/crates/solidity/outputs/cargo/crate/src/generated/language.rs index 01030f0706..611c7dabff 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/language.rs @@ -6,7 +6,7 @@ use {napi::bindgen_prelude::*, napi_derive::napi}; use semver::Version; use super::{ - kinds::{ProductionKind, RuleKind, TokenKind}, + kinds::{IsLexicalContext, LexicalContextType, ProductionKind, RuleKind, TokenKind}, lexer::Lexer, parse_output::ParseOutput, support::*, @@ -166,74 +166,6 @@ impl Language { &self.version } - #[allow(dead_code)] - fn default_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token_with_trivia::<{ LexicalContext::Default as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn default_parse_token(&self, input: &mut ParserContext, kind: TokenKind) -> ParserResult { - Lexer::parse_token::<{ LexicalContext::Default as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn default_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[ - (TokenKind::OpenBrace, TokenKind::CloseBrace), - (TokenKind::OpenBracket, TokenKind::CloseBracket), - (TokenKind::OpenParen, TokenKind::CloseParen), - ] - } - - #[allow(dead_code)] - fn version_pragma_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token_with_trivia::<{ LexicalContext::VersionPragma as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn version_pragma_parse_token( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token::<{ LexicalContext::VersionPragma as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn version_pragma_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[] - } - - #[allow(dead_code)] - fn yul_block_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token_with_trivia::<{ LexicalContext::YulBlock as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn yul_block_parse_token(&self, input: &mut ParserContext, kind: TokenKind) -> ParserResult { - Lexer::parse_token::<{ LexicalContext::YulBlock as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn yul_block_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[ - (TokenKind::OpenBrace, TokenKind::CloseBrace), - (TokenKind::OpenParen, TokenKind::CloseParen), - ] - } - /******************************************** * Parser Functions ********************************************/ @@ -241,8 +173,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn abi_coder_pragma(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ABICoderKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ABICoderKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }) .with_kind(RuleKind::ABICoderPragma) @@ -252,14 +190,23 @@ impl Language { fn address_type(&self, input: &mut ParserContext) -> ParserResult { ChoiceHelper::run(input, |mut choice, input| { let result = SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AddressKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AddressKeyword, + ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ), ))?; seq.finish() }); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -271,7 +218,10 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(ChoiceHelper::run(input, |mut choice, input| { let result = self.positional_arguments_list(input); @@ -280,16 +230,17 @@ impl Language { choice.consider(input, result)?; choice.finish(input) })) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }) .with_kind(RuleKind::ArgumentsDeclaration) @@ -300,19 +251,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBracket, + ))?; seq.elem( self.array_values_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBracket, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBracket, + ))?; seq.finish() }) .with_kind(RuleKind::ArrayExpression) @@ -320,11 +275,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn array_values_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.expression(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::ArrayValuesList) } @@ -332,18 +287,26 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn ascii_string_literals_list(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral) + self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ) }) .with_kind(RuleKind::AsciiStringLiteralsList) } #[allow(unused_assignments, unused_parens)] fn assembly_flags_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, - |input| self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral), - TokenKind::Comma, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ) + }, + TokenKind::Comma, ) .with_kind(RuleKind::AssemblyFlagsList) } @@ -351,28 +314,36 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn assembly_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AssemblyKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AssemblyKeyword, + ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral), + self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ), ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( self.assembly_flags_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() })))?; seq.elem(self.yul_block(input))?; @@ -386,19 +357,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.statements_list(input)) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBrace, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }) .with_kind(RuleKind::Block) @@ -408,17 +383,21 @@ impl Language { fn break_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::BreakKeyword) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), + self.parse_token_with_trivia::( + input, + TokenKind::BreakKeyword, + ) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::BreakStatement) @@ -428,7 +407,10 @@ impl Language { fn catch_clause(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CatchKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CatchKeyword, + ))?; seq.elem(OptionalHelper::transform(self.catch_clause_error(input)))?; seq.elem(self.block(input))?; seq.finish() @@ -444,7 +426,10 @@ impl Language { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.elem(self.parameters_declaration(input))?; seq.finish() @@ -472,26 +457,32 @@ impl Language { seq.elem( SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ConstantKeyword), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), - )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -508,14 +499,20 @@ impl Language { ChoiceHelper::run(input, |mut choice, input| { let result = self.modifier_invocation(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -533,9 +530,10 @@ impl Language { fn constructor_definition(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_4_22 { SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ConstructorKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ConstructorKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.constructor_attributes_list(input), @@ -553,17 +551,21 @@ impl Language { fn continue_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ContinueKeyword) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), + self.parse_token_with_trivia::( + input, + TokenKind::ContinueKeyword, + ) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::ContinueStatement) @@ -574,30 +576,41 @@ impl Language { SequenceHelper::run(|mut seq| { if self.version_is_at_least_0_6_0 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::AbstractKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::AbstractKeyword, + ), ))?; } - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ContractKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ContractKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(self.inheritance_specifier(input)))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.contract_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -661,25 +674,33 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( self.deconstruction_import_symbols_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBrace, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FromKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FromKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ))?; seq.finish() }) .with_kind(RuleKind::DeconstructionImport) @@ -688,10 +709,19 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn deconstruction_import_symbol(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() })))?; seq.finish() @@ -701,11 +731,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn deconstruction_import_symbols_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.deconstruction_import_symbol(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::DeconstructionImportSymbolsList) } @@ -715,22 +745,24 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::DeleteKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::DeleteKeyword, + ))?; seq.elem(self.expression(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::DeleteStatement) @@ -741,42 +773,50 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::DoKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::DoKeyword, + ))?; seq.elem(self.statement(input))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::WhileKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::WhileKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), - )?; seq.finish() }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::DoWhileStatement) @@ -788,23 +828,25 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::EmitKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EmitKeyword, + ))?; seq.elem(self.identifier_path(input))?; seq.elem(self.arguments_declaration(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -817,13 +859,19 @@ impl Language { fn end_of_file_trivia(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token(input, TokenKind::Whitespace); + let result = + self.parse_token::(input, TokenKind::Whitespace); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::EndOfLine); + let result = + self.parse_token::(input, TokenKind::EndOfLine); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::MultilineComment); + let result = self + .parse_token::(input, TokenKind::MultilineComment); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::SingleLineComment); + let result = self.parse_token::( + input, + TokenKind::SingleLineComment, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -834,26 +882,34 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn enum_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::EnumKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EnumKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.identifiers_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -863,60 +919,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn error_definition(&self, input: &mut ParserContext) -> ParserResult { - if self.version_is_at_least_0_8_4 { - SequenceHelper::run(|mut seq| { - seq.elem( - SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ErrorKeyword), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), - )?; - seq.elem(SequenceHelper::run(|mut seq| { - let mut delim_guard = input.open_delim(TokenKind::CloseParen); - let input = delim_guard.ctx(); - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), - )?; - seq.elem( - OptionalHelper::transform(self.error_parameters_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), - )?; - seq.finish() - }))?; - seq.finish() - }) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), - )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; - seq.finish() - }) - } else { - ParserResult::disabled() - } - .with_kind(RuleKind::ErrorDefinition) + if self . version_is_at_least_0_8_4 { SequenceHelper :: run (| mut seq | { seq . elem (SequenceHelper :: run (| mut seq | { seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: ErrorKeyword)) ? ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: Identifier)) ? ; seq . elem (SequenceHelper :: run (| mut seq | { let mut delim_guard = input . open_delim (TokenKind :: CloseParen) ; let input = delim_guard . ctx () ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: OpenParen)) ? ; seq . elem (OptionalHelper :: transform (self . error_parameters_list (input)) . recover_until_with_nested_delims :: < _ , LexicalContextType :: Default > (input , self , TokenKind :: CloseParen , RecoverFromNoMatch :: Yes ,)) ? ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: CloseParen)) ? ; seq . finish () })) ? ; seq . finish () }) . recover_until_with_nested_delims :: < _ , LexicalContextType :: Default > (input , self , TokenKind :: Semicolon , RecoverFromNoMatch :: No ,)) ? ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: Semicolon)) ? ; seq . finish () }) } else { ParserResult :: disabled () } . with_kind (RuleKind :: ErrorDefinition) } #[allow(unused_assignments, unused_parens)] @@ -925,7 +928,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.finish() }) @@ -938,11 +944,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn error_parameters_list(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_8_4 { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.error_parameter(input), TokenKind::Comma, - self, ) } else { ParserResult::disabled() @@ -955,49 +961,55 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::EventKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EventKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.event_parameters_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::AnonymousKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::AnonymousKeyword, + ), ))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::EventDefinition) @@ -1008,10 +1020,16 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::IndexedKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::IndexedKeyword, + ), ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.finish() }) @@ -1020,11 +1038,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn event_parameters_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.event_parameter(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::EventParametersList) } @@ -1032,12 +1050,20 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn experimental_pragma(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ExperimentalKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ExperimentalKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; choice.finish(input) }))?; @@ -1054,36 +1080,62 @@ impl Language { 1u8, 1u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Equal); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::BarEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BarEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PlusEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PlusEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::MinusEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinusEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::CaretEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::CaretEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::SlashEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SlashEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PercentEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PercentEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::AsteriskEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AsteriskEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::AmpersandEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AmpersandEqual, + ); choice.consider(input, result)?; - let result = self - .default_parse_token_with_trivia(input, TokenKind::LessThanLessThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanLessThanEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanEqual, ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanGreaterThanEqual, ); @@ -1097,9 +1149,15 @@ impl Language { RuleKind::ConditionalExpression, 3u8, SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::QuestionMark))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::QuestionMark, + ))?; seq.elem(self.expression(input))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Colon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Colon, + ))?; seq.elem(self.expression(input))?; seq.finish() }), @@ -1110,7 +1168,10 @@ impl Language { RuleKind::BinaryExpression, 5u8, 5u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::BarBar), + self.parse_token_with_trivia::( + input, + TokenKind::BarBar, + ), ) }; let parse_and_operator = |input: &mut ParserContext| { @@ -1118,7 +1179,10 @@ impl Language { RuleKind::BinaryExpression, 7u8, 7u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::AmpersandAmpersand), + self.parse_token_with_trivia::( + input, + TokenKind::AmpersandAmpersand, + ), ) }; let parse_equality_comparison_operator = |input: &mut ParserContext| { @@ -1127,9 +1191,15 @@ impl Language { 9u8, 9u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::EqualEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::EqualEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::BangEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BangEqual, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1141,16 +1211,25 @@ impl Language { 11u8, 11u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::LessThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThan, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::GreaterThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThan, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::LessThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::GreaterThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThanEqual, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1161,7 +1240,7 @@ impl Language { RuleKind::BinaryExpression, 13u8, 13u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::Bar), + self.parse_token_with_trivia::(input, TokenKind::Bar), ) }; let parse_bitwise_x_or_operator = |input: &mut ParserContext| { @@ -1169,7 +1248,10 @@ impl Language { RuleKind::BinaryExpression, 15u8, 15u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::Caret), + self.parse_token_with_trivia::( + input, + TokenKind::Caret, + ), ) }; let parse_bitwise_and_operator = |input: &mut ParserContext| { @@ -1177,7 +1259,10 @@ impl Language { RuleKind::BinaryExpression, 17u8, 17u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::Ampersand), + self.parse_token_with_trivia::( + input, + TokenKind::Ampersand, + ), ) }; let parse_shift_operator = |input: &mut ParserContext| { @@ -1186,13 +1271,17 @@ impl Language { 19u8, 19u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::LessThanLessThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanLessThan, + ); choice.consider(input, result)?; - let result = self - .default_parse_token_with_trivia(input, TokenKind::GreaterThanGreaterThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThanGreaterThan, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanGreaterThan, ); @@ -1207,9 +1296,15 @@ impl Language { 21u8, 21u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Plus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Plus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Minus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Minus, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1221,11 +1316,20 @@ impl Language { 23u8, 23u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Asterisk); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Slash); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Slash, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Percent); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Percent, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1236,7 +1340,10 @@ impl Language { RuleKind::BinaryExpression, 25u8, 25u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::AsteriskAsterisk), + self.parse_token_with_trivia::( + input, + TokenKind::AsteriskAsterisk, + ), ) }; let parse_exponentiation_operator_introduced_from_0_6_0 = |input: &mut ParserContext| { @@ -1244,7 +1351,10 @@ impl Language { RuleKind::BinaryExpression, 27u8 + 1, 27u8, - self.default_parse_token_with_trivia(input, TokenKind::AsteriskAsterisk), + self.parse_token_with_trivia::( + input, + TokenKind::AsteriskAsterisk, + ), ) }; let parse_unary_postfix_operator = |input: &mut ParserContext| { @@ -1252,9 +1362,15 @@ impl Language { RuleKind::UnaryPostfixExpression, 29u8, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::PlusPlus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PlusPlus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::MinusMinus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinusMinus, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1265,18 +1381,36 @@ impl Language { RuleKind::UnaryPrefixExpression, 31u8, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::PlusPlus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PlusPlus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::MinusMinus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinusMinus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Tilde); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Tilde, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Bang); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Bang, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Minus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Minus, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { - let result = self.default_parse_token_with_trivia(input, TokenKind::Plus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Plus, + ); choice.consider(input, result)?; } choice.finish(input) @@ -1301,13 +1435,20 @@ impl Language { RuleKind::MemberAccessExpression, 35u8, SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Period))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Period, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::AddressKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AddressKeyword, + ); choice.consider(input, result)?; choice.finish(input) }))?; @@ -1322,31 +1463,36 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBracket, + ))?; seq.elem( SequenceHelper::run(|mut seq| { seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Colon), + self.parse_token_with_trivia::( + input, + TokenKind::Colon, + ), )?; seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.finish() })))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBracket, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBracket, + ))?; seq.finish() }), ) @@ -1367,11 +1513,15 @@ impl Language { let result = self.array_expression(input); choice.consider(input, result)?; let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::TrueKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::TrueKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FalseKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FalseKeyword, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -1391,38 +1541,57 @@ impl Language { }); choice.consider(input, result)?; let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StringKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_3 { let result = self.type_expression(input); @@ -1516,15 +1685,19 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn expression_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem( + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; seq.finish() }) .with_kind(RuleKind::ExpressionStatement) @@ -1540,20 +1713,30 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -1571,14 +1754,20 @@ impl Language { fn fallback_function_definition(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FallbackKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FallbackKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.fallback_function_attributes_list(input), ))?; seq.elem(OptionalHelper::transform(self.returns_declaration(input)))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -1595,11 +1784,17 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn for_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ForKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ForKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { @@ -1613,32 +1808,39 @@ impl Language { choice.finish(input) }); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; choice.finish(input) }))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.expression_statement(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; choice.finish(input) }))?; seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; seq.elem(self.statement(input))?; @@ -1655,30 +1857,53 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PrivateKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ConstantKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ); choice.consider(input, result)?; } if self.version_is_at_least_0_6_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -1707,14 +1932,25 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn function_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FallbackKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FallbackKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::ReceiveKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ReceiveKeyword, + ); choice.consider(input, result)?; choice.finish(input) }))?; @@ -1724,7 +1960,10 @@ impl Language { ))?; seq.elem(OptionalHelper::transform(self.returns_declaration(input)))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -1738,7 +1977,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn function_type(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.function_type_attributes_list(input), @@ -1753,21 +1995,40 @@ impl Language { fn function_type_attributes_list(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PrivateKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -1778,40 +2039,53 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn hex_string_literals_list(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.default_parse_token_with_trivia(input, TokenKind::HexStringLiteral) + self.parse_token_with_trivia::( + input, + TokenKind::HexStringLiteral, + ) }) .with_kind(RuleKind::HexStringLiteralsList) } #[allow(unused_assignments, unused_parens)] fn identifier_path(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, - |input| self.default_parse_token_with_trivia(input, TokenKind::Identifier), - TokenKind::Period, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ) + }, + TokenKind::Period, ) .with_kind(RuleKind::IdentifierPath) } #[allow(unused_assignments, unused_parens)] fn identifier_paths_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.identifier_path(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::IdentifierPathsList) } #[allow(unused_assignments, unused_parens)] fn identifiers_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, - |input| self.default_parse_token_with_trivia(input, TokenKind::Identifier), - TokenKind::Comma, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ) + }, + TokenKind::Comma, ) .with_kind(RuleKind::IdentifiersList) } @@ -1819,25 +2093,38 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn if_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::IfKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::IfKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; + seq.elem( + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }))?; seq.elem(self.statement(input))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ElseKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ElseKeyword, + ))?; seq.elem(self.statement(input))?; seq.finish() })))?; @@ -1851,9 +2138,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ImportKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ImportKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.path_import(input); choice.consider(input, result)?; @@ -1865,16 +2153,17 @@ impl Language { }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::ImportDirective) @@ -1883,7 +2172,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn inheritance_specifier(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::IsKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::IsKeyword, + ))?; seq.elem(self.inheritance_types_list(input))?; seq.finish() }) @@ -1902,11 +2194,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn inheritance_types_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.inheritance_type(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::InheritanceTypesList) } @@ -1914,27 +2206,35 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn interface_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::InterfaceKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::InterfaceKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(self.inheritance_specifier(input)))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.interface_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -1996,13 +2296,19 @@ impl Language { fn leading_trivia(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token(input, TokenKind::Whitespace); + let result = + self.parse_token::(input, TokenKind::Whitespace); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::EndOfLine); + let result = + self.parse_token::(input, TokenKind::EndOfLine); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::MultilineComment); + let result = self + .parse_token::(input, TokenKind::MultilineComment); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::SingleLineComment); + let result = self.parse_token::( + input, + TokenKind::SingleLineComment, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -2013,26 +2319,34 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn library_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::LibraryKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::LibraryKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.library_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -2095,32 +2409,48 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StringKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -2132,7 +2462,10 @@ impl Language { }))?; if self.version_is_at_least_0_8_18 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; } seq.finish() @@ -2143,33 +2476,38 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn mapping_type(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::MappingKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::MappingKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( SequenceHelper::run(|mut seq| { seq.elem(self.mapping_key_type(input))?; - seq.elem( - self.default_parse_token_with_trivia( - input, - TokenKind::EqualGreaterThan, - ), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EqualGreaterThan, + ))?; seq.elem(self.mapping_value_type(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; seq.finish() @@ -2183,7 +2521,10 @@ impl Language { seq.elem(self.type_name(input))?; if self.version_is_at_least_0_8_18 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; } seq.finish() @@ -2198,8 +2539,10 @@ impl Language { let result = self.override_specifier(input); choice.consider(input, result)?; if self.version_is_at_least_0_6_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -2211,8 +2554,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn modifier_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ModifierKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ModifierKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform( self.parameters_declaration(input), ))?; @@ -2220,7 +2569,10 @@ impl Language { self.modifier_attributes_list(input), ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -2244,8 +2596,16 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_argument(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Colon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::Colon, + ), + )?; seq.elem(self.expression(input))?; seq.finish() }) @@ -2257,19 +2617,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.named_arguments_list(input)) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }) .with_kind(RuleKind::NamedArgumentsDeclaration) @@ -2277,11 +2641,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_arguments_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.named_argument(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::NamedArgumentsList) } @@ -2289,11 +2653,26 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_import(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Asterisk))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FromKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FromKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ))?; seq.finish() }) .with_kind(RuleKind::NamedImport) @@ -2302,7 +2681,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn new_expression(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::NewKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::NewKeyword, + ))?; seq.elem(self.type_name(input))?; seq.finish() }) @@ -2313,55 +2695,85 @@ impl Language { fn numeric_expression(&self, input: &mut ParserContext) -> ParserResult { ChoiceHelper::run(input, |mut choice, input| { let result = SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::HexLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::HexLiteral, + ))?; if !self.version_is_at_least_0_5_0 { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::DaysKeyword); - choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::EtherKeyword); + .parse_token_with_trivia::( + input, + TokenKind::DaysKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::HoursKeyword); + .parse_token_with_trivia::( + input, + TokenKind::EtherKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::MinutesKeyword); + .parse_token_with_trivia::( + input, + TokenKind::HoursKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::SecondsKeyword); + .parse_token_with_trivia::( + input, + TokenKind::MinutesKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::WeeksKeyword); + .parse_token_with_trivia::( + input, + TokenKind::SecondsKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::WeiKeyword); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::WeeksKeyword, + ); choice.consider(input, result)?; - if !self.version_is_at_least_0_5_0 { - let result = self.default_parse_token_with_trivia( + let result = self + .parse_token_with_trivia::( input, - TokenKind::YearsKeyword, + TokenKind::WeiKeyword, ); + choice.consider(input, result)?; + if !self.version_is_at_least_0_5_0 { + let result = self + .parse_token_with_trivia::( + input, + TokenKind::YearsKeyword, + ); choice.consider(input, result)?; } if self.version_is_at_least_0_6_11 { let result = self - .default_parse_token_with_trivia(input, TokenKind::GweiKeyword); + .parse_token_with_trivia::( + input, + TokenKind::GweiKeyword, + ); choice.consider(input, result)?; } if !self.version_is_at_least_0_7_0 { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia( - input, - TokenKind::FinneyKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::FinneyKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::SzaboKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::SzaboKeyword, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -2375,52 +2787,77 @@ impl Language { }); choice.consider(input, result)?; let result = SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::DecimalLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::DecimalLiteral, + ))?; seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::DaysKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::DaysKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::EtherKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::EtherKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::HoursKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::HoursKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::MinutesKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinutesKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SecondsKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SecondsKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::WeeksKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::WeeksKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::WeiKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::WeiKeyword, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::YearsKeyword); + .parse_token_with_trivia::( + input, + TokenKind::YearsKeyword, + ); choice.consider(input, result)?; } if self.version_is_at_least_0_6_11 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::GweiKeyword); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::GweiKeyword, + ); choice.consider(input, result)?; } if !self.version_is_at_least_0_7_0 { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia( - input, - TokenKind::FinneyKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::FinneyKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::SzaboKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::SzaboKeyword, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -2440,25 +2877,30 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn override_specifier(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OverrideKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OverrideKeyword, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.identifier_paths_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() })))?; seq.finish() @@ -2473,22 +2915,31 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.finish() }) @@ -2500,19 +2951,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.parameters_list(input)) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }) .with_kind(RuleKind::ParametersDeclaration) @@ -2520,11 +2975,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn parameters_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.parameter(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::ParametersList) } @@ -2532,10 +2987,19 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn path_import(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() })))?; seq.finish() @@ -2545,11 +3009,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn positional_arguments_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.expression(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::PositionalArgumentsList) } @@ -2559,9 +3023,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::PragmaKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::PragmaKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.abi_coder_pragma(input); choice.consider(input, result)?; @@ -2573,16 +3038,17 @@ impl Language { }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::PragmaDirective) @@ -2598,14 +3064,20 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -2623,13 +3095,19 @@ impl Language { fn receive_function_definition(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ReceiveKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ReceiveKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.receive_function_attributes_list(input), ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -2648,22 +3126,24 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ReturnKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ReturnKeyword, + ))?; seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::ReturnStatement) @@ -2672,7 +3152,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn returns_declaration(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ReturnsKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ReturnsKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.finish() }) @@ -2684,23 +3167,25 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::RevertKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::RevertKeyword, + ))?; seq.elem(OptionalHelper::transform(self.identifier_path(input)))?; seq.elem(self.arguments_declaration(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::RevertStatement) @@ -2774,19 +3259,31 @@ impl Language { ChoiceHelper::run(input, |mut choice, input| { let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ConstantKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PrivateKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_6_5 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ImmutableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ImmutableKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -2804,24 +3301,31 @@ impl Language { seq.elem(OptionalHelper::transform( self.state_variable_attributes_list(input), ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() })))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::StateVariableDefinition) @@ -2898,26 +3402,34 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn struct_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::StructKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::StructKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.struct_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -2931,19 +3443,23 @@ impl Language { seq.elem( SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::StructMember) @@ -2960,19 +3476,21 @@ impl Language { if !self.version_is_at_least_0_5_0 { SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ThrowKeyword) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), + self.parse_token_with_trivia::( + input, + TokenKind::ThrowKeyword, + ) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -2985,12 +3503,15 @@ impl Language { fn trailing_trivia(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem(OptionalHelper::transform( - self.default_parse_token(input, TokenKind::Whitespace), + self.parse_token::(input, TokenKind::Whitespace), ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token(input, TokenKind::SingleLineComment), + self.parse_token::( + input, + TokenKind::SingleLineComment, + ), ))?; - seq.elem(self.default_parse_token(input, TokenKind::EndOfLine))?; + seq.elem(self.parse_token::(input, TokenKind::EndOfLine))?; seq.finish() }) .with_kind(RuleKind::TrailingTrivia) @@ -3000,7 +3521,10 @@ impl Language { fn try_statement(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::TryKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::TryKeyword, + ))?; seq.elem(self.expression(input))?; seq.elem(OptionalHelper::transform(self.returns_declaration(input)))?; seq.elem(self.block(input))?; @@ -3021,43 +3545,43 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.tuple_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::TupleDeconstructionStatement) @@ -3068,19 +3592,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( self.tuple_values_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }) .with_kind(RuleKind::TupleExpression) @@ -3094,21 +3622,31 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + .parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }); choice.consider(input, result)?; @@ -3116,21 +3654,31 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + .parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }); choice.consider(input, result)?; @@ -3141,22 +3689,22 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn tuple_members_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.tuple_member(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::TupleMembersList) } #[allow(unused_assignments, unused_parens)] fn tuple_values_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| OptionalHelper::transform(self.expression(input)), TokenKind::Comma, - self, ) .with_kind(RuleKind::TupleValuesList) } @@ -3165,20 +3713,30 @@ impl Language { fn type_expression(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_5_3 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::TypeKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::TypeKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; - seq.elem(self.type_name(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; + seq.elem( + self.type_name(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }))?; seq.finish() @@ -3198,23 +3756,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBracket, + ))?; seq.elem( OptionalHelper::transform(self.expression(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBracket, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBracket, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBracket, + ))?; seq.finish() }), ) @@ -3226,32 +3784,48 @@ impl Language { let result = self.mapping_type(input); choice.consider(input, result)?; let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StringKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -3289,7 +3863,10 @@ impl Language { fn unchecked_block(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_8_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::UncheckedKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::UncheckedKeyword, + ))?; seq.elem(self.block(input))?; seq.finish() }) @@ -3303,7 +3880,10 @@ impl Language { fn unicode_string_literals_list(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_7_0 { OneOrMoreHelper::run(input, |input| { - self.default_parse_token_with_trivia(input, TokenKind::UnicodeStringLiteral) + self.parse_token_with_trivia::( + input, + TokenKind::UnicodeStringLiteral, + ) }) } else { ParserResult::disabled() @@ -3321,17 +3901,25 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -3349,13 +3937,19 @@ impl Language { fn unnamed_function_definition(&self, input: &mut ParserContext) -> ParserResult { if !self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.unnamed_function_attributes_list(input), ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -3375,64 +3969,86 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::TypeKeyword), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::IsKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::TypeKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::IsKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::StringKeyword); + .parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + .parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::SignedIntegerType, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::UnsignedIntegerType, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + .parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::UnsignedFixedType, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + .parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -3446,7 +4062,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::UsingKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::UsingKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.using_directive_path(input); choice.consider(input, result)?; @@ -3454,10 +4073,15 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ForKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ForKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::Asterisk); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ); choice.consider(input, result)?; let result = self.type_name(input); choice.consider(input, result)?; @@ -3465,21 +4089,25 @@ impl Language { }))?; if self.version_is_at_least_0_8_13 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::GlobalKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::GlobalKeyword, + ), ))?; } seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::UsingDirective) @@ -3490,19 +4118,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( self.using_directive_symbols_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBrace, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }) .with_kind(RuleKind::UsingDirectiveDeconstruction) @@ -3520,55 +4152,101 @@ impl Language { seq.elem(self.identifier_path(input))?; if self.version_is_at_least_0_8_19 { seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; seq.elem(if self.version_is_at_least_0_8_19 { ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::Ampersand); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Ampersand, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Asterisk); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::BangEqual); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::BangEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Bar); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Bar, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Caret); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Caret, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::EqualEqual); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::EqualEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::GreaterThan); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::GreaterThan, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::GreaterThanEqual, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::GreaterThanEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::LessThan); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::LessThan, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::LessThanEqual); + .parse_token_with_trivia::( + input, + TokenKind::LessThanEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Minus); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Minus, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Percent); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Percent, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Plus); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Plus, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Slash); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Slash, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Tilde); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Tilde, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -3585,11 +4263,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn using_directive_symbols_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.using_directive_symbol(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::UsingDirectiveSymbolsList) } @@ -3599,7 +4277,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { if !self.version_is_at_least_0_5_0 { - let result = self.default_parse_token_with_trivia(input, TokenKind::VarKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VarKeyword, + ); choice.consider(input, result)?; } let result = self.type_name(input); @@ -3609,21 +4290,30 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }) .with_kind(RuleKind::VariableDeclaration) @@ -3636,22 +4326,26 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(self.variable_declaration(input))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() })))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::VariableDeclarationStatement) @@ -3661,7 +4355,10 @@ impl Language { fn version_pragma(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem( - self.version_pragma_parse_token_with_trivia(input, TokenKind::SolidityKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::SolidityKeyword, + ), )?; seq.elem(self.version_pragma_expressions_list(input))?; seq.finish() @@ -3676,7 +4373,10 @@ impl Language { RuleKind::VersionPragmaBinaryExpression, 1u8, 1u8 + 1, - self.version_pragma_parse_token_with_trivia(input, TokenKind::BarBar), + self.parse_token_with_trivia::( + input, + TokenKind::BarBar, + ), ) }; let parse_version_pragma_range_operator = |input: &mut ParserContext| { @@ -3684,7 +4384,10 @@ impl Language { RuleKind::VersionPragmaBinaryExpression, 3u8, 3u8 + 1, - self.version_pragma_parse_token_with_trivia(input, TokenKind::Minus), + self.parse_token_with_trivia::( + input, + TokenKind::Minus, + ), ) }; let parse_version_pragma_unary_operator = |input: &mut ParserContext| { @@ -3692,26 +4395,40 @@ impl Language { RuleKind::VersionPragmaUnaryExpression, 5u8, ChoiceHelper::run(input, |mut choice, input| { - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::Caret); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Caret, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::Tilde); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Tilde, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::Equal); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::LessThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThan, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::GreaterThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThan, + ); choice.consider(input, result)?; - let result = self - .version_pragma_parse_token_with_trivia(input, TokenKind::LessThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanEqual, + ); choice.consider(input, result)?; - let result = self - .version_pragma_parse_token_with_trivia(input, TokenKind::GreaterThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThanEqual, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -3772,13 +4489,16 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn version_pragma_specifier(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::VersionPragma as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::VersionPragma>( input, + self, |input| { - self.version_pragma_parse_token_with_trivia(input, TokenKind::VersionPragmaValue) + self.parse_token_with_trivia::( + input, + TokenKind::VersionPragmaValue, + ) }, TokenKind::Period, - self, ) .with_kind(RuleKind::VersionPragmaSpecifier) } @@ -3786,20 +4506,30 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn while_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::WhileKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::WhileKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; + seq.elem( + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }))?; seq.elem(self.statement(input))?; @@ -3812,7 +4542,12 @@ impl Language { fn yul_assignment_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem(self.yul_identifier_paths_list(input))?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::ColonEqual))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::ColonEqual, + ), + )?; seq.elem(self.yul_expression(input))?; seq.finish() }) @@ -3824,21 +4559,27 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ), + )?; seq.elem( OptionalHelper::transform(self.yul_statements_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::yul_block_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::YulBlock>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ), )?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::CloseBrace))?; seq.finish() }) .with_kind(RuleKind::YulBlock) @@ -3846,23 +4587,36 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_break_statement(&self, input: &mut ParserContext) -> ParserResult { - self.yul_block_parse_token_with_trivia(input, TokenKind::BreakKeyword) + self.parse_token_with_trivia::(input, TokenKind::BreakKeyword) .with_kind(RuleKind::YulBreakStatement) } #[allow(unused_assignments, unused_parens)] fn yul_continue_statement(&self, input: &mut ParserContext) -> ParserResult { - self.yul_block_parse_token_with_trivia(input, TokenKind::ContinueKeyword) - .with_kind(RuleKind::YulContinueStatement) + self.parse_token_with_trivia::( + input, + TokenKind::ContinueKeyword, + ) + .with_kind(RuleKind::YulContinueStatement) } #[allow(unused_assignments, unused_parens)] fn yul_declaration_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::LetKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::LetKeyword, + ), + )?; seq.elem(self.yul_identifier_paths_list(input))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::ColonEqual))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::ColonEqual, + ), + )?; seq.elem(self.yul_expression(input))?; seq.finish() })))?; @@ -3880,23 +4634,27 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ), + )?; seq.elem( OptionalHelper::transform(self.yul_expressions_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::yul_block_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::YulBlock>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ), )?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }), ) @@ -3904,23 +4662,35 @@ impl Language { let primary_expression_parser = |input: &mut ParserContext| { ChoiceHelper::run(input, |mut choice, input| { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::TrueKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::TrueKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::FalseKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FalseKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::YulHexLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulHexLiteral, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::YulDecimalLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulDecimalLiteral, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::HexStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::HexStringLiteral, + ); choice.consider(input, result)?; - let result = self - .yul_block_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -3955,11 +4725,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_expressions_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, + self, |input| self.yul_expression(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::YulExpressionsList) } @@ -3967,7 +4737,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_for_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::ForKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::ForKeyword, + ), + )?; seq.elem(self.yul_block(input))?; seq.elem(self.yul_expression(input))?; seq.elem(self.yul_block(input))?; @@ -3980,8 +4755,18 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_function_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::YulIdentifier))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::YulIdentifier, + ), + )?; seq.elem(self.yul_parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.yul_returns_declaration(input), @@ -3994,33 +4779,43 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_identifier_path(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, - |input| self.yul_block_parse_token_with_trivia(input, TokenKind::YulIdentifier), - TokenKind::Period, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::YulIdentifier, + ) + }, + TokenKind::Period, ) .with_kind(RuleKind::YulIdentifierPath) } #[allow(unused_assignments, unused_parens)] fn yul_identifier_paths_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, + self, |input| self.yul_identifier_path(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::YulIdentifierPathsList) } #[allow(unused_assignments, unused_parens)] fn yul_identifiers_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, - |input| self.yul_block_parse_token_with_trivia(input, TokenKind::YulIdentifier), - TokenKind::Comma, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::YulIdentifier, + ) + }, + TokenKind::Comma, ) .with_kind(RuleKind::YulIdentifiersList) } @@ -4028,7 +4823,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_if_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::IfKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::IfKeyword, + ), + )?; seq.elem(self.yul_expression(input))?; seq.elem(self.yul_block(input))?; seq.finish() @@ -4039,7 +4839,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_leave_statement(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { - self.yul_block_parse_token_with_trivia(input, TokenKind::LeaveKeyword) + self.parse_token_with_trivia::( + input, + TokenKind::LeaveKeyword, + ) } else { ParserResult::disabled() } @@ -4051,21 +4854,27 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ), + )?; seq.elem( OptionalHelper::transform(self.yul_identifiers_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::yul_block_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::YulBlock>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ), )?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }) .with_kind(RuleKind::YulParametersDeclaration) @@ -4074,7 +4883,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_returns_declaration(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::MinusGreaterThan))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::MinusGreaterThan, + ), + )?; seq.elem(self.yul_identifiers_list(input))?; seq.finish() }) @@ -4123,30 +4937,45 @@ impl Language { fn yul_switch_case(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::DefaultKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::DefaultKeyword, + ); choice.consider(input, result)?; let result = SequenceHelper::run(|mut seq| { seq.elem( - self.yul_block_parse_token_with_trivia(input, TokenKind::CaseKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::CaseKeyword, + ), )?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::TrueKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::TrueKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::FalseKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FalseKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::YulHexLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulHexLiteral, + ); choice.consider(input, result)?; - let result = self - .yul_block_parse_token_with_trivia(input, TokenKind::YulDecimalLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulDecimalLiteral, + ); choice.consider(input, result)?; - let result = self - .yul_block_parse_token_with_trivia(input, TokenKind::HexStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::HexStringLiteral, + ); choice.consider(input, result)?; - let result = self.yul_block_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::AsciiStringLiteral, ); @@ -4173,7 +5002,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_switch_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::SwitchKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::SwitchKeyword, + ), + )?; seq.elem(self.yul_expression(input))?; seq.elem(self.yul_switch_cases_list(input))?; seq.finish() @@ -4760,13 +5594,13 @@ impl Language { let mut input = ParserContext::new(input); match lexical_context { LexicalContext::Default => { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, &mut input) + Lexer::next_token::(self, &mut input) } LexicalContext::VersionPragma => { - Lexer::next_token::<{ LexicalContext::VersionPragma as u8 }>(self, &mut input) + Lexer::next_token::(self, &mut input) } LexicalContext::YulBlock => { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>(self, &mut input) + Lexer::next_token::(self, &mut input) } } } @@ -4997,20 +5831,27 @@ impl Lexer for Language { Language::trailing_trivia(self, input) } - fn delimiters() -> &'static [(TokenKind, TokenKind)] { - match LexicalContext::from_repr(LEX_CTX).unwrap() { - LexicalContext::Default => Self::default_delimiters(), - LexicalContext::VersionPragma => Self::version_pragma_delimiters(), - LexicalContext::YulBlock => Self::yul_block_delimiters(), + fn delimiters() -> &'static [(TokenKind, TokenKind)] { + match LexCtx::value() { + LexicalContext::Default => &[ + (TokenKind::OpenBrace, TokenKind::CloseBrace), + (TokenKind::OpenBracket, TokenKind::CloseBracket), + (TokenKind::OpenParen, TokenKind::CloseParen), + ], + LexicalContext::VersionPragma => &[], + LexicalContext::YulBlock => &[ + (TokenKind::OpenBrace, TokenKind::CloseBrace), + (TokenKind::OpenParen, TokenKind::CloseParen), + ], } } - fn next_token(&self, input: &mut ParserContext) -> Option { + fn next_token(&self, input: &mut ParserContext) -> Option { let save = input.position(); let mut furthest_position = input.position(); let mut longest_token = None; - match LexicalContext::from_repr(LEX_CTX).unwrap() { + match LexCtx::value() { LexicalContext::Default => { macro_rules! longest_match { ($( { $kind:ident = $function:ident } )*) => { diff --git a/crates/solidity/outputs/cargo/crate/src/generated/lexer.rs b/crates/solidity/outputs/cargo/crate/src/generated/lexer.rs index 0ee1eba42d..4661f4e2b7 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/lexer.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/lexer.rs @@ -2,42 +2,53 @@ use crate::{ cst, - kinds::{LexicalContext, TokenKind}, + kinds::{IsLexicalContext, TokenKind}, support::{ParserContext, ParserResult}, }; -// Ensure that the `LexicalContext` enum is `repr(u8)`. -// Workaround until repr(u8) enums can be used as const params. -const _ASSERT_CONTEXT_IS_REPR_U8: fn() = || { - let _ = core::mem::transmute::; -}; - pub trait Lexer { // Generated by the templating engine #[doc(hidden)] - fn next_token(&self, input: &mut ParserContext) -> Option; + fn next_token(&self, input: &mut ParserContext) -> Option; // NOTE: These are context-insensitive #[doc(hidden)] fn leading_trivia(&self, input: &mut ParserContext) -> ParserResult; #[doc(hidden)] fn trailing_trivia(&self, input: &mut ParserContext) -> ParserResult; #[doc(hidden)] - fn delimiters() -> &'static [(TokenKind, TokenKind)]; + /// Returns valid grouping delimiters in the given lexical context. + fn delimiters() -> &'static [(TokenKind, TokenKind)]; - fn peek_token(&self, input: &mut ParserContext) -> Option { + /// Peeks the next token, including trivia. Does not advance the input. + fn peek_token(&self, input: &mut ParserContext) -> Option { let start = input.position(); - let token = self.next_token::(input); + let token = self.next_token::(input); + input.set_position(start); + token + } + + /// Peeks the next significant (i.e. non-trivia) token. Does not advance the input. + fn peek_token_with_trivia( + &self, + input: &mut ParserContext, + ) -> Option { + let start = input.position(); + + let _ = self.leading_trivia(input); + let token = self.next_token::(input); + input.set_position(start); token } - fn parse_token( + /// Attempts to consume the next expected token. Advances the input only if the token matches. + fn parse_token( &self, input: &mut ParserContext, kind: TokenKind, ) -> ParserResult { let start = input.position(); - if self.next_token::(input) != Some(kind) { + if self.next_token::(input) != Some(kind) { input.set_position(start); return ParserResult::no_match(vec![kind]); } @@ -49,7 +60,9 @@ pub trait Lexer { ) } - fn parse_token_with_trivia( + /// Attempts to consume the next significant token including both leading and trailing trivia. + /// Advances the input only if the token matches. + fn parse_token_with_trivia( &self, input: &mut ParserContext, kind: TokenKind, @@ -64,7 +77,7 @@ pub trait Lexer { } let start = input.position(); - if self.next_token::(input) != Some(kind) { + if self.next_token::(input) != Some(kind) { input.set_position(restore); return ParserResult::no_match(vec![kind]); } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/support/recovery.rs b/crates/solidity/outputs/cargo/crate/src/generated/support/recovery.rs index 8aec4fffd4..d6d3e1016b 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/support/recovery.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/support/recovery.rs @@ -1,7 +1,8 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use crate::cst; -use crate::kinds::TokenKind; +use crate::kinds::{IsLexicalContext, TokenKind}; +use crate::lexer::Lexer; use crate::parse_error::ParseError; use crate::support::ParserResult; use crate::text_index::{TextRange, TextRangeExtensions as _}; @@ -41,27 +42,15 @@ impl ParserResult { /// /// Respects nested delimiters, i.e. the `expected` token is only accepted if it's not nested inside. /// Does not consume the `expected` token. - pub fn recover_until_with_nested_delims( + pub fn recover_until_with_nested_delims( self, input: &mut ParserContext, - next_token: impl Fn(&mut ParserContext) -> Option, - leading_trivia: impl Fn(&mut ParserContext) -> ParserResult, + lexer: &L, expected: TokenKind, - delims: &[(TokenKind, TokenKind)], recover_from_no_match: RecoverFromNoMatch, ) -> ParserResult { let before_recovery = input.position(); - let mut peek_token_after_trivia = || { - let start = input.position(); - - opt_parse(input, &leading_trivia); - let token = next_token(input); - - input.set_position(start); - token - }; - enum ParseResultKind { Match, Incomplete, @@ -74,7 +63,9 @@ impl ParserResult { result.expected_tokens, ParseResultKind::Incomplete, ), - ParserResult::Match(result) if peek_token_after_trivia() != Some(expected) => { + ParserResult::Match(result) + if lexer.peek_token_with_trivia::(input) != Some(expected) => + { (result.nodes, result.expected_tokens, ParseResultKind::Match) } ParserResult::NoMatch(result) if recover_from_no_match.as_bool() => { @@ -84,9 +75,9 @@ impl ParserResult { _ => return self, }; - let leading_trivia = opt_parse(input, &leading_trivia); + let leading_trivia = opt_parse(input, |input| lexer.leading_trivia(input)); - match skip_until_with_nested_delims(input, next_token, expected, delims) { + match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, expected) { Some((found, skipped_range)) => { nodes.extend(leading_trivia); if matches!(result_kind, ParseResultKind::Match) { @@ -100,24 +91,24 @@ impl ParserResult { tokens_that_would_have_allowed_more_progress: expected_tokens.clone(), }); - return ParserResult::SkippedUntil(SkippedUntil { + ParserResult::SkippedUntil(SkippedUntil { nodes, expected, skipped, found, - }); + }) } // Not found till EOF, revert any recovery attempt None => { input.set_position(before_recovery); - return match result_kind { + match result_kind { ParseResultKind::Match => ParserResult::r#match(nodes, expected_tokens), ParseResultKind::Incomplete => { ParserResult::incomplete_match(nodes, expected_tokens) } ParseResultKind::NoMatch => ParserResult::no_match(expected_tokens), - }; + } } } } @@ -128,18 +119,19 @@ impl ParserResult { /// Does not consume the `expected` token. /// /// Returns the found token and the range of skipped tokens on success. -pub fn skip_until_with_nested_delims( +pub fn skip_until_with_nested_delims( input: &mut ParserContext, - next_token: impl Fn(&mut ParserContext) -> Option, + lexer: &L, until: TokenKind, - delims: &[(TokenKind, TokenKind)], ) -> Option<(TokenKind, TextRange)> { + let delims = L::delimiters::(); + let start = input.position(); let mut local_delims = vec![]; loop { let save = input.position(); - match next_token(input) { + match lexer.next_token::(input) { // If we're not skipping past a local delimited group (delimiter stack is empty), // we can unwind on a token that's expected by us or by our ancestor. Some(token) diff --git a/crates/solidity/outputs/cargo/crate/src/generated/support/separated_helper.rs b/crates/solidity/outputs/cargo/crate/src/generated/support/separated_helper.rs index dddf9def05..58721ac557 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/support/separated_helper.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/support/separated_helper.rs @@ -1,21 +1,26 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use crate::{ - cst, kinds::TokenKind, lexer::Lexer, parse_error::ParseError, text_index::TextRangeExtensions, -}; - -use super::{ - parser_result::IncompleteMatch, skip_until_with_nested_delims, ParserContext, ParserResult, + cst, + kinds::{IsLexicalContext, TokenKind}, + lexer::Lexer, + parse_error::ParseError, + support::{ + parser_result::{ParserResult, SkippedUntil}, + recovery::skip_until_with_nested_delims, + ParserContext, + }, + text_index::TextRangeExtensions, }; pub struct SeparatedHelper; impl SeparatedHelper { - pub fn run( + pub fn run( input: &mut ParserContext, + lexer: &L, body_parser: impl Fn(&mut ParserContext) -> ParserResult, separator: TokenKind, - lexer: &L, ) -> ParserResult { let mut accum = vec![]; loop { @@ -23,16 +28,9 @@ impl SeparatedHelper { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); - // Parse the leading trivia so that we can peek the next significant token - if let ParserResult::Match(r#match) = lexer.leading_trivia(input) { - accum.extend(r#match.nodes); - } - - match lexer.peek_token::(input) { + match lexer.peek_token_with_trivia::(input) { Some(token) if token == separator => { - let separator = - lexer.parse_token_with_trivia::(input, separator); - match separator { + match lexer.parse_token_with_trivia::(input, separator) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); continue; @@ -40,21 +38,12 @@ impl SeparatedHelper { _ => unreachable!("We just checked that the separator matches"), } } - // Heuristic: lists (separated-by) are often in a delimited group, so if we - // see a closing delimiter, we assume that we're done and don't recover. - Some(token) if input.closing_delimiters().contains(&token) => { - return ParserResult::r#match(accum, vec![separator]); - } - // Otherwise, we try to recover from unexpected tokens until we see a separator - Some(..) => { - // TODO: Attempt recovery: sometimes the list is not in a delimited group, - // so don't attempt to recover for now to not risk misparses - return ParserResult::r#match(accum, vec![separator]); - } - // EOF - None => { - return ParserResult::r#match(accum, vec![separator]); - } + + // Unrecognized, return the accumulated matches. + // NOTE: We can't correctly attempt recovery until #600 lands, otherwise we'd risk misparses, + // as we need to stop at certain synchronizing tokens (and we can't reliably scan until + // a delimiter, as not every list is enclosed in a delimited group). + Some(..) | None => return ParserResult::r#match(accum, vec![separator]), } } // Body was partially parsed, so try to recover by skipping tokens until we see a separator @@ -63,14 +52,7 @@ impl SeparatedHelper { let start = input.position(); - let skipped = skip_until_with_nested_delims( - input, - |input| lexer.next_token::(input), - separator, - ::delimiters::(), - ); - - match skipped { + match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, separator) { // A separator was found, so we can recover the incomplete match Some((found, skipped_range)) if found == separator => { accum.push(cst::Node::token( @@ -83,7 +65,7 @@ impl SeparatedHelper { .expected_tokens, }); - match lexer.parse_token_with_trivia::(input, separator) { + match lexer.parse_token_with_trivia::(input, separator) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); continue; @@ -91,23 +73,17 @@ impl SeparatedHelper { _ => unreachable!("We just checked that the separator matches"), } } + // Didn't find a separator during recovery. It might've been the last of the // separatees, so we can't recover to not risk misparses. - Some(..) => { + Some(..) | None => { // Undo the recovery attempt input.set_position(start); - return ParserResult::IncompleteMatch(IncompleteMatch { - nodes: accum, - expected_tokens: incomplete.expected_tokens, - }); - } - // Separator wasn't found till EOF, so we can't recover - None => { - return ParserResult::IncompleteMatch(IncompleteMatch { - nodes: accum, - expected_tokens: incomplete.expected_tokens, - }); + return ParserResult::incomplete_match( + accum, + incomplete.expected_tokens, + ); } } } @@ -121,7 +97,8 @@ impl SeparatedHelper { ParserResult::SkippedUntil(skipped) => { accum.extend(skipped.nodes); - return ParserResult::SkippedUntil(super::parser_result::SkippedUntil { + + return ParserResult::SkippedUntil(SkippedUntil { nodes: accum, ..skipped }); diff --git a/crates/solidity/outputs/npm/crate/src/generated/kinds.rs b/crates/solidity/outputs/npm/crate/src/generated/kinds.rs index 78e00cedda..2907502d19 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/kinds.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/kinds.rs @@ -533,9 +533,37 @@ pub enum TokenKind { /// The lexical context of the scanner. #[cfg_attr(feature = "slang_napi_interfaces", /* derives `Clone` and `Copy` */ napi(string_enum, namespace = "language"))] #[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] -#[repr(u8)] // This is used as a const argument, which only supports primitive types pub enum LexicalContext { Default, VersionPragma, YulBlock, } + +/// Marker trait for type-level [`LexicalContext`] variants. +pub trait IsLexicalContext { + /// Returns a run-time [`LexicalContext`] value. + fn value() -> LexicalContext; +} + +#[allow(non_snake_case)] +pub mod LexicalContextType { + use super::*; + pub struct Default {} + impl IsLexicalContext for Default { + fn value() -> LexicalContext { + LexicalContext::Default + } + } + pub struct VersionPragma {} + impl IsLexicalContext for VersionPragma { + fn value() -> LexicalContext { + LexicalContext::VersionPragma + } + } + pub struct YulBlock {} + impl IsLexicalContext for YulBlock { + fn value() -> LexicalContext { + LexicalContext::YulBlock + } + } +} diff --git a/crates/solidity/outputs/npm/crate/src/generated/language.rs b/crates/solidity/outputs/npm/crate/src/generated/language.rs index 01030f0706..611c7dabff 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/language.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/language.rs @@ -6,7 +6,7 @@ use {napi::bindgen_prelude::*, napi_derive::napi}; use semver::Version; use super::{ - kinds::{ProductionKind, RuleKind, TokenKind}, + kinds::{IsLexicalContext, LexicalContextType, ProductionKind, RuleKind, TokenKind}, lexer::Lexer, parse_output::ParseOutput, support::*, @@ -166,74 +166,6 @@ impl Language { &self.version } - #[allow(dead_code)] - fn default_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token_with_trivia::<{ LexicalContext::Default as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn default_parse_token(&self, input: &mut ParserContext, kind: TokenKind) -> ParserResult { - Lexer::parse_token::<{ LexicalContext::Default as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn default_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[ - (TokenKind::OpenBrace, TokenKind::CloseBrace), - (TokenKind::OpenBracket, TokenKind::CloseBracket), - (TokenKind::OpenParen, TokenKind::CloseParen), - ] - } - - #[allow(dead_code)] - fn version_pragma_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token_with_trivia::<{ LexicalContext::VersionPragma as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn version_pragma_parse_token( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token::<{ LexicalContext::VersionPragma as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn version_pragma_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[] - } - - #[allow(dead_code)] - fn yul_block_parse_token_with_trivia( - &self, - input: &mut ParserContext, - kind: TokenKind, - ) -> ParserResult { - Lexer::parse_token_with_trivia::<{ LexicalContext::YulBlock as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - fn yul_block_parse_token(&self, input: &mut ParserContext, kind: TokenKind) -> ParserResult { - Lexer::parse_token::<{ LexicalContext::YulBlock as u8 }>(self, input, kind) - } - - #[allow(dead_code)] - const fn yul_block_delimiters() -> &'static [(TokenKind, TokenKind)] { - &[ - (TokenKind::OpenBrace, TokenKind::CloseBrace), - (TokenKind::OpenParen, TokenKind::CloseParen), - ] - } - /******************************************** * Parser Functions ********************************************/ @@ -241,8 +173,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn abi_coder_pragma(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ABICoderKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ABICoderKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }) .with_kind(RuleKind::ABICoderPragma) @@ -252,14 +190,23 @@ impl Language { fn address_type(&self, input: &mut ParserContext) -> ParserResult { ChoiceHelper::run(input, |mut choice, input| { let result = SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AddressKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AddressKeyword, + ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ), ))?; seq.finish() }); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -271,7 +218,10 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(ChoiceHelper::run(input, |mut choice, input| { let result = self.positional_arguments_list(input); @@ -280,16 +230,17 @@ impl Language { choice.consider(input, result)?; choice.finish(input) })) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }) .with_kind(RuleKind::ArgumentsDeclaration) @@ -300,19 +251,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBracket, + ))?; seq.elem( self.array_values_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBracket, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBracket, + ))?; seq.finish() }) .with_kind(RuleKind::ArrayExpression) @@ -320,11 +275,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn array_values_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.expression(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::ArrayValuesList) } @@ -332,18 +287,26 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn ascii_string_literals_list(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral) + self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ) }) .with_kind(RuleKind::AsciiStringLiteralsList) } #[allow(unused_assignments, unused_parens)] fn assembly_flags_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, - |input| self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral), - TokenKind::Comma, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ) + }, + TokenKind::Comma, ) .with_kind(RuleKind::AssemblyFlagsList) } @@ -351,28 +314,36 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn assembly_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AssemblyKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AssemblyKeyword, + ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral), + self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ), ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( self.assembly_flags_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() })))?; seq.elem(self.yul_block(input))?; @@ -386,19 +357,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.statements_list(input)) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBrace, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }) .with_kind(RuleKind::Block) @@ -408,17 +383,21 @@ impl Language { fn break_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::BreakKeyword) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), + self.parse_token_with_trivia::( + input, + TokenKind::BreakKeyword, + ) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::BreakStatement) @@ -428,7 +407,10 @@ impl Language { fn catch_clause(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CatchKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CatchKeyword, + ))?; seq.elem(OptionalHelper::transform(self.catch_clause_error(input)))?; seq.elem(self.block(input))?; seq.finish() @@ -444,7 +426,10 @@ impl Language { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.elem(self.parameters_declaration(input))?; seq.finish() @@ -472,26 +457,32 @@ impl Language { seq.elem( SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ConstantKeyword), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), - )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -508,14 +499,20 @@ impl Language { ChoiceHelper::run(input, |mut choice, input| { let result = self.modifier_invocation(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -533,9 +530,10 @@ impl Language { fn constructor_definition(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_4_22 { SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ConstructorKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ConstructorKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.constructor_attributes_list(input), @@ -553,17 +551,21 @@ impl Language { fn continue_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ContinueKeyword) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), + self.parse_token_with_trivia::( + input, + TokenKind::ContinueKeyword, + ) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::ContinueStatement) @@ -574,30 +576,41 @@ impl Language { SequenceHelper::run(|mut seq| { if self.version_is_at_least_0_6_0 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::AbstractKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::AbstractKeyword, + ), ))?; } - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ContractKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ContractKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(self.inheritance_specifier(input)))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.contract_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -661,25 +674,33 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( self.deconstruction_import_symbols_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBrace, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FromKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FromKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ))?; seq.finish() }) .with_kind(RuleKind::DeconstructionImport) @@ -688,10 +709,19 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn deconstruction_import_symbol(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() })))?; seq.finish() @@ -701,11 +731,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn deconstruction_import_symbols_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.deconstruction_import_symbol(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::DeconstructionImportSymbolsList) } @@ -715,22 +745,24 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::DeleteKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::DeleteKeyword, + ))?; seq.elem(self.expression(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::DeleteStatement) @@ -741,42 +773,50 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::DoKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::DoKeyword, + ))?; seq.elem(self.statement(input))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::WhileKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::WhileKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), - )?; seq.finish() }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::DoWhileStatement) @@ -788,23 +828,25 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::EmitKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EmitKeyword, + ))?; seq.elem(self.identifier_path(input))?; seq.elem(self.arguments_declaration(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -817,13 +859,19 @@ impl Language { fn end_of_file_trivia(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token(input, TokenKind::Whitespace); + let result = + self.parse_token::(input, TokenKind::Whitespace); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::EndOfLine); + let result = + self.parse_token::(input, TokenKind::EndOfLine); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::MultilineComment); + let result = self + .parse_token::(input, TokenKind::MultilineComment); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::SingleLineComment); + let result = self.parse_token::( + input, + TokenKind::SingleLineComment, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -834,26 +882,34 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn enum_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::EnumKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EnumKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.identifiers_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -863,60 +919,7 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn error_definition(&self, input: &mut ParserContext) -> ParserResult { - if self.version_is_at_least_0_8_4 { - SequenceHelper::run(|mut seq| { - seq.elem( - SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ErrorKeyword), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), - )?; - seq.elem(SequenceHelper::run(|mut seq| { - let mut delim_guard = input.open_delim(TokenKind::CloseParen); - let input = delim_guard.ctx(); - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), - )?; - seq.elem( - OptionalHelper::transform(self.error_parameters_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), - )?; - seq.finish() - }))?; - seq.finish() - }) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), - )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; - seq.finish() - }) - } else { - ParserResult::disabled() - } - .with_kind(RuleKind::ErrorDefinition) + if self . version_is_at_least_0_8_4 { SequenceHelper :: run (| mut seq | { seq . elem (SequenceHelper :: run (| mut seq | { seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: ErrorKeyword)) ? ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: Identifier)) ? ; seq . elem (SequenceHelper :: run (| mut seq | { let mut delim_guard = input . open_delim (TokenKind :: CloseParen) ; let input = delim_guard . ctx () ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: OpenParen)) ? ; seq . elem (OptionalHelper :: transform (self . error_parameters_list (input)) . recover_until_with_nested_delims :: < _ , LexicalContextType :: Default > (input , self , TokenKind :: CloseParen , RecoverFromNoMatch :: Yes ,)) ? ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: CloseParen)) ? ; seq . finish () })) ? ; seq . finish () }) . recover_until_with_nested_delims :: < _ , LexicalContextType :: Default > (input , self , TokenKind :: Semicolon , RecoverFromNoMatch :: No ,)) ? ; seq . elem (self . parse_token_with_trivia :: < LexicalContextType :: Default > (input , TokenKind :: Semicolon)) ? ; seq . finish () }) } else { ParserResult :: disabled () } . with_kind (RuleKind :: ErrorDefinition) } #[allow(unused_assignments, unused_parens)] @@ -925,7 +928,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.finish() }) @@ -938,11 +944,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn error_parameters_list(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_8_4 { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.error_parameter(input), TokenKind::Comma, - self, ) } else { ParserResult::disabled() @@ -955,49 +961,55 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::EventKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EventKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.event_parameters_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::AnonymousKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::AnonymousKeyword, + ), ))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::EventDefinition) @@ -1008,10 +1020,16 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::IndexedKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::IndexedKeyword, + ), ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.finish() }) @@ -1020,11 +1038,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn event_parameters_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.event_parameter(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::EventParametersList) } @@ -1032,12 +1050,20 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn experimental_pragma(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ExperimentalKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ExperimentalKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; choice.finish(input) }))?; @@ -1054,36 +1080,62 @@ impl Language { 1u8, 1u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Equal); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::BarEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BarEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PlusEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PlusEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::MinusEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinusEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::CaretEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::CaretEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::SlashEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SlashEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PercentEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PercentEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::AsteriskEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AsteriskEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::AmpersandEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AmpersandEqual, + ); choice.consider(input, result)?; - let result = self - .default_parse_token_with_trivia(input, TokenKind::LessThanLessThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanLessThanEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanEqual, ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanGreaterThanEqual, ); @@ -1097,9 +1149,15 @@ impl Language { RuleKind::ConditionalExpression, 3u8, SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::QuestionMark))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::QuestionMark, + ))?; seq.elem(self.expression(input))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Colon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Colon, + ))?; seq.elem(self.expression(input))?; seq.finish() }), @@ -1110,7 +1168,10 @@ impl Language { RuleKind::BinaryExpression, 5u8, 5u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::BarBar), + self.parse_token_with_trivia::( + input, + TokenKind::BarBar, + ), ) }; let parse_and_operator = |input: &mut ParserContext| { @@ -1118,7 +1179,10 @@ impl Language { RuleKind::BinaryExpression, 7u8, 7u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::AmpersandAmpersand), + self.parse_token_with_trivia::( + input, + TokenKind::AmpersandAmpersand, + ), ) }; let parse_equality_comparison_operator = |input: &mut ParserContext| { @@ -1127,9 +1191,15 @@ impl Language { 9u8, 9u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::EqualEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::EqualEqual, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::BangEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BangEqual, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1141,16 +1211,25 @@ impl Language { 11u8, 11u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::LessThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThan, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::GreaterThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThan, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::LessThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::GreaterThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThanEqual, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1161,7 +1240,7 @@ impl Language { RuleKind::BinaryExpression, 13u8, 13u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::Bar), + self.parse_token_with_trivia::(input, TokenKind::Bar), ) }; let parse_bitwise_x_or_operator = |input: &mut ParserContext| { @@ -1169,7 +1248,10 @@ impl Language { RuleKind::BinaryExpression, 15u8, 15u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::Caret), + self.parse_token_with_trivia::( + input, + TokenKind::Caret, + ), ) }; let parse_bitwise_and_operator = |input: &mut ParserContext| { @@ -1177,7 +1259,10 @@ impl Language { RuleKind::BinaryExpression, 17u8, 17u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::Ampersand), + self.parse_token_with_trivia::( + input, + TokenKind::Ampersand, + ), ) }; let parse_shift_operator = |input: &mut ParserContext| { @@ -1186,13 +1271,17 @@ impl Language { 19u8, 19u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::LessThanLessThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanLessThan, + ); choice.consider(input, result)?; - let result = self - .default_parse_token_with_trivia(input, TokenKind::GreaterThanGreaterThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThanGreaterThan, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::GreaterThanGreaterThanGreaterThan, ); @@ -1207,9 +1296,15 @@ impl Language { 21u8, 21u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Plus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Plus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Minus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Minus, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1221,11 +1316,20 @@ impl Language { 23u8, 23u8 + 1, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Asterisk); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Slash); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Slash, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Percent); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Percent, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1236,7 +1340,10 @@ impl Language { RuleKind::BinaryExpression, 25u8, 25u8 + 1, - self.default_parse_token_with_trivia(input, TokenKind::AsteriskAsterisk), + self.parse_token_with_trivia::( + input, + TokenKind::AsteriskAsterisk, + ), ) }; let parse_exponentiation_operator_introduced_from_0_6_0 = |input: &mut ParserContext| { @@ -1244,7 +1351,10 @@ impl Language { RuleKind::BinaryExpression, 27u8 + 1, 27u8, - self.default_parse_token_with_trivia(input, TokenKind::AsteriskAsterisk), + self.parse_token_with_trivia::( + input, + TokenKind::AsteriskAsterisk, + ), ) }; let parse_unary_postfix_operator = |input: &mut ParserContext| { @@ -1252,9 +1362,15 @@ impl Language { RuleKind::UnaryPostfixExpression, 29u8, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::PlusPlus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PlusPlus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::MinusMinus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinusMinus, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -1265,18 +1381,36 @@ impl Language { RuleKind::UnaryPrefixExpression, 31u8, ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::PlusPlus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PlusPlus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::MinusMinus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinusMinus, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Tilde); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Tilde, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Bang); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Bang, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Minus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Minus, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { - let result = self.default_parse_token_with_trivia(input, TokenKind::Plus); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Plus, + ); choice.consider(input, result)?; } choice.finish(input) @@ -1301,13 +1435,20 @@ impl Language { RuleKind::MemberAccessExpression, 35u8, SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Period))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Period, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::AddressKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AddressKeyword, + ); choice.consider(input, result)?; choice.finish(input) }))?; @@ -1322,31 +1463,36 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBracket, + ))?; seq.elem( SequenceHelper::run(|mut seq| { seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Colon), + self.parse_token_with_trivia::( + input, + TokenKind::Colon, + ), )?; seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.finish() })))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBracket, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBracket, + ))?; seq.finish() }), ) @@ -1367,11 +1513,15 @@ impl Language { let result = self.array_expression(input); choice.consider(input, result)?; let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::TrueKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::TrueKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FalseKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FalseKeyword, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -1391,38 +1541,57 @@ impl Language { }); choice.consider(input, result)?; let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StringKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_3 { let result = self.type_expression(input); @@ -1516,15 +1685,19 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn expression_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem( + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; seq.finish() }) .with_kind(RuleKind::ExpressionStatement) @@ -1540,20 +1713,30 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -1571,14 +1754,20 @@ impl Language { fn fallback_function_definition(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FallbackKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FallbackKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.fallback_function_attributes_list(input), ))?; seq.elem(OptionalHelper::transform(self.returns_declaration(input)))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -1595,11 +1784,17 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn for_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ForKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ForKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { @@ -1613,32 +1808,39 @@ impl Language { choice.finish(input) }); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; choice.finish(input) }))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.expression_statement(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; choice.finish(input) }))?; seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; seq.elem(self.statement(input))?; @@ -1655,30 +1857,53 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PrivateKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ConstantKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ); choice.consider(input, result)?; } if self.version_is_at_least_0_6_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -1707,14 +1932,25 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn function_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Identifier); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FallbackKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FallbackKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::ReceiveKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ReceiveKeyword, + ); choice.consider(input, result)?; choice.finish(input) }))?; @@ -1724,7 +1960,10 @@ impl Language { ))?; seq.elem(OptionalHelper::transform(self.returns_declaration(input)))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -1738,7 +1977,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn function_type(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.function_type_attributes_list(input), @@ -1753,21 +1995,40 @@ impl Language { fn function_type_attributes_list(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PrivateKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -1778,40 +2039,53 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn hex_string_literals_list(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.default_parse_token_with_trivia(input, TokenKind::HexStringLiteral) + self.parse_token_with_trivia::( + input, + TokenKind::HexStringLiteral, + ) }) .with_kind(RuleKind::HexStringLiteralsList) } #[allow(unused_assignments, unused_parens)] fn identifier_path(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, - |input| self.default_parse_token_with_trivia(input, TokenKind::Identifier), - TokenKind::Period, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ) + }, + TokenKind::Period, ) .with_kind(RuleKind::IdentifierPath) } #[allow(unused_assignments, unused_parens)] fn identifier_paths_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.identifier_path(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::IdentifierPathsList) } #[allow(unused_assignments, unused_parens)] fn identifiers_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, - |input| self.default_parse_token_with_trivia(input, TokenKind::Identifier), - TokenKind::Comma, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ) + }, + TokenKind::Comma, ) .with_kind(RuleKind::IdentifiersList) } @@ -1819,25 +2093,38 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn if_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::IfKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::IfKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; + seq.elem( + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }))?; seq.elem(self.statement(input))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ElseKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ElseKeyword, + ))?; seq.elem(self.statement(input))?; seq.finish() })))?; @@ -1851,9 +2138,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ImportKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ImportKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.path_import(input); choice.consider(input, result)?; @@ -1865,16 +2153,17 @@ impl Language { }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::ImportDirective) @@ -1883,7 +2172,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn inheritance_specifier(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::IsKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::IsKeyword, + ))?; seq.elem(self.inheritance_types_list(input))?; seq.finish() }) @@ -1902,11 +2194,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn inheritance_types_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.inheritance_type(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::InheritanceTypesList) } @@ -1914,27 +2206,35 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn interface_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::InterfaceKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::InterfaceKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(self.inheritance_specifier(input)))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.interface_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -1996,13 +2296,19 @@ impl Language { fn leading_trivia(&self, input: &mut ParserContext) -> ParserResult { OneOrMoreHelper::run(input, |input| { ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token(input, TokenKind::Whitespace); + let result = + self.parse_token::(input, TokenKind::Whitespace); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::EndOfLine); + let result = + self.parse_token::(input, TokenKind::EndOfLine); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::MultilineComment); + let result = self + .parse_token::(input, TokenKind::MultilineComment); choice.consider(input, result)?; - let result = self.default_parse_token(input, TokenKind::SingleLineComment); + let result = self.parse_token::( + input, + TokenKind::SingleLineComment, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -2013,26 +2319,34 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn library_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::LibraryKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::LibraryKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.library_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -2095,32 +2409,48 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StringKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -2132,7 +2462,10 @@ impl Language { }))?; if self.version_is_at_least_0_8_18 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; } seq.finish() @@ -2143,33 +2476,38 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn mapping_type(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::MappingKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::MappingKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( SequenceHelper::run(|mut seq| { seq.elem(self.mapping_key_type(input))?; - seq.elem( - self.default_parse_token_with_trivia( - input, - TokenKind::EqualGreaterThan, - ), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::EqualGreaterThan, + ))?; seq.elem(self.mapping_value_type(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; seq.finish() @@ -2183,7 +2521,10 @@ impl Language { seq.elem(self.type_name(input))?; if self.version_is_at_least_0_8_18 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; } seq.finish() @@ -2198,8 +2539,10 @@ impl Language { let result = self.override_specifier(input); choice.consider(input, result)?; if self.version_is_at_least_0_6_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -2211,8 +2554,14 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn modifier_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ModifierKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ModifierKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform( self.parameters_declaration(input), ))?; @@ -2220,7 +2569,10 @@ impl Language { self.modifier_attributes_list(input), ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -2244,8 +2596,16 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_argument(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Colon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::Colon, + ), + )?; seq.elem(self.expression(input))?; seq.finish() }) @@ -2257,19 +2617,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.named_arguments_list(input)) - .recover_until_with_nested_delims( - input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }) .with_kind(RuleKind::NamedArgumentsDeclaration) @@ -2277,11 +2641,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_arguments_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.named_argument(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::NamedArgumentsList) } @@ -2289,11 +2653,26 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn named_import(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Asterisk))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FromKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FromKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ))?; seq.finish() }) .with_kind(RuleKind::NamedImport) @@ -2302,7 +2681,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn new_expression(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::NewKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::NewKeyword, + ))?; seq.elem(self.type_name(input))?; seq.finish() }) @@ -2313,55 +2695,85 @@ impl Language { fn numeric_expression(&self, input: &mut ParserContext) -> ParserResult { ChoiceHelper::run(input, |mut choice, input| { let result = SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::HexLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::HexLiteral, + ))?; if !self.version_is_at_least_0_5_0 { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::DaysKeyword); - choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::EtherKeyword); + .parse_token_with_trivia::( + input, + TokenKind::DaysKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::HoursKeyword); + .parse_token_with_trivia::( + input, + TokenKind::EtherKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::MinutesKeyword); + .parse_token_with_trivia::( + input, + TokenKind::HoursKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::SecondsKeyword); + .parse_token_with_trivia::( + input, + TokenKind::MinutesKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::WeeksKeyword); + .parse_token_with_trivia::( + input, + TokenKind::SecondsKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::WeiKeyword); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::WeeksKeyword, + ); choice.consider(input, result)?; - if !self.version_is_at_least_0_5_0 { - let result = self.default_parse_token_with_trivia( + let result = self + .parse_token_with_trivia::( input, - TokenKind::YearsKeyword, + TokenKind::WeiKeyword, ); + choice.consider(input, result)?; + if !self.version_is_at_least_0_5_0 { + let result = self + .parse_token_with_trivia::( + input, + TokenKind::YearsKeyword, + ); choice.consider(input, result)?; } if self.version_is_at_least_0_6_11 { let result = self - .default_parse_token_with_trivia(input, TokenKind::GweiKeyword); + .parse_token_with_trivia::( + input, + TokenKind::GweiKeyword, + ); choice.consider(input, result)?; } if !self.version_is_at_least_0_7_0 { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia( - input, - TokenKind::FinneyKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::FinneyKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::SzaboKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::SzaboKeyword, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -2375,52 +2787,77 @@ impl Language { }); choice.consider(input, result)?; let result = SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::DecimalLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::DecimalLiteral, + ))?; seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::DaysKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::DaysKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::EtherKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::EtherKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::HoursKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::HoursKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::MinutesKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MinutesKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SecondsKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SecondsKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::WeeksKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::WeeksKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::WeiKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::WeiKeyword, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_5_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::YearsKeyword); + .parse_token_with_trivia::( + input, + TokenKind::YearsKeyword, + ); choice.consider(input, result)?; } if self.version_is_at_least_0_6_11 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::GweiKeyword); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::GweiKeyword, + ); choice.consider(input, result)?; } if !self.version_is_at_least_0_7_0 { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia( - input, - TokenKind::FinneyKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::FinneyKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::SzaboKeyword, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::SzaboKeyword, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -2440,25 +2877,30 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn override_specifier(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OverrideKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OverrideKeyword, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.identifier_paths_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() })))?; seq.finish() @@ -2473,22 +2915,31 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), + self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ), ))?; seq.finish() }) @@ -2500,19 +2951,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.parameters_list(input)) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }) .with_kind(RuleKind::ParametersDeclaration) @@ -2520,11 +2975,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn parameters_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.parameter(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::ParametersList) } @@ -2532,10 +2987,19 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn path_import(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() })))?; seq.finish() @@ -2545,11 +3009,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn positional_arguments_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.expression(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::PositionalArgumentsList) } @@ -2559,9 +3023,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::PragmaKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::PragmaKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.abi_coder_pragma(input); choice.consider(input, result)?; @@ -2573,16 +3038,17 @@ impl Language { }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::PragmaDirective) @@ -2598,14 +3064,20 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::VirtualKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VirtualKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -2623,13 +3095,19 @@ impl Language { fn receive_function_definition(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ReceiveKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ReceiveKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.receive_function_attributes_list(input), ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -2648,22 +3126,24 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ReturnKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ReturnKeyword, + ))?; seq.elem(OptionalHelper::transform(self.expression(input)))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::ReturnStatement) @@ -2672,7 +3152,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn returns_declaration(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ReturnsKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ReturnsKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.finish() }) @@ -2684,23 +3167,25 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::RevertKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::RevertKeyword, + ))?; seq.elem(OptionalHelper::transform(self.identifier_path(input)))?; seq.elem(self.arguments_declaration(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::RevertStatement) @@ -2774,19 +3259,31 @@ impl Language { ChoiceHelper::run(input, |mut choice, input| { let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ConstantKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ConstantKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::InternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::InternalKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PrivateKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PrivateKeyword, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia(input, TokenKind::PublicKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PublicKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_6_5 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ImmutableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ImmutableKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -2804,24 +3301,31 @@ impl Language { seq.elem(OptionalHelper::transform( self.state_variable_attributes_list(input), ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() })))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::StateVariableDefinition) @@ -2898,26 +3402,34 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn struct_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::StructKeyword))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::StructKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( OptionalHelper::transform(self.struct_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }))?; seq.finish() @@ -2931,19 +3443,23 @@ impl Language { seq.elem( SequenceHelper::run(|mut seq| { seq.elem(self.type_name(input))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::StructMember) @@ -2960,19 +3476,21 @@ impl Language { if !self.version_is_at_least_0_5_0 { SequenceHelper::run(|mut seq| { seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::ThrowKeyword) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::Semicolon, - Self::default_delimiters(), - RecoverFromNoMatch::No, - ), + self.parse_token_with_trivia::( + input, + TokenKind::ThrowKeyword, + ) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::Semicolon, + RecoverFromNoMatch::No, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -2985,12 +3503,15 @@ impl Language { fn trailing_trivia(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem(OptionalHelper::transform( - self.default_parse_token(input, TokenKind::Whitespace), + self.parse_token::(input, TokenKind::Whitespace), ))?; seq.elem(OptionalHelper::transform( - self.default_parse_token(input, TokenKind::SingleLineComment), + self.parse_token::( + input, + TokenKind::SingleLineComment, + ), ))?; - seq.elem(self.default_parse_token(input, TokenKind::EndOfLine))?; + seq.elem(self.parse_token::(input, TokenKind::EndOfLine))?; seq.finish() }) .with_kind(RuleKind::TrailingTrivia) @@ -3000,7 +3521,10 @@ impl Language { fn try_statement(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::TryKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::TryKeyword, + ))?; seq.elem(self.expression(input))?; seq.elem(OptionalHelper::transform(self.returns_declaration(input)))?; seq.elem(self.block(input))?; @@ -3021,43 +3545,43 @@ impl Language { seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::OpenParen), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( OptionalHelper::transform(self.tuple_members_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::CloseParen), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::TupleDeconstructionStatement) @@ -3068,19 +3592,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; seq.elem( self.tuple_values_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseParen, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ))?; seq.finish() }) .with_kind(RuleKind::TupleExpression) @@ -3094,21 +3622,31 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + .parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }); choice.consider(input, result)?; @@ -3116,21 +3654,31 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + .parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }); choice.consider(input, result)?; @@ -3141,22 +3689,22 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn tuple_members_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.tuple_member(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::TupleMembersList) } #[allow(unused_assignments, unused_parens)] fn tuple_values_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| OptionalHelper::transform(self.expression(input)), TokenKind::Comma, - self, ) .with_kind(RuleKind::TupleValuesList) } @@ -3165,20 +3713,30 @@ impl Language { fn type_expression(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_5_3 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::TypeKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::TypeKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; - seq.elem(self.type_name(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; + seq.elem( + self.type_name(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }))?; seq.finish() @@ -3198,23 +3756,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBracket); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBracket, + ))?; seq.elem( OptionalHelper::transform(self.expression(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::Default as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBracket, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseBracket, + RecoverFromNoMatch::Yes, + ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBracket))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBracket, + ))?; seq.finish() }), ) @@ -3226,32 +3784,48 @@ impl Language { let result = self.mapping_type(input); choice.consider(input, result)?; let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StringKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedIntegerType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::UnsignedFixedType); + let result = self.parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) @@ -3289,7 +3863,10 @@ impl Language { fn unchecked_block(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_8_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::UncheckedKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::UncheckedKeyword, + ))?; seq.elem(self.block(input))?; seq.finish() }) @@ -3303,7 +3880,10 @@ impl Language { fn unicode_string_literals_list(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_7_0 { OneOrMoreHelper::run(input, |input| { - self.default_parse_token_with_trivia(input, TokenKind::UnicodeStringLiteral) + self.parse_token_with_trivia::( + input, + TokenKind::UnicodeStringLiteral, + ) }) } else { ParserResult::disabled() @@ -3321,17 +3901,25 @@ impl Language { choice.consider(input, result)?; let result = self.override_specifier(input); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ExternalKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ExternalKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PayableKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PayableKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::PureKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::PureKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::ViewKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::ViewKeyword, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -3349,13 +3937,19 @@ impl Language { fn unnamed_function_definition(&self, input: &mut ParserContext) -> ParserResult { if !self.version_is_at_least_0_6_0 { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ))?; seq.elem(self.parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.unnamed_function_attributes_list(input), ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = self.default_parse_token_with_trivia(input, TokenKind::Semicolon); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ); choice.consider(input, result)?; let result = self.block(input); choice.consider(input, result)?; @@ -3375,64 +3969,86 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::TypeKeyword), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::Identifier), - )?; - seq.elem( - self.default_parse_token_with_trivia(input, TokenKind::IsKeyword), - )?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::TypeKeyword, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::IsKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::BoolKeyword); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::BoolKeyword, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::StringKeyword); + .parse_token_with_trivia::( + input, + TokenKind::StringKeyword, + ); choice.consider(input, result)?; let result = self.address_type(input); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::FixedBytesType); + .parse_token_with_trivia::( + input, + TokenKind::FixedBytesType, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::SignedIntegerType, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::SignedIntegerType, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::UnsignedIntegerType, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::UnsignedIntegerType, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::SignedFixedType); + .parse_token_with_trivia::( + input, + TokenKind::SignedFixedType, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::UnsignedFixedType, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::UnsignedFixedType, + ); choice.consider(input, result)?; if !self.version_is_at_least_0_8_0 { let result = self - .default_parse_token_with_trivia(input, TokenKind::ByteKeyword); + .parse_token_with_trivia::( + input, + TokenKind::ByteKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) } else { @@ -3446,7 +4062,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem( SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::UsingKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::UsingKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { let result = self.using_directive_path(input); choice.consider(input, result)?; @@ -3454,10 +4073,15 @@ impl Language { choice.consider(input, result)?; choice.finish(input) }))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::ForKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::ForKeyword, + ))?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::Asterisk); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ); choice.consider(input, result)?; let result = self.type_name(input); choice.consider(input, result)?; @@ -3465,21 +4089,25 @@ impl Language { }))?; if self.version_is_at_least_0_8_13 { seq.elem(OptionalHelper::transform( - self.default_parse_token_with_trivia(input, TokenKind::GlobalKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::GlobalKeyword, + ), ))?; } seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::UsingDirective) @@ -3490,19 +4118,23 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ))?; seq.elem( self.using_directive_symbols_list(input) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::CloseBrace, - Self::default_delimiters(), RecoverFromNoMatch::Yes, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseBrace))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ))?; seq.finish() }) .with_kind(RuleKind::UsingDirectiveDeconstruction) @@ -3520,55 +4152,101 @@ impl Language { seq.elem(self.identifier_path(input))?; if self.version_is_at_least_0_8_19 { seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::AsKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::AsKeyword, + ))?; seq.elem(if self.version_is_at_least_0_8_19 { ChoiceHelper::run(input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::Ampersand); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Ampersand, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Asterisk); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Asterisk, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::BangEqual); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::BangEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Bar); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Bar, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Caret); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Caret, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::EqualEqual); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::EqualEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::GreaterThan); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::GreaterThan, + ); choice.consider(input, result)?; - let result = self.default_parse_token_with_trivia( - input, - TokenKind::GreaterThanEqual, - ); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::GreaterThanEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::LessThan); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::LessThan, + ); choice.consider(input, result)?; let result = self - .default_parse_token_with_trivia(input, TokenKind::LessThanEqual); + .parse_token_with_trivia::( + input, + TokenKind::LessThanEqual, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Minus); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Minus, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Percent); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Percent, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Plus); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Plus, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Slash); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Slash, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::Tilde); + let result = self + .parse_token_with_trivia::( + input, + TokenKind::Tilde, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -3585,11 +4263,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn using_directive_symbols_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::Default as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::Default>( input, + self, |input| self.using_directive_symbol(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::UsingDirectiveSymbolsList) } @@ -3599,7 +4277,10 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { if !self.version_is_at_least_0_5_0 { - let result = self.default_parse_token_with_trivia(input, TokenKind::VarKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::VarKeyword, + ); choice.consider(input, result)?; } let result = self.type_name(input); @@ -3609,21 +4290,30 @@ impl Language { seq.elem(OptionalHelper::transform(ChoiceHelper::run( input, |mut choice, input| { - let result = - self.default_parse_token_with_trivia(input, TokenKind::MemoryKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::MemoryKeyword, + ); choice.consider(input, result)?; - let result = - self.default_parse_token_with_trivia(input, TokenKind::StorageKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::StorageKeyword, + ); choice.consider(input, result)?; if self.version_is_at_least_0_5_0 { - let result = - self.default_parse_token_with_trivia(input, TokenKind::CalldataKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::CalldataKeyword, + ); choice.consider(input, result)?; } choice.finish(input) }, )))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Identifier))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Identifier, + ))?; seq.finish() }) .with_kind(RuleKind::VariableDeclaration) @@ -3636,22 +4326,26 @@ impl Language { SequenceHelper::run(|mut seq| { seq.elem(self.variable_declaration(input))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Equal))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ))?; seq.elem(self.expression(input))?; seq.finish() })))?; seq.finish() }) - .recover_until_with_nested_delims( + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), + self, TokenKind::Semicolon, - Self::default_delimiters(), RecoverFromNoMatch::No, ), )?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::Semicolon))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::Semicolon, + ))?; seq.finish() }) .with_kind(RuleKind::VariableDeclarationStatement) @@ -3661,7 +4355,10 @@ impl Language { fn version_pragma(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem( - self.version_pragma_parse_token_with_trivia(input, TokenKind::SolidityKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::SolidityKeyword, + ), )?; seq.elem(self.version_pragma_expressions_list(input))?; seq.finish() @@ -3676,7 +4373,10 @@ impl Language { RuleKind::VersionPragmaBinaryExpression, 1u8, 1u8 + 1, - self.version_pragma_parse_token_with_trivia(input, TokenKind::BarBar), + self.parse_token_with_trivia::( + input, + TokenKind::BarBar, + ), ) }; let parse_version_pragma_range_operator = |input: &mut ParserContext| { @@ -3684,7 +4384,10 @@ impl Language { RuleKind::VersionPragmaBinaryExpression, 3u8, 3u8 + 1, - self.version_pragma_parse_token_with_trivia(input, TokenKind::Minus), + self.parse_token_with_trivia::( + input, + TokenKind::Minus, + ), ) }; let parse_version_pragma_unary_operator = |input: &mut ParserContext| { @@ -3692,26 +4395,40 @@ impl Language { RuleKind::VersionPragmaUnaryExpression, 5u8, ChoiceHelper::run(input, |mut choice, input| { - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::Caret); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Caret, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::Tilde); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Tilde, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::Equal); + let result = self.parse_token_with_trivia::( + input, + TokenKind::Equal, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::LessThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThan, + ); choice.consider(input, result)?; - let result = - self.version_pragma_parse_token_with_trivia(input, TokenKind::GreaterThan); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThan, + ); choice.consider(input, result)?; - let result = self - .version_pragma_parse_token_with_trivia(input, TokenKind::LessThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::LessThanEqual, + ); choice.consider(input, result)?; - let result = self - .version_pragma_parse_token_with_trivia(input, TokenKind::GreaterThanEqual); + let result = self.parse_token_with_trivia::( + input, + TokenKind::GreaterThanEqual, + ); choice.consider(input, result)?; choice.finish(input) }), @@ -3772,13 +4489,16 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn version_pragma_specifier(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::VersionPragma as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::VersionPragma>( input, + self, |input| { - self.version_pragma_parse_token_with_trivia(input, TokenKind::VersionPragmaValue) + self.parse_token_with_trivia::( + input, + TokenKind::VersionPragmaValue, + ) }, TokenKind::Period, - self, ) .with_kind(RuleKind::VersionPragmaSpecifier) } @@ -3786,20 +4506,30 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn while_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::WhileKeyword))?; + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::WhileKeyword, + ))?; seq.elem(SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::OpenParen))?; - seq.elem(self.expression(input).recover_until_with_nested_delims( + seq.elem(self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ))?; + seq.elem( + self.expression(input) + .recover_until_with_nested_delims::<_, LexicalContextType::Default>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem(self.parse_token_with_trivia::( input, - |input| Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, input), - |input| Lexer::leading_trivia(self, input), TokenKind::CloseParen, - Self::default_delimiters(), - RecoverFromNoMatch::Yes, ))?; - seq.elem(self.default_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }))?; seq.elem(self.statement(input))?; @@ -3812,7 +4542,12 @@ impl Language { fn yul_assignment_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem(self.yul_identifier_paths_list(input))?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::ColonEqual))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::ColonEqual, + ), + )?; seq.elem(self.yul_expression(input))?; seq.finish() }) @@ -3824,21 +4559,27 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseBrace); let input = delim_guard.ctx(); - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::OpenBrace))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::OpenBrace, + ), + )?; seq.elem( OptionalHelper::transform(self.yul_statements_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseBrace, - Self::yul_block_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::YulBlock>( + input, + self, + TokenKind::CloseBrace, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::CloseBrace, + ), )?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::CloseBrace))?; seq.finish() }) .with_kind(RuleKind::YulBlock) @@ -3846,23 +4587,36 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_break_statement(&self, input: &mut ParserContext) -> ParserResult { - self.yul_block_parse_token_with_trivia(input, TokenKind::BreakKeyword) + self.parse_token_with_trivia::(input, TokenKind::BreakKeyword) .with_kind(RuleKind::YulBreakStatement) } #[allow(unused_assignments, unused_parens)] fn yul_continue_statement(&self, input: &mut ParserContext) -> ParserResult { - self.yul_block_parse_token_with_trivia(input, TokenKind::ContinueKeyword) - .with_kind(RuleKind::YulContinueStatement) + self.parse_token_with_trivia::( + input, + TokenKind::ContinueKeyword, + ) + .with_kind(RuleKind::YulContinueStatement) } #[allow(unused_assignments, unused_parens)] fn yul_declaration_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::LetKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::LetKeyword, + ), + )?; seq.elem(self.yul_identifier_paths_list(input))?; seq.elem(OptionalHelper::transform(SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::ColonEqual))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::ColonEqual, + ), + )?; seq.elem(self.yul_expression(input))?; seq.finish() })))?; @@ -3880,23 +4634,27 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ), + )?; seq.elem( OptionalHelper::transform(self.yul_expressions_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>( - self, input, - ) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::yul_block_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::YulBlock>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ), )?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }), ) @@ -3904,23 +4662,35 @@ impl Language { let primary_expression_parser = |input: &mut ParserContext| { ChoiceHelper::run(input, |mut choice, input| { let result = ChoiceHelper::run(input, |mut choice, input| { - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::TrueKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::TrueKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::FalseKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FalseKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::YulHexLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulHexLiteral, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::YulDecimalLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulDecimalLiteral, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::HexStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::HexStringLiteral, + ); choice.consider(input, result)?; - let result = self - .yul_block_parse_token_with_trivia(input, TokenKind::AsciiStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::AsciiStringLiteral, + ); choice.consider(input, result)?; choice.finish(input) }); @@ -3955,11 +4725,11 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_expressions_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, + self, |input| self.yul_expression(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::YulExpressionsList) } @@ -3967,7 +4737,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_for_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::ForKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::ForKeyword, + ), + )?; seq.elem(self.yul_block(input))?; seq.elem(self.yul_expression(input))?; seq.elem(self.yul_block(input))?; @@ -3980,8 +4755,18 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_function_definition(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::FunctionKeyword))?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::YulIdentifier))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::FunctionKeyword, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::YulIdentifier, + ), + )?; seq.elem(self.yul_parameters_declaration(input))?; seq.elem(OptionalHelper::transform( self.yul_returns_declaration(input), @@ -3994,33 +4779,43 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_identifier_path(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, - |input| self.yul_block_parse_token_with_trivia(input, TokenKind::YulIdentifier), - TokenKind::Period, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::YulIdentifier, + ) + }, + TokenKind::Period, ) .with_kind(RuleKind::YulIdentifierPath) } #[allow(unused_assignments, unused_parens)] fn yul_identifier_paths_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, + self, |input| self.yul_identifier_path(input), TokenKind::Comma, - self, ) .with_kind(RuleKind::YulIdentifierPathsList) } #[allow(unused_assignments, unused_parens)] fn yul_identifiers_list(&self, input: &mut ParserContext) -> ParserResult { - SeparatedHelper::run::<{ LexicalContext::YulBlock as u8 }, Self>( + SeparatedHelper::run::<_, LexicalContextType::YulBlock>( input, - |input| self.yul_block_parse_token_with_trivia(input, TokenKind::YulIdentifier), - TokenKind::Comma, self, + |input| { + self.parse_token_with_trivia::( + input, + TokenKind::YulIdentifier, + ) + }, + TokenKind::Comma, ) .with_kind(RuleKind::YulIdentifiersList) } @@ -4028,7 +4823,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_if_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::IfKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::IfKeyword, + ), + )?; seq.elem(self.yul_expression(input))?; seq.elem(self.yul_block(input))?; seq.finish() @@ -4039,7 +4839,10 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_leave_statement(&self, input: &mut ParserContext) -> ParserResult { if self.version_is_at_least_0_6_0 { - self.yul_block_parse_token_with_trivia(input, TokenKind::LeaveKeyword) + self.parse_token_with_trivia::( + input, + TokenKind::LeaveKeyword, + ) } else { ParserResult::disabled() } @@ -4051,21 +4854,27 @@ impl Language { SequenceHelper::run(|mut seq| { let mut delim_guard = input.open_delim(TokenKind::CloseParen); let input = delim_guard.ctx(); - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::OpenParen))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::OpenParen, + ), + )?; seq.elem( OptionalHelper::transform(self.yul_identifiers_list(input)) - .recover_until_with_nested_delims( - input, - |input| { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>(self, input) - }, - |input| Lexer::leading_trivia(self, input), - TokenKind::CloseParen, - Self::yul_block_delimiters(), - RecoverFromNoMatch::Yes, - ), + .recover_until_with_nested_delims::<_, LexicalContextType::YulBlock>( + input, + self, + TokenKind::CloseParen, + RecoverFromNoMatch::Yes, + ), + )?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::CloseParen, + ), )?; - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::CloseParen))?; seq.finish() }) .with_kind(RuleKind::YulParametersDeclaration) @@ -4074,7 +4883,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_returns_declaration(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::MinusGreaterThan))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::MinusGreaterThan, + ), + )?; seq.elem(self.yul_identifiers_list(input))?; seq.finish() }) @@ -4123,30 +4937,45 @@ impl Language { fn yul_switch_case(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::DefaultKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::DefaultKeyword, + ); choice.consider(input, result)?; let result = SequenceHelper::run(|mut seq| { seq.elem( - self.yul_block_parse_token_with_trivia(input, TokenKind::CaseKeyword), + self.parse_token_with_trivia::( + input, + TokenKind::CaseKeyword, + ), )?; seq.elem(ChoiceHelper::run(input, |mut choice, input| { - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::TrueKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::TrueKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::FalseKeyword); + let result = self.parse_token_with_trivia::( + input, + TokenKind::FalseKeyword, + ); choice.consider(input, result)?; - let result = - self.yul_block_parse_token_with_trivia(input, TokenKind::YulHexLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulHexLiteral, + ); choice.consider(input, result)?; - let result = self - .yul_block_parse_token_with_trivia(input, TokenKind::YulDecimalLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::YulDecimalLiteral, + ); choice.consider(input, result)?; - let result = self - .yul_block_parse_token_with_trivia(input, TokenKind::HexStringLiteral); + let result = self.parse_token_with_trivia::( + input, + TokenKind::HexStringLiteral, + ); choice.consider(input, result)?; - let result = self.yul_block_parse_token_with_trivia( + let result = self.parse_token_with_trivia::( input, TokenKind::AsciiStringLiteral, ); @@ -4173,7 +5002,12 @@ impl Language { #[allow(unused_assignments, unused_parens)] fn yul_switch_statement(&self, input: &mut ParserContext) -> ParserResult { SequenceHelper::run(|mut seq| { - seq.elem(self.yul_block_parse_token_with_trivia(input, TokenKind::SwitchKeyword))?; + seq.elem( + self.parse_token_with_trivia::( + input, + TokenKind::SwitchKeyword, + ), + )?; seq.elem(self.yul_expression(input))?; seq.elem(self.yul_switch_cases_list(input))?; seq.finish() @@ -4760,13 +5594,13 @@ impl Language { let mut input = ParserContext::new(input); match lexical_context { LexicalContext::Default => { - Lexer::next_token::<{ LexicalContext::Default as u8 }>(self, &mut input) + Lexer::next_token::(self, &mut input) } LexicalContext::VersionPragma => { - Lexer::next_token::<{ LexicalContext::VersionPragma as u8 }>(self, &mut input) + Lexer::next_token::(self, &mut input) } LexicalContext::YulBlock => { - Lexer::next_token::<{ LexicalContext::YulBlock as u8 }>(self, &mut input) + Lexer::next_token::(self, &mut input) } } } @@ -4997,20 +5831,27 @@ impl Lexer for Language { Language::trailing_trivia(self, input) } - fn delimiters() -> &'static [(TokenKind, TokenKind)] { - match LexicalContext::from_repr(LEX_CTX).unwrap() { - LexicalContext::Default => Self::default_delimiters(), - LexicalContext::VersionPragma => Self::version_pragma_delimiters(), - LexicalContext::YulBlock => Self::yul_block_delimiters(), + fn delimiters() -> &'static [(TokenKind, TokenKind)] { + match LexCtx::value() { + LexicalContext::Default => &[ + (TokenKind::OpenBrace, TokenKind::CloseBrace), + (TokenKind::OpenBracket, TokenKind::CloseBracket), + (TokenKind::OpenParen, TokenKind::CloseParen), + ], + LexicalContext::VersionPragma => &[], + LexicalContext::YulBlock => &[ + (TokenKind::OpenBrace, TokenKind::CloseBrace), + (TokenKind::OpenParen, TokenKind::CloseParen), + ], } } - fn next_token(&self, input: &mut ParserContext) -> Option { + fn next_token(&self, input: &mut ParserContext) -> Option { let save = input.position(); let mut furthest_position = input.position(); let mut longest_token = None; - match LexicalContext::from_repr(LEX_CTX).unwrap() { + match LexCtx::value() { LexicalContext::Default => { macro_rules! longest_match { ($( { $kind:ident = $function:ident } )*) => { diff --git a/crates/solidity/outputs/npm/crate/src/generated/lexer.rs b/crates/solidity/outputs/npm/crate/src/generated/lexer.rs index 0ee1eba42d..4661f4e2b7 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/lexer.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/lexer.rs @@ -2,42 +2,53 @@ use crate::{ cst, - kinds::{LexicalContext, TokenKind}, + kinds::{IsLexicalContext, TokenKind}, support::{ParserContext, ParserResult}, }; -// Ensure that the `LexicalContext` enum is `repr(u8)`. -// Workaround until repr(u8) enums can be used as const params. -const _ASSERT_CONTEXT_IS_REPR_U8: fn() = || { - let _ = core::mem::transmute::; -}; - pub trait Lexer { // Generated by the templating engine #[doc(hidden)] - fn next_token(&self, input: &mut ParserContext) -> Option; + fn next_token(&self, input: &mut ParserContext) -> Option; // NOTE: These are context-insensitive #[doc(hidden)] fn leading_trivia(&self, input: &mut ParserContext) -> ParserResult; #[doc(hidden)] fn trailing_trivia(&self, input: &mut ParserContext) -> ParserResult; #[doc(hidden)] - fn delimiters() -> &'static [(TokenKind, TokenKind)]; + /// Returns valid grouping delimiters in the given lexical context. + fn delimiters() -> &'static [(TokenKind, TokenKind)]; - fn peek_token(&self, input: &mut ParserContext) -> Option { + /// Peeks the next token, including trivia. Does not advance the input. + fn peek_token(&self, input: &mut ParserContext) -> Option { let start = input.position(); - let token = self.next_token::(input); + let token = self.next_token::(input); + input.set_position(start); + token + } + + /// Peeks the next significant (i.e. non-trivia) token. Does not advance the input. + fn peek_token_with_trivia( + &self, + input: &mut ParserContext, + ) -> Option { + let start = input.position(); + + let _ = self.leading_trivia(input); + let token = self.next_token::(input); + input.set_position(start); token } - fn parse_token( + /// Attempts to consume the next expected token. Advances the input only if the token matches. + fn parse_token( &self, input: &mut ParserContext, kind: TokenKind, ) -> ParserResult { let start = input.position(); - if self.next_token::(input) != Some(kind) { + if self.next_token::(input) != Some(kind) { input.set_position(start); return ParserResult::no_match(vec![kind]); } @@ -49,7 +60,9 @@ pub trait Lexer { ) } - fn parse_token_with_trivia( + /// Attempts to consume the next significant token including both leading and trailing trivia. + /// Advances the input only if the token matches. + fn parse_token_with_trivia( &self, input: &mut ParserContext, kind: TokenKind, @@ -64,7 +77,7 @@ pub trait Lexer { } let start = input.position(); - if self.next_token::(input) != Some(kind) { + if self.next_token::(input) != Some(kind) { input.set_position(restore); return ParserResult::no_match(vec![kind]); } diff --git a/crates/solidity/outputs/npm/crate/src/generated/support/recovery.rs b/crates/solidity/outputs/npm/crate/src/generated/support/recovery.rs index 8aec4fffd4..d6d3e1016b 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/support/recovery.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/support/recovery.rs @@ -1,7 +1,8 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use crate::cst; -use crate::kinds::TokenKind; +use crate::kinds::{IsLexicalContext, TokenKind}; +use crate::lexer::Lexer; use crate::parse_error::ParseError; use crate::support::ParserResult; use crate::text_index::{TextRange, TextRangeExtensions as _}; @@ -41,27 +42,15 @@ impl ParserResult { /// /// Respects nested delimiters, i.e. the `expected` token is only accepted if it's not nested inside. /// Does not consume the `expected` token. - pub fn recover_until_with_nested_delims( + pub fn recover_until_with_nested_delims( self, input: &mut ParserContext, - next_token: impl Fn(&mut ParserContext) -> Option, - leading_trivia: impl Fn(&mut ParserContext) -> ParserResult, + lexer: &L, expected: TokenKind, - delims: &[(TokenKind, TokenKind)], recover_from_no_match: RecoverFromNoMatch, ) -> ParserResult { let before_recovery = input.position(); - let mut peek_token_after_trivia = || { - let start = input.position(); - - opt_parse(input, &leading_trivia); - let token = next_token(input); - - input.set_position(start); - token - }; - enum ParseResultKind { Match, Incomplete, @@ -74,7 +63,9 @@ impl ParserResult { result.expected_tokens, ParseResultKind::Incomplete, ), - ParserResult::Match(result) if peek_token_after_trivia() != Some(expected) => { + ParserResult::Match(result) + if lexer.peek_token_with_trivia::(input) != Some(expected) => + { (result.nodes, result.expected_tokens, ParseResultKind::Match) } ParserResult::NoMatch(result) if recover_from_no_match.as_bool() => { @@ -84,9 +75,9 @@ impl ParserResult { _ => return self, }; - let leading_trivia = opt_parse(input, &leading_trivia); + let leading_trivia = opt_parse(input, |input| lexer.leading_trivia(input)); - match skip_until_with_nested_delims(input, next_token, expected, delims) { + match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, expected) { Some((found, skipped_range)) => { nodes.extend(leading_trivia); if matches!(result_kind, ParseResultKind::Match) { @@ -100,24 +91,24 @@ impl ParserResult { tokens_that_would_have_allowed_more_progress: expected_tokens.clone(), }); - return ParserResult::SkippedUntil(SkippedUntil { + ParserResult::SkippedUntil(SkippedUntil { nodes, expected, skipped, found, - }); + }) } // Not found till EOF, revert any recovery attempt None => { input.set_position(before_recovery); - return match result_kind { + match result_kind { ParseResultKind::Match => ParserResult::r#match(nodes, expected_tokens), ParseResultKind::Incomplete => { ParserResult::incomplete_match(nodes, expected_tokens) } ParseResultKind::NoMatch => ParserResult::no_match(expected_tokens), - }; + } } } } @@ -128,18 +119,19 @@ impl ParserResult { /// Does not consume the `expected` token. /// /// Returns the found token and the range of skipped tokens on success. -pub fn skip_until_with_nested_delims( +pub fn skip_until_with_nested_delims( input: &mut ParserContext, - next_token: impl Fn(&mut ParserContext) -> Option, + lexer: &L, until: TokenKind, - delims: &[(TokenKind, TokenKind)], ) -> Option<(TokenKind, TextRange)> { + let delims = L::delimiters::(); + let start = input.position(); let mut local_delims = vec![]; loop { let save = input.position(); - match next_token(input) { + match lexer.next_token::(input) { // If we're not skipping past a local delimited group (delimiter stack is empty), // we can unwind on a token that's expected by us or by our ancestor. Some(token) diff --git a/crates/solidity/outputs/npm/crate/src/generated/support/separated_helper.rs b/crates/solidity/outputs/npm/crate/src/generated/support/separated_helper.rs index dddf9def05..58721ac557 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/support/separated_helper.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/support/separated_helper.rs @@ -1,21 +1,26 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use crate::{ - cst, kinds::TokenKind, lexer::Lexer, parse_error::ParseError, text_index::TextRangeExtensions, -}; - -use super::{ - parser_result::IncompleteMatch, skip_until_with_nested_delims, ParserContext, ParserResult, + cst, + kinds::{IsLexicalContext, TokenKind}, + lexer::Lexer, + parse_error::ParseError, + support::{ + parser_result::{ParserResult, SkippedUntil}, + recovery::skip_until_with_nested_delims, + ParserContext, + }, + text_index::TextRangeExtensions, }; pub struct SeparatedHelper; impl SeparatedHelper { - pub fn run( + pub fn run( input: &mut ParserContext, + lexer: &L, body_parser: impl Fn(&mut ParserContext) -> ParserResult, separator: TokenKind, - lexer: &L, ) -> ParserResult { let mut accum = vec![]; loop { @@ -23,16 +28,9 @@ impl SeparatedHelper { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); - // Parse the leading trivia so that we can peek the next significant token - if let ParserResult::Match(r#match) = lexer.leading_trivia(input) { - accum.extend(r#match.nodes); - } - - match lexer.peek_token::(input) { + match lexer.peek_token_with_trivia::(input) { Some(token) if token == separator => { - let separator = - lexer.parse_token_with_trivia::(input, separator); - match separator { + match lexer.parse_token_with_trivia::(input, separator) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); continue; @@ -40,21 +38,12 @@ impl SeparatedHelper { _ => unreachable!("We just checked that the separator matches"), } } - // Heuristic: lists (separated-by) are often in a delimited group, so if we - // see a closing delimiter, we assume that we're done and don't recover. - Some(token) if input.closing_delimiters().contains(&token) => { - return ParserResult::r#match(accum, vec![separator]); - } - // Otherwise, we try to recover from unexpected tokens until we see a separator - Some(..) => { - // TODO: Attempt recovery: sometimes the list is not in a delimited group, - // so don't attempt to recover for now to not risk misparses - return ParserResult::r#match(accum, vec![separator]); - } - // EOF - None => { - return ParserResult::r#match(accum, vec![separator]); - } + + // Unrecognized, return the accumulated matches. + // NOTE: We can't correctly attempt recovery until #600 lands, otherwise we'd risk misparses, + // as we need to stop at certain synchronizing tokens (and we can't reliably scan until + // a delimiter, as not every list is enclosed in a delimited group). + Some(..) | None => return ParserResult::r#match(accum, vec![separator]), } } // Body was partially parsed, so try to recover by skipping tokens until we see a separator @@ -63,14 +52,7 @@ impl SeparatedHelper { let start = input.position(); - let skipped = skip_until_with_nested_delims( - input, - |input| lexer.next_token::(input), - separator, - ::delimiters::(), - ); - - match skipped { + match skip_until_with_nested_delims::<_, LexCtx>(input, lexer, separator) { // A separator was found, so we can recover the incomplete match Some((found, skipped_range)) if found == separator => { accum.push(cst::Node::token( @@ -83,7 +65,7 @@ impl SeparatedHelper { .expected_tokens, }); - match lexer.parse_token_with_trivia::(input, separator) { + match lexer.parse_token_with_trivia::(input, separator) { ParserResult::Match(r#match) => { accum.extend(r#match.nodes); continue; @@ -91,23 +73,17 @@ impl SeparatedHelper { _ => unreachable!("We just checked that the separator matches"), } } + // Didn't find a separator during recovery. It might've been the last of the // separatees, so we can't recover to not risk misparses. - Some(..) => { + Some(..) | None => { // Undo the recovery attempt input.set_position(start); - return ParserResult::IncompleteMatch(IncompleteMatch { - nodes: accum, - expected_tokens: incomplete.expected_tokens, - }); - } - // Separator wasn't found till EOF, so we can't recover - None => { - return ParserResult::IncompleteMatch(IncompleteMatch { - nodes: accum, - expected_tokens: incomplete.expected_tokens, - }); + return ParserResult::incomplete_match( + accum, + incomplete.expected_tokens, + ); } } } @@ -121,7 +97,8 @@ impl SeparatedHelper { ParserResult::SkippedUntil(skipped) => { accum.extend(skipped.nodes); - return ParserResult::SkippedUntil(super::parser_result::SkippedUntil { + + return ParserResult::SkippedUntil(SkippedUntil { nodes: accum, ..skipped }); diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.4.11-failure.yml index 126a86ff12..41b8661c2d 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.4.11-failure.yml @@ -90,7 +90,7 @@ Tree: - Statement (Rule): # 201..262 "\n (bool success, ) = recipient.call{ value: amo..." - TupleDeconstructionStatement (Rule): # 201..262 "\n (bool success, ) = recipient.call{ value: amo..." - OpenParen (Token): "(" # 206..207 - - TupleMembersList (Rule): # 207..221 "bool success, " + - TupleMembersList (Rule): # 207..220 "bool success," - TupleMember (Rule): # 207..219 "bool success" - TypeName (Rule): # 207..211 "bool" - BoolKeyword (Token): "bool" # 207..211 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.6.2-success.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.6.2-success.yml index dbdd6618f1..042b47fad3 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.6.2-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/function_multiple_delimiters/generated/0.6.2-success.yml @@ -82,7 +82,7 @@ Tree: - Statement (Rule): # 201..262 "\n (bool success, ) = recipient.call{ value: amo..." - TupleDeconstructionStatement (Rule): # 201..262 "\n (bool success, ) = recipient.call{ value: amo..." - OpenParen (Token): "(" # 206..207 - - TupleMembersList (Rule): # 207..221 "bool success, " + - TupleMembersList (Rule): # 207..220 "bool success," - TupleMember (Rule): # 207..219 "bool success" - TypeName (Rule): # 207..211 "bool" - BoolKeyword (Token): "bool" # 207..211 @@ -102,7 +102,7 @@ Tree: - FunctionCallOptions (Rule): # 239..256 "{ value: amount }" - NamedArgumentsDeclaration (Rule): # 239..256 "{ value: amount }" - OpenBrace (Token): "{" # 239..240 - - NamedArgumentsList (Rule): # 240..255 " value: amount " + - NamedArgumentsList (Rule): # 240..254 " value: amount" - NamedArgument (Rule): # 240..254 " value: amount" - Identifier (Token): "value" # 241..246 - Colon (Token): ":" # 246..247 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/inheritence_specifier/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/inheritence_specifier/generated/0.4.11-success.yml index 46a213597b..c52bf5eaa5 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/inheritence_specifier/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/inheritence_specifier/generated/0.4.11-success.yml @@ -9,9 +9,9 @@ Tree: - ContractDefinition (Rule): # 0..41 "contract Sample is Foo, Bar(1, 2), Baz {}" - ContractKeyword (Token): "contract" # 0..8 - Identifier (Token): "Sample" # 9..15 - - InheritanceSpecifier (Rule): # 15..39 " is Foo, Bar(1, 2), Baz " + - InheritanceSpecifier (Rule): # 15..38 " is Foo, Bar(1, 2), Baz" - IsKeyword (Token): "is" # 16..18 - - InheritanceTypesList (Rule): # 18..39 " Foo, Bar(1, 2), Baz " + - InheritanceTypesList (Rule): # 18..38 " Foo, Bar(1, 2), Baz" - InheritanceType (Rule): # 18..22 " Foo" - IdentifierPath (Rule): # 18..22 " Foo" - Identifier (Token): "Foo" # 19..22 @@ -31,8 +31,8 @@ Tree: - DecimalLiteral (Token): "2" # 31..32 - CloseParen (Token): ")" # 32..33 - Comma (Token): "," # 33..34 - - InheritanceType (Rule): # 34..39 " Baz " - - IdentifierPath (Rule): # 34..39 " Baz " + - InheritanceType (Rule): # 34..38 " Baz" + - IdentifierPath (Rule): # 34..38 " Baz" - Identifier (Token): "Baz" # 35..38 - OpenBrace (Token): "{" # 39..40 - CloseBrace (Token): "}" # 40..41 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_enum_definition/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_enum_definition/generated/0.4.11-success.yml index 75cb603aa0..5f7e784e79 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_enum_definition/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_enum_definition/generated/0.4.11-success.yml @@ -21,7 +21,7 @@ Tree: - EnumKeyword (Token): "enum" # 20..24 - Identifier (Token): "State" # 25..30 - OpenBrace (Token): "{" # 31..32 - - IdentifiersList (Rule): # 33..55 " A,\n B,\n C\n " + - IdentifiersList (Rule): # 33..53 " A,\n B,\n C\n" - Identifier (Token): "A" # 37..38 - Comma (Token): "," # 38..39 - Identifier (Token): "B" # 44..45 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_error_definition/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_error_definition/generated/0.4.11-failure.yml index 5570e9a2b6..545b4d7d83 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_error_definition/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_error_definition/generated/0.4.11-failure.yml @@ -22,8 +22,8 @@ Tree: - OpenBrace (Token): "{" # 16..17 - ContractMembersList (Rule): # 18..36 " error Error1();\n" - StateVariableDefinition (Rule): # 18..36 " error Error1();\n" - - TypeName (Rule): # 18..26 " error " - - IdentifierPath (Rule): # 18..26 " error " + - TypeName (Rule): # 18..25 " error" + - IdentifierPath (Rule): # 18..25 " error" - Identifier (Token): "error" # 20..25 - Identifier (Token): "Error1" # 26..32 - SKIPPED (Token): "()" # 32..34 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_using_directive/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_using_directive/generated/0.4.11-success.yml index adf0dd7617..157803ac80 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_using_directive/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/member_using_directive/generated/0.4.11-success.yml @@ -15,8 +15,8 @@ Tree: - ContractMembersList (Rule): # 18..35 " using x for *;\n" - UsingDirective (Rule): # 18..35 " using x for *;\n" - UsingKeyword (Token): "using" # 20..25 - - UsingDirectivePath (Rule): # 25..28 " x " - - IdentifierPath (Rule): # 25..28 " x " + - UsingDirectivePath (Rule): # 25..27 " x" + - IdentifierPath (Rule): # 25..27 " x" - Identifier (Token): "x" # 26..27 - ForKeyword (Token): "for" # 28..31 - Asterisk (Token): "*" # 32..33 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.4.11-failure.yml index 94e739ffbd..853d48d94a 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.4.11-failure.yml @@ -52,7 +52,7 @@ Tree: - Identifier (Token): "_transfer" # 30..39 - ParametersDeclaration (Rule): # 39..54 "(address while)" - OpenParen (Token): "(" # 39..40 - - ParametersList (Rule): # 40..48 "address " + - ParametersList (Rule): # 40..47 "address" - Parameter (Rule): # 40..47 "address" - TypeName (Rule): # 40..47 "address" - AddressType (Rule): # 40..47 "address" diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.5.3-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.5.3-failure.yml index 4a7a4061dd..7d913010da 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.5.3-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.5.3-failure.yml @@ -52,7 +52,7 @@ Tree: - Identifier (Token): "_transfer" # 30..39 - ParametersDeclaration (Rule): # 39..54 "(address while)" - OpenParen (Token): "(" # 39..40 - - ParametersList (Rule): # 40..48 "address " + - ParametersList (Rule): # 40..47 "address" - Parameter (Rule): # 40..47 "address" - TypeName (Rule): # 40..47 "address" - AddressType (Rule): # 40..47 "address" diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.6.2-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.6.2-failure.yml index aec50412cd..5857647b99 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.6.2-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.6.2-failure.yml @@ -59,7 +59,7 @@ Tree: - Identifier (Token): "_transfer" # 30..39 - ParametersDeclaration (Rule): # 39..54 "(address while)" - OpenParen (Token): "(" # 39..40 - - ParametersList (Rule): # 40..48 "address " + - ParametersList (Rule): # 40..47 "address" - Parameter (Rule): # 40..47 "address" - TypeName (Rule): # 40..47 "address" - AddressType (Rule): # 40..47 "address" diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.7.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.7.0-failure.yml index d477102c06..177cc0e0ff 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.7.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.7.0-failure.yml @@ -59,7 +59,7 @@ Tree: - Identifier (Token): "_transfer" # 30..39 - ParametersDeclaration (Rule): # 39..54 "(address while)" - OpenParen (Token): "(" # 39..40 - - ParametersList (Rule): # 40..48 "address " + - ParametersList (Rule): # 40..47 "address" - Parameter (Rule): # 40..47 "address" - TypeName (Rule): # 40..47 "address" - AddressType (Rule): # 40..47 "address" diff --git a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.8.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.8.0-failure.yml index b00a39aa93..3267d38264 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.8.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractDefinition/recovery_testbed/generated/0.8.0-failure.yml @@ -51,7 +51,7 @@ Tree: - Identifier (Token): "_transfer" # 30..39 - ParametersDeclaration (Rule): # 39..54 "(address while)" - OpenParen (Token): "(" # 39..40 - - ParametersList (Rule): # 40..48 "address " + - ParametersList (Rule): # 40..47 "address" - Parameter (Rule): # 40..47 "address" - TypeName (Rule): # 40..47 "address" - AddressType (Rule): # 40..47 "address" @@ -115,8 +115,8 @@ Tree: - Statement (Rule): # 187..205 " invalid sequence " - VariableDeclarationStatement (Rule): # 187..205 " invalid sequence " - VariableDeclaration (Rule): # 187..204 " invalid sequence" - - TypeName (Rule): # 187..196 " invalid " - - IdentifierPath (Rule): # 187..196 " invalid " + - TypeName (Rule): # 187..195 " invalid" + - IdentifierPath (Rule): # 187..195 " invalid" - Identifier (Token): "invalid" # 188..195 - Identifier (Token): "sequence" # 196..204 - SKIPPED (Token): "" # 205..205 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.4.11-failure.yml index efb895405d..88fef61f5c 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.4.11-failure.yml @@ -108,8 +108,8 @@ Tree: - OverrideSpecifier (Rule): # 14..76 " override(some.ident unexpected tokens, ISomeInter..." - OverrideKeyword (Token): "override" # 15..23 - OpenParen (Token): "(" # 23..24 - - IdentifierPathsList (Rule): # 24..35 "some.ident " - - IdentifierPath (Rule): # 24..35 "some.ident " + - IdentifierPathsList (Rule): # 24..34 "some.ident" + - IdentifierPath (Rule): # 24..34 "some.ident" - Identifier (Token): "some" # 24..28 - Period (Token): "." # 28..29 - Identifier (Token): "ident" # 29..34 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.6.2-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.6.2-failure.yml index 1846ff20a1..e739e6c311 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.6.2-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.6.2-failure.yml @@ -124,8 +124,8 @@ Tree: - OverrideSpecifier (Rule): # 14..76 " override(some.ident unexpected tokens, ISomeInter..." - OverrideKeyword (Token): "override" # 15..23 - OpenParen (Token): "(" # 23..24 - - IdentifierPathsList (Rule): # 24..35 "some.ident " - - IdentifierPath (Rule): # 24..35 "some.ident " + - IdentifierPathsList (Rule): # 24..34 "some.ident" + - IdentifierPath (Rule): # 24..34 "some.ident" - Identifier (Token): "some" # 24..28 - Period (Token): "." # 28..29 - Identifier (Token): "ident" # 29..34 @@ -238,7 +238,7 @@ Tree: - FunctionCallOptions (Rule): # 247..302 "{arg: 1 unexpected tokens, not: 2, recovered, yet:..." - NamedArgumentsDeclaration (Rule): # 247..302 "{arg: 1 unexpected tokens, not: 2, recovered, yet:..." - OpenBrace (Token): "{" # 247..248 - - NamedArgumentsList (Rule): # 248..255 "arg: 1 " + - NamedArgumentsList (Rule): # 248..254 "arg: 1" - NamedArgument (Rule): # 248..254 "arg: 1" - Identifier (Token): "arg" # 248..251 - Colon (Token): ":" # 251..252 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.7.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.7.0-failure.yml index fa0edcd3ed..6dc05f3059 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.7.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.7.0-failure.yml @@ -124,8 +124,8 @@ Tree: - OverrideSpecifier (Rule): # 14..76 " override(some.ident unexpected tokens, ISomeInter..." - OverrideKeyword (Token): "override" # 15..23 - OpenParen (Token): "(" # 23..24 - - IdentifierPathsList (Rule): # 24..35 "some.ident " - - IdentifierPath (Rule): # 24..35 "some.ident " + - IdentifierPathsList (Rule): # 24..34 "some.ident" + - IdentifierPath (Rule): # 24..34 "some.ident" - Identifier (Token): "some" # 24..28 - Period (Token): "." # 28..29 - Identifier (Token): "ident" # 29..34 @@ -238,7 +238,7 @@ Tree: - FunctionCallOptions (Rule): # 247..302 "{arg: 1 unexpected tokens, not: 2, recovered, yet:..." - NamedArgumentsDeclaration (Rule): # 247..302 "{arg: 1 unexpected tokens, not: 2, recovered, yet:..." - OpenBrace (Token): "{" # 247..248 - - NamedArgumentsList (Rule): # 248..255 "arg: 1 " + - NamedArgumentsList (Rule): # 248..254 "arg: 1" - NamedArgument (Rule): # 248..254 "arg: 1" - Identifier (Token): "arg" # 248..251 - Colon (Token): ":" # 251..252 diff --git a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.8.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.8.0-failure.yml index e302312b95..564c9af893 100644 --- a/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.8.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/ContractMembersList/separated_recovery/generated/0.8.0-failure.yml @@ -124,8 +124,8 @@ Tree: - OverrideSpecifier (Rule): # 14..76 " override(some.ident unexpected tokens, ISomeInter..." - OverrideKeyword (Token): "override" # 15..23 - OpenParen (Token): "(" # 23..24 - - IdentifierPathsList (Rule): # 24..35 "some.ident " - - IdentifierPath (Rule): # 24..35 "some.ident " + - IdentifierPathsList (Rule): # 24..34 "some.ident" + - IdentifierPath (Rule): # 24..34 "some.ident" - Identifier (Token): "some" # 24..28 - Period (Token): "." # 28..29 - Identifier (Token): "ident" # 29..34 @@ -238,7 +238,7 @@ Tree: - FunctionCallOptions (Rule): # 247..302 "{arg: 1 unexpected tokens, not: 2, recovered, yet:..." - NamedArgumentsDeclaration (Rule): # 247..302 "{arg: 1 unexpected tokens, not: 2, recovered, yet:..." - OpenBrace (Token): "{" # 247..248 - - NamedArgumentsList (Rule): # 248..255 "arg: 1 " + - NamedArgumentsList (Rule): # 248..254 "arg: 1" - NamedArgument (Rule): # 248..254 "arg: 1" - Identifier (Token): "arg" # 248..251 - Colon (Token): ":" # 251..252 diff --git a/crates/solidity/testing/snapshots/cst_output/EventDefinition/transfer/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/EventDefinition/transfer/generated/0.4.11-failure.yml index a9434b00cf..589149e0e6 100644 --- a/crates/solidity/testing/snapshots/cst_output/EventDefinition/transfer/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/EventDefinition/transfer/generated/0.4.11-failure.yml @@ -18,7 +18,7 @@ Tree: - EventKeyword (Token): "event" # 0..5 - Identifier (Token): "Transfer" # 6..14 - OpenParen (Token): "(" # 14..15 - - EventParametersList (Rule): # 15..31 "address indexed " + - EventParametersList (Rule): # 15..30 "address indexed" - EventParameter (Rule): # 15..30 "address indexed" - TypeName (Rule): # 15..22 "address" - AddressType (Rule): # 15..22 "address" diff --git a/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/from_contextual_keyword/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/from_contextual_keyword/generated/0.4.11-failure.yml index 810148f69f..842c29c973 100644 --- a/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/from_contextual_keyword/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/FunctionDefinition/from_contextual_keyword/generated/0.4.11-failure.yml @@ -19,7 +19,7 @@ Tree: - Identifier (Token): "transferFrom" # 9..21 - ParametersDeclaration (Rule): # 21..63 "(address from, address to, uint256 amount)" - OpenParen (Token): "(" # 21..22 - - ParametersList (Rule): # 22..30 "address " + - ParametersList (Rule): # 22..29 "address" - Parameter (Rule): # 22..29 "address" - TypeName (Rule): # 22..29 "address" - AddressType (Rule): # 22..29 "address" diff --git a/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_multiple/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_multiple/generated/0.4.11-success.yml index 9df6123ff0..f954111db8 100644 --- a/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_multiple/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_multiple/generated/0.4.11-success.yml @@ -10,7 +10,7 @@ Tree: - ImportKeyword (Token): "import" # 0..6 - DeconstructionImport (Rule): # 6..44 ' { A1 as A2, B1, C1 as C2 } from "foo"' - OpenBrace (Token): "{" # 7..8 - - DeconstructionImportSymbolsList (Rule): # 8..32 " A1 as A2, B1, C1 as C2 " + - DeconstructionImportSymbolsList (Rule): # 8..31 " A1 as A2, B1, C1 as C2" - DeconstructionImportSymbol (Rule): # 8..17 " A1 as A2" - Identifier (Token): "A1" # 9..11 - AsKeyword (Token): "as" # 12..14 diff --git a/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_single/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_single/generated/0.4.11-success.yml index 41a372fc6c..d62862b618 100644 --- a/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_single/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/ImportDirective/destructure_import_single/generated/0.4.11-success.yml @@ -10,7 +10,7 @@ Tree: - ImportKeyword (Token): "import" # 0..6 - DeconstructionImport (Rule): # 6..28 ' { x as y } from "foo"' - OpenBrace (Token): "{" # 7..8 - - DeconstructionImportSymbolsList (Rule): # 8..16 " x as y " + - DeconstructionImportSymbolsList (Rule): # 8..15 " x as y" - DeconstructionImportSymbol (Rule): # 8..15 " x as y" - Identifier (Token): "x" # 9..10 - AsKeyword (Token): "as" # 11..13 diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-success.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-success.yml index 4fa974eb7c..c73ee5b8fd 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-success.yml @@ -50,8 +50,8 @@ Tree: - Semicolon (Token): ";" # 40..41 - UsingDirective (Rule): # 42..58 "\nusing A for B;\n" - UsingKeyword (Token): "using" # 43..48 - - UsingDirectivePath (Rule): # 48..51 " A " - - IdentifierPath (Rule): # 48..51 " A " + - UsingDirectivePath (Rule): # 48..50 " A" + - IdentifierPath (Rule): # 48..50 " A" - Identifier (Token): "A" # 49..50 - ForKeyword (Token): "for" # 51..54 - TypeName (Rule): # 54..56 " B" diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml index fa7fa1493d..29a05d2130 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml @@ -50,23 +50,23 @@ Tree: - Semicolon (Token): ";" # 54..55 - UsingDirective (Rule): # 56..98 "\nusing EnvelopeUtils for Envelope global;\n" - UsingKeyword (Token): "using" # 57..62 - - UsingDirectivePath (Rule): # 62..77 " EnvelopeUtils " - - IdentifierPath (Rule): # 62..77 " EnvelopeUtils " + - UsingDirectivePath (Rule): # 62..76 " EnvelopeUtils" + - IdentifierPath (Rule): # 62..76 " EnvelopeUtils" - Identifier (Token): "EnvelopeUtils" # 63..76 - ForKeyword (Token): "for" # 77..80 - - TypeName (Rule): # 80..90 " Envelope " - - IdentifierPath (Rule): # 80..90 " Envelope " + - TypeName (Rule): # 80..89 " Envelope" + - IdentifierPath (Rule): # 80..89 " Envelope" - Identifier (Token): "Envelope" # 81..89 - GlobalKeyword (Token): "global" # 90..96 - Semicolon (Token): ";" # 96..97 - UsingDirective (Rule): # 98..145 "using TransactionUtils for Transaction global;\n" - UsingKeyword (Token): "using" # 98..103 - - UsingDirectivePath (Rule): # 103..121 " TransactionUtils " - - IdentifierPath (Rule): # 103..121 " TransactionUtils " + - UsingDirectivePath (Rule): # 103..120 " TransactionUtils" + - IdentifierPath (Rule): # 103..120 " TransactionUtils" - Identifier (Token): "TransactionUtils" # 104..120 - ForKeyword (Token): "for" # 121..124 - - TypeName (Rule): # 124..137 " Transaction " - - IdentifierPath (Rule): # 124..137 " Transaction " + - TypeName (Rule): # 124..136 " Transaction" + - IdentifierPath (Rule): # 124..136 " Transaction" - Identifier (Token): "Transaction" # 125..136 - GlobalKeyword (Token): "global" # 137..143 - Semicolon (Token): ";" # 143..144 @@ -105,8 +105,8 @@ Tree: - Identifier (Token): "destinationChainId" # 754..772 - Semicolon (Token): ";" # 772..773 - StructMember (Rule): # 774..791 " bytes message;\n" - - TypeName (Rule): # 774..782 " bytes " - - IdentifierPath (Rule): # 774..782 " bytes " + - TypeName (Rule): # 774..781 " bytes" + - IdentifierPath (Rule): # 774..781 " bytes" - Identifier (Token): "bytes" # 776..781 - Identifier (Token): "message" # 782..789 - Semicolon (Token): ";" # 789..790 diff --git a/crates/solidity/testing/snapshots/cst_output/Statement/try_catch/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/Statement/try_catch/generated/0.4.11-failure.yml index d55a39459a..4d73618872 100644 --- a/crates/solidity/testing/snapshots/cst_output/Statement/try_catch/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/Statement/try_catch/generated/0.4.11-failure.yml @@ -17,8 +17,8 @@ Tree: - Statement (Rule): # 0..21 "try a.b() {} catch {}" - VariableDeclarationStatement (Rule): # 0..5 "try a" - VariableDeclaration (Rule): # 0..5 "try a" - - TypeName (Rule): # 0..4 "try " - - IdentifierPath (Rule): # 0..4 "try " + - TypeName (Rule): # 0..3 "try" + - IdentifierPath (Rule): # 0..3 "try" - Identifier (Token): "try" # 0..3 - Identifier (Token): "a" # 4..5 - SKIPPED (Token): ".b() {} catch {}" # 5..21 diff --git a/crates/solidity/testing/snapshots/cst_output/TupleExpression/empty/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/TupleExpression/empty/generated/0.4.11-success.yml index 07639b22da..a03a765449 100644 --- a/crates/solidity/testing/snapshots/cst_output/TupleExpression/empty/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/TupleExpression/empty/generated/0.4.11-success.yml @@ -8,5 +8,5 @@ Errors: [] Tree: - TupleExpression (Rule): # 0..3 "( )" - OpenParen (Token): "(" # 0..1 - - TupleValuesList (Rule): " " # 1..2 + - TupleValuesList (Rule): [] # 1..1 - CloseParen (Token): ")" # 2..3 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.4.11-failure.yml index 9b718773c8..83b7c99b99 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.4.11-failure.yml @@ -26,15 +26,15 @@ Tree: - UsingKeyword (Token): "using" # 0..5 - UsingDirectiveDeconstruction (Rule): # 5..36 " {add as +, sub, mul, div as /}" - OpenBrace (Token): "{" # 6..7 - - UsingDirectiveSymbolsList (Rule): # 7..11 "add " - - UsingDirectiveSymbol (Rule): # 7..11 "add " - - IdentifierPath (Rule): # 7..11 "add " + - UsingDirectiveSymbolsList (Rule): # 7..10 "add" + - UsingDirectiveSymbol (Rule): # 7..10 "add" + - IdentifierPath (Rule): # 7..10 "add" - Identifier (Token): "add" # 7..10 - SKIPPED (Token): "as +, sub, mul, div as /" # 11..35 - CloseBrace (Token): "}" # 35..36 - ForKeyword (Token): "for" # 37..40 - - TypeName (Rule): # 40..45 " Int " - - IdentifierPath (Rule): # 40..45 " Int " + - TypeName (Rule): # 40..44 " Int" + - IdentifierPath (Rule): # 40..44 " Int" - Identifier (Token): "Int" # 41..44 - SKIPPED (Token): "global" # 45..51 - Semicolon (Token): ";" # 51..52 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.13-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.13-failure.yml index 3d9df08874..ce5ecd3db2 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.13-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.13-failure.yml @@ -18,15 +18,15 @@ Tree: - UsingKeyword (Token): "using" # 0..5 - UsingDirectiveDeconstruction (Rule): # 5..36 " {add as +, sub, mul, div as /}" - OpenBrace (Token): "{" # 6..7 - - UsingDirectiveSymbolsList (Rule): # 7..11 "add " - - UsingDirectiveSymbol (Rule): # 7..11 "add " - - IdentifierPath (Rule): # 7..11 "add " + - UsingDirectiveSymbolsList (Rule): # 7..10 "add" + - UsingDirectiveSymbol (Rule): # 7..10 "add" + - IdentifierPath (Rule): # 7..10 "add" - Identifier (Token): "add" # 7..10 - SKIPPED (Token): "as +, sub, mul, div as /" # 11..35 - CloseBrace (Token): "}" # 35..36 - ForKeyword (Token): "for" # 37..40 - - TypeName (Rule): # 40..45 " Int " - - IdentifierPath (Rule): # 40..45 " Int " + - TypeName (Rule): # 40..44 " Int" + - IdentifierPath (Rule): # 40..44 " Int" - Identifier (Token): "Int" # 41..44 - GlobalKeyword (Token): "global" # 45..51 - Semicolon (Token): ";" # 51..52 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.19-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.19-success.yml index 5521525136..d0a2f4dcdc 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.19-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_multiple/generated/0.8.19-success.yml @@ -12,7 +12,7 @@ Tree: - OpenBrace (Token): "{" # 6..7 - UsingDirectiveSymbolsList (Rule): # 7..35 "add as +, sub, mul, div as /" - UsingDirectiveSymbol (Rule): # 7..15 "add as +" - - IdentifierPath (Rule): # 7..11 "add " + - IdentifierPath (Rule): # 7..10 "add" - Identifier (Token): "add" # 7..10 - AsKeyword (Token): "as" # 11..13 - Plus (Token): "+" # 14..15 @@ -26,14 +26,14 @@ Tree: - Identifier (Token): "mul" # 22..25 - Comma (Token): "," # 25..26 - UsingDirectiveSymbol (Rule): # 26..35 " div as /" - - IdentifierPath (Rule): # 26..31 " div " + - IdentifierPath (Rule): # 26..30 " div" - Identifier (Token): "div" # 27..30 - AsKeyword (Token): "as" # 31..33 - Slash (Token): "/" # 34..35 - CloseBrace (Token): "}" # 35..36 - ForKeyword (Token): "for" # 37..40 - - TypeName (Rule): # 40..45 " Int " - - IdentifierPath (Rule): # 40..45 " Int " + - TypeName (Rule): # 40..44 " Int" + - IdentifierPath (Rule): # 40..44 " Int" - Identifier (Token): "Int" # 41..44 - GlobalKeyword (Token): "global" # 45..51 - Semicolon (Token): ";" # 51..52 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.4.11-failure.yml index abaf1c630b..125e8d1e4d 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.4.11-failure.yml @@ -24,8 +24,8 @@ Tree: - Identifier (Token): "add" # 7..10 - CloseBrace (Token): "}" # 10..11 - ForKeyword (Token): "for" # 12..15 - - TypeName (Rule): # 15..20 " Int " - - IdentifierPath (Rule): # 15..20 " Int " + - TypeName (Rule): # 15..19 " Int" + - IdentifierPath (Rule): # 15..19 " Int" - Identifier (Token): "Int" # 16..19 - SKIPPED (Token): "global" # 20..26 - Semicolon (Token): ";" # 26..27 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.8.13-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.8.13-success.yml index ba1e832caa..c56e4f7774 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.8.13-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/destructure_single/generated/0.8.13-success.yml @@ -16,8 +16,8 @@ Tree: - Identifier (Token): "add" # 7..10 - CloseBrace (Token): "}" # 10..11 - ForKeyword (Token): "for" # 12..15 - - TypeName (Rule): # 15..20 " Int " - - IdentifierPath (Rule): # 15..20 " Int " + - TypeName (Rule): # 15..19 " Int" + - IdentifierPath (Rule): # 15..19 " Int" - Identifier (Token): "Int" # 16..19 - GlobalKeyword (Token): "global" # 20..26 - Semicolon (Token): ";" # 26..27 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.4.11-failure.yml index 3b169c591e..d4a79bcd2d 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.4.11-failure.yml @@ -16,12 +16,12 @@ Errors: # 1 total Tree: - UsingDirective (Rule): # 0..25 "using foo for bar global;" - UsingKeyword (Token): "using" # 0..5 - - UsingDirectivePath (Rule): # 5..10 " foo " - - IdentifierPath (Rule): # 5..10 " foo " + - UsingDirectivePath (Rule): # 5..9 " foo" + - IdentifierPath (Rule): # 5..9 " foo" - Identifier (Token): "foo" # 6..9 - ForKeyword (Token): "for" # 10..13 - - TypeName (Rule): # 13..18 " bar " - - IdentifierPath (Rule): # 13..18 " bar " + - TypeName (Rule): # 13..17 " bar" + - IdentifierPath (Rule): # 13..17 " bar" - Identifier (Token): "bar" # 14..17 - SKIPPED (Token): "global" # 18..24 - Semicolon (Token): ";" # 24..25 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.8.13-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.8.13-success.yml index c2f7c9f5f2..2bfac291a4 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.8.13-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_named/generated/0.8.13-success.yml @@ -8,12 +8,12 @@ Errors: [] Tree: - UsingDirective (Rule): # 0..25 "using foo for bar global;" - UsingKeyword (Token): "using" # 0..5 - - UsingDirectivePath (Rule): # 5..10 " foo " - - IdentifierPath (Rule): # 5..10 " foo " + - UsingDirectivePath (Rule): # 5..9 " foo" + - IdentifierPath (Rule): # 5..9 " foo" - Identifier (Token): "foo" # 6..9 - ForKeyword (Token): "for" # 10..13 - - TypeName (Rule): # 13..18 " bar " - - IdentifierPath (Rule): # 13..18 " bar " + - TypeName (Rule): # 13..17 " bar" + - IdentifierPath (Rule): # 13..17 " bar" - Identifier (Token): "bar" # 14..17 - GlobalKeyword (Token): "global" # 18..24 - Semicolon (Token): ";" # 24..25 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_unnamed/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_unnamed/generated/0.4.11-success.yml index 02f1886669..c94ba36a51 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_unnamed/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/path_unnamed/generated/0.4.11-success.yml @@ -8,8 +8,8 @@ Errors: [] Tree: - UsingDirective (Rule): # 0..16 "using foo for *;" - UsingKeyword (Token): "using" # 0..5 - - UsingDirectivePath (Rule): # 5..10 " foo " - - IdentifierPath (Rule): # 5..10 " foo " + - UsingDirectivePath (Rule): # 5..9 " foo" + - IdentifierPath (Rule): # 5..9 " foo" - Identifier (Token): "foo" # 6..9 - ForKeyword (Token): "for" # 10..13 - Asterisk (Token): "*" # 14..15 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.4.11-failure.yml index acfa11b001..9fb9e654a4 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.4.11-failure.yml @@ -26,15 +26,15 @@ Tree: - UsingKeyword (Token): "using" # 0..5 - UsingDirectiveDeconstruction (Rule): # 5..16 " {div as /}" - OpenBrace (Token): "{" # 6..7 - - UsingDirectiveSymbolsList (Rule): # 7..11 "div " - - UsingDirectiveSymbol (Rule): # 7..11 "div " - - IdentifierPath (Rule): # 7..11 "div " + - UsingDirectiveSymbolsList (Rule): # 7..10 "div" + - UsingDirectiveSymbol (Rule): # 7..10 "div" + - IdentifierPath (Rule): # 7..10 "div" - Identifier (Token): "div" # 7..10 - SKIPPED (Token): "as /" # 11..15 - CloseBrace (Token): "}" # 15..16 - ForKeyword (Token): "for" # 17..20 - - TypeName (Rule): # 20..25 " Int " - - IdentifierPath (Rule): # 20..25 " Int " + - TypeName (Rule): # 20..24 " Int" + - IdentifierPath (Rule): # 20..24 " Int" - Identifier (Token): "Int" # 21..24 - SKIPPED (Token): "global" # 25..31 - Semicolon (Token): ";" # 31..32 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.13-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.13-failure.yml index 424377d7e7..bc1b7ac2a0 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.13-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.13-failure.yml @@ -18,15 +18,15 @@ Tree: - UsingKeyword (Token): "using" # 0..5 - UsingDirectiveDeconstruction (Rule): # 5..16 " {div as /}" - OpenBrace (Token): "{" # 6..7 - - UsingDirectiveSymbolsList (Rule): # 7..11 "div " - - UsingDirectiveSymbol (Rule): # 7..11 "div " - - IdentifierPath (Rule): # 7..11 "div " + - UsingDirectiveSymbolsList (Rule): # 7..10 "div" + - UsingDirectiveSymbol (Rule): # 7..10 "div" + - IdentifierPath (Rule): # 7..10 "div" - Identifier (Token): "div" # 7..10 - SKIPPED (Token): "as /" # 11..15 - CloseBrace (Token): "}" # 15..16 - ForKeyword (Token): "for" # 17..20 - - TypeName (Rule): # 20..25 " Int " - - IdentifierPath (Rule): # 20..25 " Int " + - TypeName (Rule): # 20..24 " Int" + - IdentifierPath (Rule): # 20..24 " Int" - Identifier (Token): "Int" # 21..24 - GlobalKeyword (Token): "global" # 25..31 - Semicolon (Token): ";" # 31..32 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.19-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.19-success.yml index a8e55b3f92..3250979b5d 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.19-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirective/user_defined_operator/generated/0.8.19-success.yml @@ -12,14 +12,14 @@ Tree: - OpenBrace (Token): "{" # 6..7 - UsingDirectiveSymbolsList (Rule): # 7..15 "div as /" - UsingDirectiveSymbol (Rule): # 7..15 "div as /" - - IdentifierPath (Rule): # 7..11 "div " + - IdentifierPath (Rule): # 7..10 "div" - Identifier (Token): "div" # 7..10 - AsKeyword (Token): "as" # 11..13 - Slash (Token): "/" # 14..15 - CloseBrace (Token): "}" # 15..16 - ForKeyword (Token): "for" # 17..20 - - TypeName (Rule): # 20..25 " Int " - - IdentifierPath (Rule): # 20..25 " Int " + - TypeName (Rule): # 20..24 " Int" + - IdentifierPath (Rule): # 20..24 " Int" - Identifier (Token): "Int" # 21..24 - GlobalKeyword (Token): "global" # 25..31 - Semicolon (Token): ";" # 31..32 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.4.11-failure.yml index 6ccf9b050c..acafdfb3ec 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.4.11-failure.yml @@ -6,17 +6,17 @@ Source: > Errors: # 1 total - > Error: Expected Period. - ╭─[crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/input.sol:1:9] + ╭─[crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/input.sol:1:8] │ 1 │ foo.bar as / - │ ──┬─ - │ ╰─── Error occurred here. + │ ──┬── + │ ╰──── Error occurred here. ───╯ Tree: - UsingDirectiveSymbol (Rule): # 0..12 "foo.bar as /" - - IdentifierPath (Rule): # 0..8 "foo.bar " + - IdentifierPath (Rule): # 0..7 "foo.bar" - Identifier (Token): "foo" # 0..3 - Period (Token): "." # 3..4 - Identifier (Token): "bar" # 4..7 - - SKIPPED (Token): "as /" # 8..12 + - SKIPPED (Token): " as /" # 7..12 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.8.19-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.8.19-success.yml index b369790153..4b629a2288 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.8.19-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/identifier_path_as_operator/generated/0.8.19-success.yml @@ -7,7 +7,7 @@ Errors: [] Tree: - UsingDirectiveSymbol (Rule): # 0..12 "foo.bar as /" - - IdentifierPath (Rule): # 0..8 "foo.bar " + - IdentifierPath (Rule): # 0..7 "foo.bar" - Identifier (Token): "foo" # 0..3 - Period (Token): "." # 3..4 - Identifier (Token): "bar" # 4..7 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.4.11-failure.yml index 9531b78c15..8e056c58c5 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.4.11-failure.yml @@ -6,15 +6,15 @@ Source: > Errors: # 1 total - > Error: Expected Period. - ╭─[crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/input.sol:1:5] + ╭─[crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/input.sol:1:4] │ 1 │ foo as / - │ ──┬─ - │ ╰─── Error occurred here. + │ ──┬── + │ ╰──── Error occurred here. ───╯ Tree: - UsingDirectiveSymbol (Rule): # 0..8 "foo as /" - - IdentifierPath (Rule): # 0..4 "foo " + - IdentifierPath (Rule): # 0..3 "foo" - Identifier (Token): "foo" # 0..3 - - SKIPPED (Token): "as /" # 4..8 + - SKIPPED (Token): " as /" # 3..8 diff --git a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.8.19-success.yml b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.8.19-success.yml index 8b97289e59..1a7220e058 100644 --- a/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.8.19-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/UsingDirectiveSymbol/single_id_as_operator/generated/0.8.19-success.yml @@ -7,7 +7,7 @@ Errors: [] Tree: - UsingDirectiveSymbol (Rule): # 0..8 "foo as /" - - IdentifierPath (Rule): # 0..4 "foo " + - IdentifierPath (Rule): # 0..3 "foo" - Identifier (Token): "foo" # 0..3 - AsKeyword (Token): "as" # 4..6 - Slash (Token): "/" # 7..8 diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml index 98a61d64e4..df9669607c 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml @@ -11,18 +11,18 @@ Tree: - VersionPragmaExpressionsList (Rule): # 8..33 " 0.5.0 || 0.6.0 || ^0.7.0" - VersionPragmaExpression (Rule): # 8..33 " 0.5.0 || 0.6.0 || ^0.7.0" - VersionPragmaBinaryExpression (Rule): # 8..33 " 0.5.0 || 0.6.0 || ^0.7.0" - - VersionPragmaExpression (Rule): # 8..24 " 0.5.0 || 0.6.0 " - - VersionPragmaBinaryExpression (Rule): # 8..24 " 0.5.0 || 0.6.0 " - - VersionPragmaExpression (Rule): # 8..15 " 0.5.0 " - - VersionPragmaSpecifier (Rule): # 8..15 " 0.5.0 " + - VersionPragmaExpression (Rule): # 8..23 " 0.5.0 || 0.6.0" + - VersionPragmaBinaryExpression (Rule): # 8..23 " 0.5.0 || 0.6.0" + - VersionPragmaExpression (Rule): # 8..14 " 0.5.0" + - VersionPragmaSpecifier (Rule): # 8..14 " 0.5.0" - VersionPragmaValue (Token): "0" # 9..10 - Period (Token): "." # 10..11 - VersionPragmaValue (Token): "5" # 11..12 - Period (Token): "." # 12..13 - VersionPragmaValue (Token): "0" # 13..14 - BarBar (Token): "||" # 15..17 - - VersionPragmaExpression (Rule): # 17..24 " 0.6.0 " - - VersionPragmaSpecifier (Rule): # 17..24 " 0.6.0 " + - VersionPragmaExpression (Rule): # 17..23 " 0.6.0" + - VersionPragmaSpecifier (Rule): # 17..23 " 0.6.0" - VersionPragmaValue (Token): "0" # 18..19 - Period (Token): "." # 19..20 - VersionPragmaValue (Token): "6" # 20..21 diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml index c1852c312e..942d923267 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml @@ -9,15 +9,15 @@ Tree: - VersionPragma (Rule): # 0..20 "solidity 0.7.0 0.8.0" - SolidityKeyword (Token): "solidity" # 0..8 - VersionPragmaExpressionsList (Rule): # 8..20 " 0.7.0 0.8.0" - - VersionPragmaExpression (Rule): # 8..15 " 0.7.0 " - - VersionPragmaSpecifier (Rule): # 8..15 " 0.7.0 " + - VersionPragmaExpression (Rule): # 8..14 " 0.7.0" + - VersionPragmaSpecifier (Rule): # 8..14 " 0.7.0" - VersionPragmaValue (Token): "0" # 9..10 - Period (Token): "." # 10..11 - VersionPragmaValue (Token): "7" # 11..12 - Period (Token): "." # 12..13 - VersionPragmaValue (Token): "0" # 13..14 - - VersionPragmaExpression (Rule): # 15..20 "0.8.0" - - VersionPragmaSpecifier (Rule): # 15..20 "0.8.0" + - VersionPragmaExpression (Rule): # 14..20 " 0.8.0" + - VersionPragmaSpecifier (Rule): # 14..20 " 0.8.0" - VersionPragmaValue (Token): "0" # 15..16 - Period (Token): "." # 16..17 - VersionPragmaValue (Token): "8" # 17..18 diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml index 84b2945f7a..22340701ee 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml @@ -11,11 +11,11 @@ Tree: - VersionPragmaExpressionsList (Rule): # 8..30 " ^1.0.0 || 2.0.0-3.0.0" - VersionPragmaExpression (Rule): # 8..30 " ^1.0.0 || 2.0.0-3.0.0" - VersionPragmaBinaryExpression (Rule): # 8..30 " ^1.0.0 || 2.0.0-3.0.0" - - VersionPragmaExpression (Rule): # 8..16 " ^1.0.0 " - - VersionPragmaUnaryExpression (Rule): # 8..16 " ^1.0.0 " + - VersionPragmaExpression (Rule): # 8..15 " ^1.0.0" + - VersionPragmaUnaryExpression (Rule): # 8..15 " ^1.0.0" - Caret (Token): "^" # 9..10 - - VersionPragmaExpression (Rule): # 10..16 "1.0.0 " - - VersionPragmaSpecifier (Rule): # 10..16 "1.0.0 " + - VersionPragmaExpression (Rule): # 10..15 "1.0.0" + - VersionPragmaSpecifier (Rule): # 10..15 "1.0.0" - VersionPragmaValue (Token): "1" # 10..11 - Period (Token): "." # 11..12 - VersionPragmaValue (Token): "0" # 12..13 diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml index 9753e15bf0..41f1d30a10 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml @@ -11,8 +11,8 @@ Tree: - VersionPragmaExpressionsList (Rule): # 8..22 " 0.6.0 - 0.7.0" - VersionPragmaExpression (Rule): # 8..22 " 0.6.0 - 0.7.0" - VersionPragmaBinaryExpression (Rule): # 8..22 " 0.6.0 - 0.7.0" - - VersionPragmaExpression (Rule): # 8..15 " 0.6.0 " - - VersionPragmaSpecifier (Rule): # 8..15 " 0.6.0 " + - VersionPragmaExpression (Rule): # 8..14 " 0.6.0" + - VersionPragmaSpecifier (Rule): # 8..14 " 0.6.0" - VersionPragmaValue (Token): "0" # 9..10 - Period (Token): "." # 10..11 - VersionPragmaValue (Token): "6" # 11..12 diff --git a/crates/solidity/testing/snapshots/cst_output/YulBlock/function_def/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/YulBlock/function_def/generated/0.4.11-success.yml index 57d2954c99..fe9a3141f3 100644 --- a/crates/solidity/testing/snapshots/cst_output/YulBlock/function_def/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/YulBlock/function_def/generated/0.4.11-success.yml @@ -24,17 +24,17 @@ Tree: - Comma (Token): "," # 18..19 - YulIdentifier (Token): "b" # 20..21 - CloseParen (Token): ")" # 21..22 - - YulReturnsDeclaration (Rule): # 22..33 " -> result " + - YulReturnsDeclaration (Rule): # 22..32 " -> result" - MinusGreaterThan (Token): "->" # 23..25 - - YulIdentifiersList (Rule): # 25..33 " result " + - YulIdentifiersList (Rule): # 25..32 " result" - YulIdentifier (Token): "result" # 26..32 - - YulBlock (Rule): # 33..60 "{\n\t\tresult := mul(a, b)\n\t}\n" + - YulBlock (Rule): # 32..60 " {\n\t\tresult := mul(a, b)\n\t}\n" - OpenBrace (Token): "{" # 33..34 - YulStatementsList (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - YulStatement (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - YulAssignmentStatement (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - - YulIdentifierPathsList (Rule): # 35..44 "\t\tresult " - - YulIdentifierPath (Rule): # 35..44 "\t\tresult " + - YulIdentifierPathsList (Rule): # 35..43 "\t\tresult" + - YulIdentifierPath (Rule): # 35..43 "\t\tresult" - YulIdentifier (Token): "result" # 37..43 - ColonEqual (Token): ":=" # 44..46 - YulExpression (Rule): # 46..57 " mul(a, b)\n" diff --git a/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.4.11-failure.yml index 3451b64cc1..c500e1419c 100644 --- a/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.4.11-failure.yml @@ -34,17 +34,17 @@ Tree: - Comma (Token): "," # 18..19 - YulIdentifier (Token): "b" # 20..21 - CloseParen (Token): ")" # 21..22 - - YulReturnsDeclaration (Rule): # 22..33 " -> result " + - YulReturnsDeclaration (Rule): # 22..32 " -> result" - MinusGreaterThan (Token): "->" # 23..25 - - YulIdentifiersList (Rule): # 25..33 " result " + - YulIdentifiersList (Rule): # 25..32 " result" - YulIdentifier (Token): "result" # 26..32 - - YulBlock (Rule): # 33..83 "{\n\t\tresult := mul(a, b)\n\t\tresult := [mul(a, b)\n\t}\n" + - YulBlock (Rule): # 32..83 " {\n\t\tresult := mul(a, b)\n\t\tresult := [mul(a, b)\n\t}..." - OpenBrace (Token): "{" # 33..34 - - YulStatementsList (Rule): # 35..66 "\t\tresult := mul(a, b)\n\t\tresult " + - YulStatementsList (Rule): # 35..65 "\t\tresult := mul(a, b)\n\t\tresult" - YulStatement (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - YulAssignmentStatement (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - - YulIdentifierPathsList (Rule): # 35..44 "\t\tresult " - - YulIdentifierPath (Rule): # 35..44 "\t\tresult " + - YulIdentifierPathsList (Rule): # 35..43 "\t\tresult" + - YulIdentifierPath (Rule): # 35..43 "\t\tresult" - YulIdentifier (Token): "result" # 37..43 - ColonEqual (Token): ":=" # 44..46 - YulExpression (Rule): # 46..57 " mul(a, b)\n" @@ -62,9 +62,9 @@ Tree: - YulIdentifierPath (Rule): # 53..55 " b" - YulIdentifier (Token): "b" # 54..55 - CloseParen (Token): ")" # 55..56 - - YulStatement (Rule): # 57..66 "\t\tresult " - - YulExpression (Rule): # 57..66 "\t\tresult " - - YulIdentifierPath (Rule): # 57..66 "\t\tresult " + - YulStatement (Rule): # 57..65 "\t\tresult" + - YulExpression (Rule): # 57..65 "\t\tresult" + - YulIdentifierPath (Rule): # 57..65 "\t\tresult" - YulIdentifier (Token): "result" # 59..65 - SKIPPED (Token): ":= [mul(a, b)\n\t" # 66..81 - CloseBrace (Token): "}" # 81..82 diff --git a/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.6.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.6.0-failure.yml index fa07fba9b7..39dab865c2 100644 --- a/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.6.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/YulBlock/ignore_unknown_delim/generated/0.6.0-failure.yml @@ -34,17 +34,17 @@ Tree: - Comma (Token): "," # 18..19 - YulIdentifier (Token): "b" # 20..21 - CloseParen (Token): ")" # 21..22 - - YulReturnsDeclaration (Rule): # 22..33 " -> result " + - YulReturnsDeclaration (Rule): # 22..32 " -> result" - MinusGreaterThan (Token): "->" # 23..25 - - YulIdentifiersList (Rule): # 25..33 " result " + - YulIdentifiersList (Rule): # 25..32 " result" - YulIdentifier (Token): "result" # 26..32 - - YulBlock (Rule): # 33..83 "{\n\t\tresult := mul(a, b)\n\t\tresult := [mul(a, b)\n\t}\n" + - YulBlock (Rule): # 32..83 " {\n\t\tresult := mul(a, b)\n\t\tresult := [mul(a, b)\n\t}..." - OpenBrace (Token): "{" # 33..34 - - YulStatementsList (Rule): # 35..66 "\t\tresult := mul(a, b)\n\t\tresult " + - YulStatementsList (Rule): # 35..65 "\t\tresult := mul(a, b)\n\t\tresult" - YulStatement (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - YulAssignmentStatement (Rule): # 35..57 "\t\tresult := mul(a, b)\n" - - YulIdentifierPathsList (Rule): # 35..44 "\t\tresult " - - YulIdentifierPath (Rule): # 35..44 "\t\tresult " + - YulIdentifierPathsList (Rule): # 35..43 "\t\tresult" + - YulIdentifierPath (Rule): # 35..43 "\t\tresult" - YulIdentifier (Token): "result" # 37..43 - ColonEqual (Token): ":=" # 44..46 - YulExpression (Rule): # 46..57 " mul(a, b)\n" @@ -62,9 +62,9 @@ Tree: - YulIdentifierPath (Rule): # 53..55 " b" - YulIdentifier (Token): "b" # 54..55 - CloseParen (Token): ")" # 55..56 - - YulStatement (Rule): # 57..66 "\t\tresult " - - YulExpression (Rule): # 57..66 "\t\tresult " - - YulIdentifierPath (Rule): # 57..66 "\t\tresult " + - YulStatement (Rule): # 57..65 "\t\tresult" + - YulExpression (Rule): # 57..65 "\t\tresult" + - YulIdentifierPath (Rule): # 57..65 "\t\tresult" - YulIdentifier (Token): "result" # 59..65 - SKIPPED (Token): ":= [mul(a, b)\n\t" # 66..81 - CloseBrace (Token): "}" # 81..82