diff --git a/.conformance-review/Rust.test.stg b/.conformance-review/Rust.test.stg index e7b72949..ae9178e6 100644 --- a/.conformance-review/Rust.test.stg +++ b/.conformance-review/Rust.test.stg @@ -21,18 +21,18 @@ * exposes over a `&mut dyn std::io::Write` sink the test harness captures; * `writeln!`/`write!` against it never surface a `io::Result` into * action/predicate position (the handle swallows/records it). - * - Generated contexts are typed structs. Child accessors follow Rust - * snake_case for rule refs (`ctx.e(0)`, list `ctx.e_all()`) and keep - * ANTLR's uppercase for token refs (`ctx.INT(0)`, list `ctx.INT_all()`), - * mirroring Go's `E(0)`/`AllE()` split but in Rust casing. + * - Generated contexts are typed structs. Child accessors use snake_case + * Rust names and reflect grammar cardinality: required children return + * `Result`, optional children return `Option`, and repeated children are + * lazy iterators (`ctx.e_children()`, `ctx.int_tokens()`). * - Rule return attributes are public fields on the returns/context value, * so `Result(r)`/`Production(p)` pass through as ``/`

` (no getter * wrapper — the ideal Rust target exposes them directly, unlike Go). * - Parser "members" are injected as an `impl` block on the generated parser * via `@parser::members`; helpers are called `self.foo()` / `self.pred(v)`. * - The generated listener trait is `TListener` with snake_case - * `enter_x`/`exit_x` and defaulted terminal/error-node visitors; a test - * listener is a unit struct implementing it, walked by `ParseTreeWalker::walk`. + * `enter_x`/`exit_x` and defaulted terminal/error-node visitors. Callbacks + * are fallible and a test listener is walked by `ParseTreeWalker::walk`. * - Casts from an active `ParserRuleContext` to a labeled-alt / concrete * borrowing view use the generated `__active_context_view` adapter. */ @@ -63,7 +63,7 @@ rustLabelContextType ::= [ default: key ] -Cast(t,v) ::= "__active_context_view::\<>(, self.base.active_invocation_states(), self.base.parse_tree_storage(), self.base.token_store()).unwrap()" +Cast(t,v) ::= "__active_context_view::\<\<'_, __ActiveParserContext>>(, self.base.active_invocation_states(), self.base.parse_tree_storage(), self.base.token_store()).unwrap()" // Rust has no `&str + &str` operator, and descriptors chain Append/AppendStr // with bare string literals on the left (`"(" + $ID.text + …` in Java terms), @@ -74,7 +74,7 @@ AppendStr(a,b) ::= <%format!("{}{}", , )%> Concat(a,b) ::= "" -AssertIsList(v) ::= "let __ttt__: &[_] = &;" // just use the static type system +AssertIsList(v) ::= "let _: Vec\<_> = .collect();" // just use the static type system AssignLocal(s,v) ::= " = ;" @@ -181,8 +181,12 @@ BasicListener(X) ::= << struct LeafListener; impl TListener for LeafListener { - fn visit_terminal(&mut self, node: &TerminalNode) { + fn visit_terminal( + &mut self, + node: &TerminalNode, + ) -> Result\<(), std::convert::Infallible> { writeln!(self.output(), "{}", node.symbol().text()); + Ok(()) } } } @@ -190,7 +194,11 @@ impl TListener for LeafListener { WalkListener(s) ::= << let mut listener = LeafListener::default(); -ParseTreeWalker::walk_with_invocation_states(&mut listener, , self.base.active_invocation_states()); +ParseTreeWalker::walk_with_invocation_states( + &mut listener, + , + self.base.active_invocation_states(), +).unwrap(); >> // Java needs a custom context superclass because its default RuleContext does @@ -207,18 +215,27 @@ TokenGetterListener(X) ::= << struct LeafListener; impl TListener for LeafListener { - fn exit_a(&mut self, ctx: &AContext) { + fn exit_a( + &mut self, + ctx: &AContext, + ) -> Result\<(), std::convert::Infallible> { if ctx.child_count() == 2 { + let tokens: Vec\<_> = ctx.int_tokens().collect(); writeln!( self.output(), "{} {} {}", - ctx.INT(0).symbol().text(), - ctx.INT(1).symbol().text(), - java_style_list(&ctx.INT_all()) + tokens[0].symbol().text(), + tokens[1].symbol().text(), + java_style_list(&tokens) ); } else { - writeln!(self.output(), "{}", ctx.ID(0).symbol()); + writeln!( + self.output(), + "{}", + ctx.id_token().expect("ID alternative").symbol() + ); } + Ok(()) } } } @@ -230,18 +247,23 @@ RuleGetterListener(X) ::= << struct LeafListener; impl TListener for LeafListener { - fn exit_a(&mut self, ctx: &AContext) { + fn exit_a( + &mut self, + ctx: &AContext, + ) -> Result\<(), std::convert::Infallible> { + let children: Vec\<_> = ctx.b_children().collect(); if ctx.child_count() == 2 { writeln!( self.output(), "{} {} {}", - ctx.b(0).start().text(), - ctx.b(1).start().text(), - ctx.b_all()[0].start().text() + children[0].start().text(), + children[1].start().text(), + children[0].start().text() ); } else { - writeln!(self.output(), "{}", ctx.b(0).start().text()); + writeln!(self.output(), "{}", children[0].start().text()); } + Ok(()) } } } @@ -254,18 +276,27 @@ LRListener(X) ::= << struct LeafListener; impl TListener for LeafListener { - fn exit_e(&mut self, ctx: &EContext) { + fn exit_e( + &mut self, + ctx: &EContext, + ) -> Result\<(), std::convert::Infallible> { if ctx.child_count() == 3 { + let children: Vec\<_> = ctx.e_children().collect(); writeln!( self.output(), "{} {} {}", - ctx.e(0).start().text(), - ctx.e(1).start().text(), - ctx.e_all()[0].start().text() + children[0].start().text(), + children[1].start().text(), + children[0].start().text() ); } else { - writeln!(self.output(), "{}", ctx.INT(0).symbol().text()); + writeln!( + self.output(), + "{}", + ctx.int_token().expect("INT alternative").symbol().text() + ); } + Ok(()) } } } @@ -277,11 +308,28 @@ LRWithLabelsListener(X) ::= << struct LeafListener; impl TListener for LeafListener { - fn exit_call_label(&mut self, ctx: &CallLabelContext) { - writeln!(self.output(), "{} {}", ctx.e(0).start().text(), ctx.e_list(0)); + fn exit_call_label( + &mut self, + ctx: &CallLabelContext, + ) -> Result\<(), std::convert::Infallible> { + writeln!( + self.output(), + "{} {}", + ctx.e().expect("call target").start().text(), + ctx.e_list().expect("call arguments") + ); + Ok(()) } - fn exit_int_label(&mut self, ctx: &IntLabelContext) { - writeln!(self.output(), "{}", ctx.INT(0).symbol().text()); + fn exit_int_label( + &mut self, + ctx: &IntLabelContext, + ) -> Result\<(), std::convert::Infallible> { + writeln!( + self.output(), + "{}", + ctx.int_token().expect("INT alternative").symbol().text() + ); + Ok(()) } } } @@ -290,8 +338,8 @@ impl TListener for LeafListener { DeclareContextListGettersFunction() ::= << fn foo() { let s: Option\ = None; - let _a: Vec\ = s.as_ref().unwrap().a_all(); - let _b: Vec\ = s.as_ref().unwrap().b_all(); + let _a: Vec\ = s.as_ref().unwrap().a_children().collect(); + let _b: Vec\ = s.as_ref().unwrap().b_children().collect(); } >> @@ -311,8 +359,13 @@ Invoke_pred(v) ::= <)>> ParserTokenType(t) ::= "Parser::" ContextRuleFunction(ctx, rule) ::= "." -ContextListFunction(ctx, rule) ::= "._all()" +ContextListFunction(ctx, rule) ::= "._children()" StringType() ::= "String" ContextMember(ctx, member) ::= "." -SubContextLocal(ctx, subctx, local) ::= ".." -SubContextMember(ctx, subctx, member) ::= ".." +rustSubcontextAccessor ::= [ + "e(0)": "e_children().next().unwrap()", + "e(1)": "e_children().nth(1).unwrap()", + default: key +] +SubContextLocal(ctx, subctx, local) ::= ".." +SubContextMember(ctx, subctx, member) ::= ".." diff --git a/.conformance-review/Rust.test.stg.design-notes.md b/.conformance-review/Rust.test.stg.design-notes.md index 5be34f61..bc868a57 100644 --- a/.conformance-review/Rust.test.stg.design-notes.md +++ b/.conformance-review/Rust.test.stg.design-notes.md @@ -37,9 +37,16 @@ runtime: `PrintArrayJavaStyle`, Python `str_list`), exactly as the "least certain" section predicted. Same for `TokenGetterListener`'s list print. 7. **`LRWithLabelsListener`'s `ctx.eList()` is a rule-child accessor** (rule - `eList`), not a list getter: rendered `ctx.e_list(0)`. Listener accessors - were aligned to the positional convention (`ctx.INT(0)`, `ctx.e(0)`) - declared in the header comment. + `eList`), not a list getter. It now renders + `ctx.e_list().expect("call arguments")`. +8. **Dogfooding replaced positional Java-style getters with a Rust API.** + Generated accessors now encode grammar cardinality as `Result`, `Option`, or + a lazy iterator; token methods are snake_case; listener callbacks propagate + a generic error; and active parser contexts use a hidden type-state marker. + The neutral left-recursion descriptors still pass literal `e(0)` / `e(1)` + fragments to `SubContextLocal`; the test template maps those fragments to + `e_children().next()` / `.nth(1)` instead of adding compatibility methods to + generated contexts. Companion to `Rust.test.stg`. This file explains the non-trivial renderings and, critically, enumerates the **generated-code / runtime API surface** the templates @@ -76,16 +83,14 @@ yields a sink whose `write!`/`writeln!` are used in statement position only (all three `write*` templates end in `;`), so the discarded `io::Result` is acceptable exactly as `outStream.println(...)`'s `void` is in Java. -### Typed contexts + child accessors (Go-style split, Rust casing) -`ctx.e(0)` / `ctx.e_all()` for rule children; `ctx.INT(0)` / `ctx.INT_all()` for -token children. This mirrors Go's `E(0)`/`AllE()` "single-vs-list getter" split, -but in Rust naming: rule refs are snake_case identifiers so they stay lowercase; -token refs are ANTLR token *names* (conventionally uppercase) so they stay -uppercase. I chose the `_all()` suffix (over Go's `All*` prefix or Python/TS -`*_list()`) because `ContextListFunction` in the neutral tests renders `()` in -Java but Python/TS already diverge to `_list()`; a suffix reads most naturally -in snake_case Rust and keeps the single-child getter (`e`) and list getter (`e_all`) -lexically adjacent. **`ContextListFunction` is rendered `._all()` to match.** +### Typed contexts + cardinality-aware child accessors +The grammar determines the Rust return type. A required singular child returns +`Result` because error recovery can still omit it; an +optional singular child returns `Option`; and a repeated child returns a lazy +iterator. Rule labels keep their source names (`left()`), repeated rule methods +use `_children()`, and token methods use snake_case `_token()` / `_tokens()` +suffixes. `ContextListFunction` therefore renders +`._children()`. ### Rule return attributes as fields — `Result`/`Production` pass through Java/C#/Python/Swift/Dart render `Result(r)`/`Production(p)` as a bare ``/`

` @@ -103,18 +108,18 @@ write to the output sink). Predicates `{...}?` and actions `{...}` are assumed t execute in a scope where `self` is the parser (or lexer) recognizer. ### Listener trait `TListener` -Generated trait `TListener` with snake_case `enter_` / `exit_` and a -defaulted `visit_terminal(&mut self, node: &TerminalNode)`. Test listeners are unit -structs (`#[derive(Default)] struct LeafListener;`) implementing it, walked by a -`ParseTreeWalker::walk(&mut listener, tree)`. Grammar name `T` ⇒ trait `TListener`, -matching the neutral `Listener`/`TBaseListener` convention (Rust has default -trait methods, so there is no separate "base" class — the trait *is* the base). +Generated trait `TListener` has snake_case `enter_` / +`exit_`, `enter_every_rule` / `exit_every_rule`, and defaulted terminal +and error-node methods. Every callback returns `Result<(), E>`, and the typed +walker stops on the first error. Grammar name `T` gives trait `TListener`; +default trait methods replace a separate base-listener class. ### Downcast to concrete/labeled-alt context -`Cast(t,v)` ⇒ `().downcast_ref::<>().unwrap()` — the Rust analog of Java's -`((BinaryContext)$ctx)`. Assumes contexts are `dyn`-compatible / carry an `Any`-like -downcast (`downcast_ref::()`), which is how a trait-object context tree in Rust -would expose labeled-alternative subtypes. +Stored trees use `RuleNodeView::downcast_ref::()`. Embedded actions execute +before the stored rule exists, so `Cast(t,v)` uses `__active_context_view` and +the generated `Context<'_, __ActiveParserContext>` type. The default +`Context<'_>` type represents completed trees and alone exposes total +`rule_node()`. ## Per-template notes (non-trivial only) @@ -131,10 +136,9 @@ would expose labeled-alternative subtypes. - **Append** — ` + &().to_string()`: `String + &str`. `AppendStr` is `String + &str` where `` is already a string, so no `.to_string()`. `Concat` is raw token juxtaposition (no operator) exactly as every target. -- **AssertIsList** — `let __ttt__: &[_] = &;`. Pure static-type assertion (like - Java's `List __ttt__ = ;` / C#'s cast): if `` is not sliceable it won't - compile. Chose a slice coercion over a `Vec` binding so it works whether the getter - returns `Vec<_>` or `&[_]`. +- **AssertIsList** — `let _: Vec<_> = .collect();`. Pure static-type assertion + for Rust's lazy repeated-child contract: if `` is not an iterator it will + not compile. The `Vec` exists only inside this conformance action. - **InitIntMember / InitBooleanMember / InitIntVar** — `let mut : T = ; let _ = ;`. The `let _ = ;` suppresses an `unused_variables`/`unused_assignment` warning (which, under the repo's `-D warnings`, would be a hard error), mirroring Go's @@ -189,18 +193,17 @@ would expose labeled-alternative subtypes. base via `base_next_token()`/`base_emit()` (Rust has no `super`), and that the interpreter slot is a swappable `Box`. - **BasicListener / TokenGetterListener / RuleGetterListener / LRListener / - LRWithLabelsListener** — unit-struct listeners implementing `TListener`. Note the - `TokenGetterListener` prints `ctx.INT_all()` via `{:?}` (Java printed the raw list - `ctx.INT()`); like `RuleInvocationStack` the exact debug formatting is unlikely to - byte-match Java's list rendering without a helper — flagged. + LRWithLabelsListener** — unit-struct listeners implementing the fallible + `TListener` contract. Repeated getters are collected only where the + descriptor needs indexing or Java-compatible list formatting. - **TreeNodeWithAltNumField** — a `MyRuleNode` struct wrapping `BaseParserRuleContext` with an `alt_num` field and a `ParserRuleContext` impl overriding `alt_number`/`set_alt_number`. Assumes contexts compose over a `BaseParserRuleContext` and that `alt_number` is an overridable trait method. -- **WalkListener** — `let mut listener = LeafListener::default(); ParseTreeWalker::walk(&mut listener, );`. +- **WalkListener** — creates `LeafListener`, then unwraps the typed walk's + `Result<(), Infallible>`. - **DeclareContextListGettersFunction** — a compile-only shape check using the list - getters (`a_all()`/`b_all()`) returning `Vec>`. `Rc` because a parse - tree in Rust is most naturally reference-counted shared nodes. + iterators (`a_children()` / `b_children()`) and collects them into `Vec`s. - **Declare_foo / Invoke_foo / Declare_pred / Invoke_pred** — helper fns on the recognizer (`&mut self` so they can write output); `pred` prints `eval={v}` and returns `v`. Invoked `self.foo()` / `self.pred()`. @@ -232,24 +235,24 @@ Grouped so each can be checked against a real Rust runtime. ### Generated context types 7. Per-rule context struct named `Context` (e.g. `AContext`, `EContext`, `CallContext`, `IntContext`, `SContext`, `BinaryContext`). -8. Positional child accessors: rule child `ctx.(i)` (single) + `ctx._all()` - (`Vec` of children); token child `ctx.(i)` + `ctx._all()`. +8. Cardinality-aware accessors: required singular `Result`, optional singular `Option`, and repeated + `impl Iterator`. Tokens use snake_case `_token` / `_tokens` + methods, and stable grammar labels get named methods. 9. `ctx.child_count()`, `ctx.start()` (→ token with `.text()`), and terminal nodes exposing `.symbol()` (→ token with `.text()`), plus `TerminalNode`. 10. Rule **return attributes exposed as public fields** on the returns/context value (`ctx.v`, bare `r`/`p`) — *not* getters. (Divergence from Go.) -11. Base-context downcast: `().downcast_ref::()` (an `Any`-style - facility on the context trait object) for labeled-alt access. -12. Contexts compose over a `BaseParserRuleContext`, and `ParserRuleContext` is a - trait with overridable `alt_number()`/`set_alt_number()`; a - `ParserRuleContextRef` (shared, e.g. `Rc`) type for parent links; trees are - `Rc<…Context>`. +11. Stored-context downcast through `RuleNodeView::downcast_ref::()`, plus + `__active_context_view::>()` inside parser + actions. +12. A default stored-context type state with total `rule_node()`; the hidden + active state does not implement `AsRuleNode`. ### Listener / walker -13. Generated listener trait `Listener` (e.g. `TListener`) with **defaulted** - `enter_`/`exit_(&mut self, ctx: &Context)` and a defaulted - `visit_terminal(&mut self, &TerminalNode)`. -14. `ParseTreeWalker::walk(&mut impl TListener, tree)` free function / assoc fn. +13. Generated `Listener` with defaulted typed, + every-rule, terminal, and error-node callbacks returning `Result<(), E>`. +14. `ParseTreeWalker::walk` and `walk_with_invocation_states` propagate `E`. ### Lexer override / ATN-simulator plumbing (heaviest assumptions) 15. Ability to override `next_token`/`emit` on the generated lexer and call the base diff --git a/.conformance-review/rust-test-stg-honest-reference-gap.md b/.conformance-review/rust-test-stg-honest-reference-gap.md index 365d2468..49a8d0d5 100644 --- a/.conformance-review/rust-test-stg-honest-reference-gap.md +++ b/.conformance-review/rust-test-stg-honest-reference-gap.md @@ -11,8 +11,9 @@ > rendered Rust action/predicate bodies verbatim after `$`-attribute > translation (`src/bin_support/embedded.rs` — the Rust analog of ANTLR's > `ActionTranslator`). The four capability axes below are now generated: -> an output sink (`self.output()`), typed context views with positional -> accessors and public attribute fields (`FromRuleNode` conversion), +> an output sink (`self.output()`), typed context views with +> cardinality-aware Rust accessors and public attribute fields +> (`FromRuleNode` conversion), > typed attrs snapshots replacing the int-only `int_return` map, and > `@members` as real struct fields / impl items. Listener traits and a > typed walker bridge cover the listener suite. Validating the reference diff --git a/README.md b/README.md index 9df47d8b..3f7fff38 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,45 @@ mod generated { } ``` +### Typed listeners and visitors + +Parser generation emits a typed `Listener` and +`TreeWalker` by default. A listener can start a grammar-typed walk +directly. Listener callbacks return `Result<(), E>`, where `E` defaults to +`Infallible`, so domain errors can stop traversal without a side channel: + +```rust +listener.walk(parsed.tree())?; +``` + +Use `--no-listener` to omit that surface. Add `--visitor` to emit a typed +`Visitor`; visitors choose an associated `Result` type, define its +initial value with `default_result()`, and drive recursion explicitly: + +```rust +type Result = Result; + +fn default_result(&mut self) -> Self::Result { + Ok(0) +} + +fn visit_add_label(&mut self, ctx: &AddLabelContext) -> Self::Result { + let left = self.visit(ctx.left()?)?; + let right = self.visit(ctx.right()?)?; + Ok(left + right) +} +``` + +Generated child accessors follow grammar cardinality. Required children return +`Result`, optional children return `Option`, and +repeated children are lazy iterators. Rule labels keep their grammar names +(`left()`), while token accessors use snake_case names such as `int_token()` and +`comma_tokens()`. + +`--no-visitor` disables visitor generation. The generator also accepts ANTLR's +single-dash spellings (`-listener`, `-no-listener`, `-visitor`, +`-no-visitor`). + Call the generated parser helper for the compact path: ```rust diff --git a/src/bin/antlr4-rust-gen.rs b/src/bin/antlr4-rust-gen.rs index 607c756c..fe3cbfb9 100644 --- a/src/bin/antlr4-rust-gen.rs +++ b/src/bin/antlr4-rust-gen.rs @@ -17,7 +17,8 @@ use grammar::frontend::SourceSpan; use grammar::loader::LoadOptions; use grammar::model::{ Alternative, AlternativeId, AttributeSymbol, Block, Element, ElementKind, LabelKind, - LeftRecursiveAlternativeKind, ModelNodeId, Rule, SemanticGrammar, Terminal, + LeftRecursiveAlternativeKind, ModelNodeId, Quantifier, Rule, SemanticGrammar, SetElement, + Terminal, Vocabulary, }; use grammar::provenance::{Origin, ProvenanceIndex}; use grammar::source::SourceSet; @@ -146,6 +147,8 @@ fn main() -> Result<(), Box> { ParserRenderOptions { require_generated_parser: args.require_generated_parser, embedded: args.embedded_actions, + generate_listener: args.generate_listener, + generate_visitor: args.generate_visitor, sem_unknown: args.sem_unknown, patterns: Some(&args.sem_patterns), }, @@ -1817,6 +1820,8 @@ struct Args { sem_patterns: SemPatternFile, require_full_semantics: bool, option_hooks: BTreeSet, + generate_listener: bool, + generate_visitor: bool, /// `--actions embedded`: the grammar contains real Rust action/predicate /// bodies (rendered through a `.test.stg`); splice them verbatim after /// `$`-attribute translation instead of recognizing template markup. @@ -1835,6 +1840,8 @@ impl Args { let mut sem_patterns = SemPatternFile::default(); let mut require_full_semantics = false; let mut option_hooks = BTreeSet::new(); + let mut generate_listener = true; + let mut generate_visitor = false; let mut positional_only = false; let mut iter = env::args().skip(1); @@ -1851,6 +1858,10 @@ impl Args { "--out-dir" => out_dir = Some(PathBuf::from(next_arg(&mut iter, "--out-dir")?)), "--require-generated-parser" => require_generated_parser = true, "--allow-unsupported-lexer-actions" => allow_unsupported_lexer_actions = true, + "-listener" | "--listener" => generate_listener = true, + "-no-listener" | "--no-listener" => generate_listener = false, + "-visitor" | "--visitor" => generate_visitor = true, + "-no-visitor" | "--no-visitor" => generate_visitor = false, "--sem-patterns" => { sem_patterns = load_sem_patterns(&PathBuf::from(next_arg(&mut iter, "--sem-patterns")?)) @@ -1905,6 +1916,8 @@ impl Args { sem_patterns, require_full_semantics, option_hooks, + generate_listener, + generate_visitor, embedded_actions, })) } @@ -1926,6 +1939,10 @@ Options: --require-generated-parser Require generated bodies for every parser rule --allow-unsupported-lexer-actions Ignore unsupported lexer actions + -listener, --listener Generate the typed listener and walker (default) + -no-listener, --no-listener Do not generate the typed listener or walker + -visitor, --visitor Generate the typed visitor + -no-visitor, --no-visitor Do not generate the typed visitor (default) --sem-unknown error|hook|assume-true|assume-false Choose unsupported semantic predicate policy --sem-patterns FILE Load semantic helper patterns @@ -2288,7 +2305,7 @@ fn structural_embedded_model( .collect(), init_body, after_body, - alts: structural_rule_alternatives(rule), + alts: structural_rule_alternatives(rule, &semantic.recognizer.vocabulary), }; } @@ -2319,13 +2336,13 @@ fn structural_attr_decl(attribute: &AttributeSymbol) -> embedded::AttrDecl { } } -fn structural_rule_alternatives(rule: &Rule) -> Vec { +fn structural_rule_alternatives(rule: &Rule, vocabulary: &Vocabulary) -> Vec { let Some(left_recursion) = &rule.left_recursion else { return rule .block .alternatives .iter() - .map(|alternative| structural_alt_model(alternative, None)) + .map(|alternative| structural_alt_model(alternative, None, vocabulary)) .collect(); }; @@ -2352,12 +2369,15 @@ fn structural_rule_alternatives(rule: &Rule) -> Vec { label: removed.map(|removed| removed.label.name.clone()), target: removed .map_or_else(|| rule.name.clone(), |removed| removed.target.clone()), + token_types: Vec::new(), is_block: false, is_list: removed .is_some_and(|removed| removed.label.kind == LabelKind::List), + cardinality: embedded::ChildCardinality::ONE, + stable_accessor: true, } }); - Some(structural_alt_model(alternative, leading_ref)) + Some(structural_alt_model(alternative, leading_ref, vocabulary)) }) .collect() } @@ -2381,12 +2401,21 @@ fn find_alternative(block: &Block, id: AlternativeId) -> Option<&Alternative> { fn structural_alt_model( alternative: &Alternative, removed_leading_ref: Option, + vocabulary: &Vocabulary, ) -> embedded::AltModel { let leading_target = removed_leading_ref .as_ref() .map(|element| element.target.clone()); + let mut children = structural_context_children(&alternative.elements, vocabulary); + if let Some(leading) = &removed_leading_ref { + add_child_cardinality( + &mut children, + &leading.target, + embedded::ChildCardinality::ONE, + ); + } let mut refs = removed_leading_ref.into_iter().collect(); - collect_structural_context_refs(&alternative.elements, &mut refs); + collect_structural_context_refs(&alternative.elements, &mut refs, true, vocabulary); embedded::AltModel { label: alternative.label.as_ref().map(|label| label.value.clone()), span: ( @@ -2394,6 +2423,7 @@ fn structural_alt_model( usize::try_from(alternative.span.bytes.end).expect("source offset exceeds usize"), ), refs, + children, leading_target: leading_target.or_else(|| { alternative .elements @@ -2403,54 +2433,116 @@ fn structural_alt_model( } } -fn collect_structural_context_refs(elements: &[Element], refs: &mut Vec) { +fn collect_structural_context_refs( + elements: &[Element], + refs: &mut Vec, + stable_accessor: bool, + vocabulary: &Vocabulary, +) { + collect_structural_context_refs_with_cardinality( + elements, + refs, + stable_accessor, + embedded::ChildCardinality::ONE, + vocabulary, + ); +} + +fn collect_structural_context_refs_with_cardinality( + elements: &[Element], + refs: &mut Vec, + stable_accessor: bool, + enclosing_cardinality: embedded::ChildCardinality, + vocabulary: &Vocabulary, +) { for element in elements { let label = element.label.as_ref().map(|label| label.name.clone()); let is_list = element .label .as_ref() .is_some_and(|label| label.kind == LabelKind::List); + let cardinality = multiply_child_cardinalities( + enclosing_cardinality, + quantified_cardinality(embedded::ChildCardinality::ONE, element.quantifier), + ); match &element.kind { ElementKind::RuleCall(call) => refs.push(embedded::ElementRef { label, target: call.name.clone(), + token_types: Vec::new(), is_block: false, is_list, + cardinality, + stable_accessor, }), - ElementKind::Terminal(Terminal::Token(name)) => { + ElementKind::Terminal(terminal) => { refs.push(embedded::ElementRef { label, - target: name.clone(), - is_block: false, + target: structural_terminal_target(terminal), + token_types: structural_terminal_token_types(terminal, vocabulary), + is_block: !matches!(terminal, Terminal::Token(_)), is_list, + cardinality, + stable_accessor, }); } ElementKind::Block(block) => { + let token_types = structural_block_token_types(block, vocabulary); + if !token_types.is_empty() { + refs.push(embedded::ElementRef { + label, + target: String::new(), + token_types, + is_block: true, + is_list, + cardinality, + stable_accessor, + }); + continue; + } if label.is_some() { refs.push(embedded::ElementRef { label, target: String::new(), + token_types: Vec::new(), is_block: true, is_list, + cardinality, + stable_accessor: false, }); } + let nested_stable = stable_accessor && block.alternatives.len() == 1; for alternative in &block.alternatives { - collect_structural_context_refs(&alternative.elements, refs); + collect_structural_context_refs_with_cardinality( + &alternative.elements, + refs, + nested_stable, + cardinality, + vocabulary, + ); } } - ElementKind::Terminal(_) | ElementKind::Range(..) | ElementKind::Set { .. } - if label.is_some() => - { + ElementKind::Set { inverted, elements } => { refs.push(embedded::ElementRef { label, target: String::new(), + token_types: structural_set_token_types(*inverted, elements, vocabulary), is_block: true, is_list, + cardinality, + stable_accessor, }); } - ElementKind::Terminal(_) - | ElementKind::Range(..) - | ElementKind::Set { .. } + ElementKind::Range(..) if label.is_some() => refs.push(embedded::ElementRef { + label, + target: String::new(), + token_types: Vec::new(), + is_block: false, + is_list, + cardinality, + stable_accessor: false, + }), + ElementKind::Range(..) | ElementKind::Action { .. } | ElementKind::Predicate { .. } | ElementKind::Epsilon => {} @@ -2458,6 +2550,252 @@ fn collect_structural_context_refs(elements: &[Element], refs: &mut Vec String { + match terminal { + Terminal::Token(name) | Terminal::Literal(name) | Terminal::LexerCharSet(name) => { + name.clone() + } + Terminal::Eof => "EOF".to_owned(), + Terminal::Wildcard => String::new(), + } +} + +fn structural_terminal_token_types(terminal: &Terminal, vocabulary: &Vocabulary) -> Vec { + if matches!(terminal, Terminal::Wildcard) { + return (1..=vocabulary.max_token_type()).collect(); + } + let token_type = match terminal { + Terminal::Token(name) => vocabulary.by_name.get(name).copied(), + Terminal::Literal(literal) => vocabulary.by_literal.get(literal).copied(), + Terminal::Eof => Some(TOKEN_EOF), + Terminal::LexerCharSet(_) | Terminal::Wildcard => None, + }; + token_type.into_iter().collect() +} + +fn structural_set_token_types( + inverted: bool, + elements: &[SetElement], + vocabulary: &Vocabulary, +) -> Vec { + let mut members = BTreeSet::new(); + for element in elements { + match element { + SetElement::Terminal { value, .. } => { + members.extend(structural_terminal_token_types(value, vocabulary)); + } + SetElement::Range { start, stop, .. } => { + let Some(start) = vocabulary.by_literal.get(start).copied() else { + continue; + }; + let Some(stop) = vocabulary.by_literal.get(stop).copied() else { + continue; + }; + if start <= stop { + members.extend(start..=stop); + } + } + } + } + if inverted { + (1..=vocabulary.max_token_type()) + .filter(|token_type| !members.contains(token_type)) + .collect() + } else { + members.into_iter().collect() + } +} + +fn structural_element_token_types(element: &Element, vocabulary: &Vocabulary) -> Vec { + match &element.kind { + ElementKind::Terminal(terminal) => structural_terminal_token_types(terminal, vocabulary), + ElementKind::Set { inverted, elements } => { + structural_set_token_types(*inverted, elements, vocabulary) + } + ElementKind::Block(block) => structural_block_token_types(block, vocabulary), + ElementKind::RuleCall(_) + | ElementKind::Range(..) + | ElementKind::Action { .. } + | ElementKind::Predicate { .. } + | ElementKind::Epsilon => Vec::new(), + } +} + +fn structural_block_token_types(block: &Block, vocabulary: &Vocabulary) -> Vec { + let mut token_types = BTreeSet::new(); + for alternative in &block.alternatives { + let mut elements = alternative.elements.iter().filter(|element| { + !matches!( + element.kind, + ElementKind::Action { .. } | ElementKind::Predicate { .. } | ElementKind::Epsilon + ) + }); + let Some(element) = elements.next() else { + return Vec::new(); + }; + if elements.next().is_some() || element.quantifier != Quantifier::One { + return Vec::new(); + } + let alternative_types = structural_element_token_types(element, vocabulary); + if alternative_types.is_empty() { + return Vec::new(); + } + token_types.extend(alternative_types); + } + token_types.into_iter().collect() +} + +fn structural_terminal_child_target( + terminal: &Terminal, + vocabulary: &Vocabulary, +) -> Option { + match terminal { + Terminal::Token(name) => Some(name.clone()), + Terminal::Literal(literal) => { + let token_type = vocabulary.by_literal.get(literal)?; + vocabulary + .tokens + .iter() + .find(|token| token.number == *token_type) + .and_then(|token| token.name.as_ref()) + .filter(|name| !name.starts_with("T__")) + .cloned() + } + Terminal::Eof => Some("EOF".to_owned()), + Terminal::LexerCharSet(_) | Terminal::Wildcard => None, + } +} + +fn structural_context_children( + elements: &[Element], + vocabulary: &Vocabulary, +) -> BTreeMap { + let mut children = BTreeMap::new(); + for element in elements { + let mut element_children = match &element.kind { + ElementKind::RuleCall(call) => { + BTreeMap::from([(call.name.clone(), embedded::ChildCardinality::ONE)]) + } + ElementKind::Terminal(terminal) => { + structural_terminal_child_target(terminal, vocabulary) + .map(|target| BTreeMap::from([(target, embedded::ChildCardinality::ONE)])) + .unwrap_or_default() + } + ElementKind::Block(block) => structural_block_children(block, vocabulary), + ElementKind::Range(..) + | ElementKind::Set { .. } + | ElementKind::Action { .. } + | ElementKind::Predicate { .. } + | ElementKind::Epsilon => BTreeMap::new(), + }; + for cardinality in element_children.values_mut() { + *cardinality = quantified_cardinality(*cardinality, element.quantifier); + } + for (target, cardinality) in element_children { + add_child_cardinality(&mut children, &target, cardinality); + } + } + children +} + +fn structural_block_children( + block: &Block, + vocabulary: &Vocabulary, +) -> BTreeMap { + choice_child_cardinalities( + block + .alternatives + .iter() + .map(|alternative| structural_context_children(&alternative.elements, vocabulary)), + ) +} + +fn choice_child_cardinalities( + alternatives: impl IntoIterator>, +) -> BTreeMap { + let alternatives = alternatives.into_iter().collect::>(); + let targets = alternatives + .iter() + .flat_map(|alternative| alternative.keys().cloned()) + .collect::>(); + targets + .into_iter() + .map(|target| { + let mut min = usize::MAX; + let mut max = Some(0_usize); + for alternative in &alternatives { + let cardinality = alternative + .get(&target) + .copied() + .unwrap_or(embedded::ChildCardinality::ZERO); + min = min.min(cardinality.min); + max = match (max, cardinality.max) { + (Some(current), Some(next)) => Some(current.max(next)), + _ => None, + }; + } + ( + target, + embedded::ChildCardinality { + min: if min == usize::MAX { 0 } else { min }, + max, + }, + ) + }) + .collect() +} + +fn add_child_cardinality( + children: &mut BTreeMap, + target: &str, + cardinality: embedded::ChildCardinality, +) { + let total = children + .entry(target.to_owned()) + .or_insert(embedded::ChildCardinality::ZERO); + total.min = total.min.saturating_add(cardinality.min); + total.max = match (total.max, cardinality.max) { + (Some(current), Some(next)) => Some(current.saturating_add(next)), + _ => None, + }; +} + +fn quantified_cardinality( + cardinality: embedded::ChildCardinality, + quantifier: Quantifier, +) -> embedded::ChildCardinality { + match quantifier { + Quantifier::One => cardinality, + Quantifier::Optional { .. } => embedded::ChildCardinality { + min: 0, + max: cardinality.max, + }, + Quantifier::ZeroOrMore { .. } => embedded::ChildCardinality { + min: 0, + max: (cardinality.max == Some(0)).then_some(0), + }, + Quantifier::OneOrMore { .. } => embedded::ChildCardinality { + min: cardinality.min, + max: (cardinality.max == Some(0)).then_some(0), + }, + } +} + +const fn multiply_child_cardinalities( + left: embedded::ChildCardinality, + right: embedded::ChildCardinality, +) -> embedded::ChildCardinality { + let max = match (left.max, right.max) { + (Some(0), _) | (_, Some(0)) => Some(0), + (Some(left), Some(right)) => Some(left.saturating_mul(right)), + _ => None, + }; + embedded::ChildCardinality { + min: left.min.saturating_mul(right.min), + max, + } +} + fn structural_leading_target(element: &Element) -> Option { match &element.kind { ElementKind::RuleCall(call) => Some(call.name.clone()), @@ -3146,6 +3484,7 @@ struct GeneratedStepRenderContext<'a> { portable_locals: Option>, inline_action_statements: &'a BTreeMap, track_alt_numbers: bool, + track_context_alt_numbers: bool, direct_generated_rule_calls: &'a [bool], atn_preferred_rule_calls: &'a [bool], } @@ -3184,16 +3523,31 @@ struct LexerTypedHookMapping { call: SemanticHelperCall, } -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] struct ParserRenderOptions<'a> { require_generated_parser: bool, /// Splice verbatim Rust action/predicate bodies from the grammar /// (`--actions embedded`). embedded: bool, + generate_listener: bool, + generate_visitor: bool, sem_unknown: SemUnknownPolicy, patterns: Option<&'a SemPatternFile>, } +impl Default for ParserRenderOptions<'_> { + fn default() -> Self { + Self { + require_generated_parser: false, + embedded: false, + generate_listener: true, + generate_visitor: false, + sem_unknown: SemUnknownPolicy::default(), + patterns: None, + } + } +} + #[derive(Clone, Copy)] struct ActionStateSets<'a> { all: &'a BTreeSet, @@ -4704,6 +5058,7 @@ fn render_generated_rule_dispatch( &[], inline_action_statements, track_alt_numbers, + false, None, None, ) @@ -4716,6 +5071,7 @@ fn render_generated_rule_dispatch_with_rule_names( rule_names: &[String], inline_action_statements: &BTreeMap, track_alt_numbers: bool, + track_context_alt_numbers: bool, embedded: Option>, portable_locals: Option>, ) -> String { @@ -4765,6 +5121,7 @@ fn render_generated_rule_dispatch_with_rule_names( portable_locals, inline_action_statements, track_alt_numbers, + track_context_alt_numbers, direct_generated_rule_calls, atn_preferred_rule_calls: &atn_preferred_rule_calls, }; @@ -5614,11 +5971,12 @@ fn render_generated_decision( for (index, steps) in alts.iter().enumerate() { let alt = index + 1; writeln!(out, "{pad} {alt} => {{").expect("writing to a string cannot fail"); - render_generated_alt_number_assignment( + render_generated_alt_number_assignments( out, &format!("{pad} "), alt, render_context.track_alt_numbers && track_alt_number, + render_context.track_context_alt_numbers && track_alt_number, ); render_generated_steps(out, steps, indent + 2, render_context); writeln!(out, "{pad} }}").expect("writing to a string cannot fail"); @@ -6042,14 +6400,27 @@ fn intervals_condition(symbol: &str, intervals: &[(i32, i32)]) -> String { .join(" || ") } -fn render_generated_alt_number_assignment(out: &mut String, pad: &str, alt: usize, enabled: bool) { - if !enabled { - return; +fn render_generated_alt_number_assignments( + out: &mut String, + pad: &str, + alt: usize, + track_alt_number: bool, + track_context_alt_number: bool, +) { + if track_alt_number { + writeln!(out, "{pad}if __ctx.alt_number() == 0 {{") + .expect("writing to a string cannot fail"); + writeln!(out, "{pad} __ctx.set_alt_number({alt});") + .expect("writing to a string cannot fail"); + writeln!(out, "{pad}}}").expect("writing to a string cannot fail"); + } + if track_context_alt_number { + writeln!(out, "{pad}if __ctx.context_alt_number() == 0 {{") + .expect("writing to a string cannot fail"); + writeln!(out, "{pad} __ctx.set_context_alt_number({alt});") + .expect("writing to a string cannot fail"); + writeln!(out, "{pad}}}").expect("writing to a string cannot fail"); } - writeln!(out, "{pad}if __ctx.alt_number() == 0 {{").expect("writing to a string cannot fail"); - writeln!(out, "{pad} __ctx.set_alt_number({alt});") - .expect("writing to a string cannot fail"); - writeln!(out, "{pad}}}").expect("writing to a string cannot fail"); } fn render_generated_sync_decision(out: &mut String, pad: &str, state: usize, loop_back_expr: &str) { @@ -6269,20 +6640,22 @@ fn render_generated_star_loop( writeln!(out, "{pad} {enter_alt} => {{").expect("writing to a string cannot fail"); // Once an iteration is taken, every subsequent sync is a loop-back. writeln!(out, "{pad} {loop_iter} = true;").expect("writing to a string cannot fail"); - render_generated_alt_number_assignment( + render_generated_alt_number_assignments( out, &format!("{pad} "), enter_alt, render_context.track_alt_numbers && track_alt_number, + render_context.track_context_alt_numbers && track_alt_number, ); render_generated_steps(out, body, indent + 3, render_context); writeln!(out, "{pad} }}").expect("writing to a string cannot fail"); writeln!(out, "{pad} {exit_alt} => {{").expect("writing to a string cannot fail"); - render_generated_alt_number_assignment( + render_generated_alt_number_assignments( out, &format!("{pad} "), exit_alt, render_context.track_alt_numbers && track_alt_number, + render_context.track_context_alt_numbers && track_alt_number, ); writeln!(out, "{pad} break;").expect("writing to a string cannot fail"); writeln!(out, "{pad} }}").expect("writing to a string cannot fail"); @@ -6560,7 +6933,7 @@ fn loop_entry_condition( #[allow(clippy::fn_params_excessive_bools)] fn render_parser_parse_rule_fallback( track_alt_numbers: bool, - _predicates: &[((usize, usize), PredicateTemplate)], + track_context_alt_numbers: bool, rule_args: &[(usize, usize, RuleArgTemplate)], has_action_dispatch: bool, has_predicate_dispatch: bool, @@ -6570,16 +6943,16 @@ fn render_parser_parse_rule_fallback( if has_predicate_dispatch || unknown_policy_literal.is_some() { writeln!( out, - "let (tree, actions) = self.base.parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence, antlr4_runtime::ParserRuntimeOptions {{ track_alt_numbers: {track_alt_numbers}, predicates: &[], semantics: Some(parser_semantics()), rule_args: &{}, member_actions: &[], return_actions: &[], unknown_predicate_policy: {} , ..antlr4_runtime::ParserRuntimeOptions::default() }})?;", + "let (tree, actions) = self.base.parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence, antlr4_runtime::ParserRuntimeOptions {{ track_alt_numbers: {track_alt_numbers}, track_context_alt_numbers: {track_context_alt_numbers}, predicates: &[], semantics: Some(parser_semantics()), rule_args: &{}, member_actions: &[], return_actions: &[], unknown_predicate_policy: {} , ..antlr4_runtime::ParserRuntimeOptions::default() }})?;", render_parser_rule_arg_array(rule_args), unknown_policy_literal .unwrap_or("antlr4_runtime::UnknownSemanticPolicy::AssumeTrue") ) .expect("writing to a string cannot fail"); - } else if track_alt_numbers { + } else if track_alt_numbers || track_context_alt_numbers { writeln!( out, - "let (tree, actions) = self.base.parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence, antlr4_runtime::ParserRuntimeOptions {{ track_alt_numbers: true, ..antlr4_runtime::ParserRuntimeOptions::default() }})?;" + "let (tree, actions) = self.base.parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence, antlr4_runtime::ParserRuntimeOptions {{ track_alt_numbers: {track_alt_numbers}, track_context_alt_numbers: {track_context_alt_numbers}, ..antlr4_runtime::ParserRuntimeOptions::default() }})?;" ) .expect("writing to a string cannot fail"); } else if has_action_dispatch { @@ -7050,6 +7423,7 @@ fn build_embedded_parser_data( data: &CodegenData<'_>, type_name: &str, grammar_name: &str, + options: ParserRenderOptions<'_>, ) -> io::Result { let model = structural_embedded_model(data, true)?; let token_types: BTreeMap = data @@ -7219,14 +7593,19 @@ fn build_embedded_parser_data( // Recognizer-surface facades the rendered bodies call. out.impl_items.push_str(&embedded_parser_facades()); out.module_items.push_str(EMBEDDED_INPUT_FACADE); - out.module_items - .push_str(&render_embedded_context_types(grammar_name, data, &model)); + out.module_items.push_str(&render_embedded_context_types( + grammar_name, + data, + &model, + options, + )); Ok(out) } fn build_structural_parser_surface( data: &CodegenData<'_>, grammar_name: &str, + options: ParserRenderOptions<'_>, ) -> io::Result { let model = structural_embedded_model(data, false)?; let mut out = EmbeddedParserData { @@ -7254,8 +7633,12 @@ fn build_structural_parser_surface( ); } out.module_items.push_str(EMBEDDED_INPUT_FACADE); - out.module_items - .push_str(&render_embedded_context_types(grammar_name, data, &model)); + out.module_items.push_str(&render_embedded_context_types( + grammar_name, + data, + &model, + options, + )); Ok(out) } @@ -7297,6 +7680,7 @@ fn embedded_rule_call_expression(value: &str) -> Option { struct ContextSurfaceName { context_type: String, listener_method: String, + visitor_method: String, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -7309,15 +7693,18 @@ struct ContextViewName { #[derive(Debug, Eq, PartialEq)] struct ContextSurfaceNames { rules: Vec, - alternatives: Vec>, views: Vec, } impl ContextSurfaceNames { - fn alternative(&self, rule_index: usize, label: &str) -> &ContextSurfaceName { - self.alternatives[rule_index] - .get(label) - .expect("alternative label has an allocated context name") + fn kind_id(&self, rule_index: usize, alternative_label: Option<&str>) -> usize { + self.views + .iter() + .position(|view| { + view.rule_index == rule_index + && view.alternative_label.as_deref() == alternative_label + }) + .expect("context view has an allocated dispatch identity") } } @@ -7325,14 +7712,20 @@ impl ContextSurfaceNames { /// always use a `Label`/`_label` suffix so their generated surfaces cannot be /// confused with rule surfaces. fn context_surface_names(model: &embedded::EmbeddedModel) -> ContextSurfaceNames { - let mut used_context_types = BTreeSet::new(); - let mut used_listener_methods = BTreeSet::new(); + let mut used_context_types = BTreeSet::from(["StoredTreeContext".to_owned()]); + let mut used_listener_methods = BTreeSet::from(["every_rule".to_owned()]); + let mut used_visitor_methods = BTreeSet::from([ + "children".to_owned(), + "error_node".to_owned(), + "terminal".to_owned(), + ]); let rules = model .rules .iter() .map(|rule| ContextSurfaceName { context_type: allocate_rule_context_type(&rule.name, &mut used_context_types), listener_method: allocate_rule_listener_method(&rule.name, &mut used_listener_methods), + visitor_method: allocate_rule_listener_method(&rule.name, &mut used_visitor_methods), }) .collect::>(); @@ -7357,6 +7750,10 @@ fn context_surface_names(model: &embedded::EmbeddedModel) -> ContextSurfaceNames label, &mut used_listener_methods, ), + visitor_method: allocate_label_listener_method( + label, + &mut used_visitor_methods, + ), }; entry.insert(surface.clone()); views.push(ContextViewName { @@ -7368,11 +7765,7 @@ fn context_surface_names(model: &embedded::EmbeddedModel) -> ContextSurfaceNames } } - ContextSurfaceNames { - rules, - alternatives, - views, - } + ContextSurfaceNames { rules, views } } fn allocate_rule_context_type(source_name: &str, used: &mut BTreeSet) -> String { @@ -7426,14 +7819,641 @@ fn allocate_numbered_listener_method(stem: &str, used: &mut BTreeSet) -> candidate } +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +struct ContextAlternativeDispatch { + runtime_alt_number: usize, + kind_id: usize, + operator: bool, +} + +fn context_alternative_dispatch( + rule_index: usize, + rule: &embedded::RuleModel, + names: &ContextSurfaceNames, +) -> (bool, Vec) { + let left_recursive = rule + .alts + .iter() + .any(|alternative| alternative.is_lr_operator(&rule.name)); + let mut primary_alt_number = 0; + let mut operator_alt_number = 0; + let alternatives = rule + .alts + .iter() + .enumerate() + .map(|(authored_alt_index, alternative)| { + let operator = left_recursive && alternative.is_lr_operator(&rule.name); + let runtime_alt_number = if operator { + operator_alt_number += 1; + operator_alt_number + } else if left_recursive { + primary_alt_number += 1; + primary_alt_number + } else { + authored_alt_index + 1 + }; + ContextAlternativeDispatch { + runtime_alt_number, + kind_id: names.kind_id(rule_index, alternative.label.as_deref()), + operator, + } + }) + .collect(); + (left_recursive, alternatives) +} + +fn render_context_alt_kind_match( + alternatives: &[ContextAlternativeDispatch], + fallback_kind: usize, + alt_number: &str, +) -> String { + if alternatives.is_empty() + || alternatives + .iter() + .all(|alternative| alternative.kind_id == fallback_kind) + { + return fallback_kind.to_string(); + } + let mut arms = String::new(); + for alternative in alternatives { + let _ = writeln!( + arms, + " {} => {},", + alternative.runtime_alt_number, alternative.kind_id + ); + } + let distinct_kinds = alternatives + .iter() + .map(|alternative| alternative.kind_id) + .collect::>(); + if distinct_kinds.len() == 1 { + let only_kind = distinct_kinds + .first() + .copied() + .expect("non-empty alternatives have one context kind"); + let _ = writeln!(arms, " 0 => {only_kind},"); + } + format!( + "match {alt_number} {{\n{arms} _ => {fallback_kind},\n }}" + ) +} + +fn render_context_kind_functions( + model: &embedded::EmbeddedModel, + names: &ContextSurfaceNames, +) -> String { + if names + .views + .iter() + .all(|view| view.alternative_label.is_none()) + { + return r#"#[allow(dead_code)] +fn __context_kind(context: RuleNodeView<'_>) -> usize { + context.rule_index() +} + +#[allow(dead_code)] +fn __active_context_kind( + context: &antlr4_runtime::ParserRuleContext, + _storage: &antlr4_runtime::ParseTreeStorage, + _tokens: &antlr4_runtime::TokenStore, +) -> usize { + context.rule_index() +} + +"# + .to_owned(); + } + + let mut stored_arms = String::new(); + let mut active_arms = String::new(); + for (rule_index, rule) in model.rules.iter().enumerate() { + let fallback_kind = names.kind_id(rule_index, None); + let (left_recursive, alternatives) = context_alternative_dispatch(rule_index, rule, names); + if !left_recursive { + let matcher = render_context_alt_kind_match( + &alternatives, + fallback_kind, + "context.context_alt_number()", + ); + let _ = writeln!( + stored_arms, + " {rule_index} => {{\n {matcher}\n }}," + ); + let _ = writeln!( + active_arms, + " {rule_index} => {{\n {matcher}\n }}," + ); + continue; + } + + let primary = alternatives + .iter() + .copied() + .filter(|alternative| !alternative.operator) + .collect::>(); + let operators = alternatives + .iter() + .copied() + .filter(|alternative| alternative.operator) + .collect::>(); + let primary_match = + render_context_alt_kind_match(&primary, fallback_kind, "context.context_alt_number()"); + let operator_match = render_context_alt_kind_match( + &operators, + fallback_kind, + "context.context_alt_number()", + ); + let _ = writeln!( + stored_arms, + " {rule_index} => {{\n let operator = context.children().next().and_then(antlr4_runtime::Node::as_rule).is_some_and(|child| child.rule_index() == {rule_index});\n if operator {{\n {operator_match}\n }} else {{\n {primary_match}\n }}\n }}," + ); + let _ = writeln!( + active_arms, + " {rule_index} => {{\n let operator = context.child_nodes(storage, tokens).next().and_then(antlr4_runtime::Node::as_rule).is_some_and(|child| child.rule_index() == {rule_index});\n if operator {{\n {operator_match}\n }} else {{\n {primary_match}\n }}\n }}," + ); + } + + format!( + r#"#[allow(dead_code)] +fn __context_kind(context: RuleNodeView<'_>) -> usize {{ + match context.rule_index() {{ +{stored_arms} _ => usize::MAX, + }} +}} + +#[allow(dead_code)] +fn __active_context_kind( + context: &antlr4_runtime::ParserRuleContext, + storage: &antlr4_runtime::ParseTreeStorage, + tokens: &antlr4_runtime::TokenStore, +) -> usize {{ + match context.rule_index() {{ +{active_arms} _ => usize::MAX, + }} +}} + +"# + ) +} + +fn context_alternatives<'a>( + rule: &'a embedded::RuleModel, + alternative_label: Option<&str>, +) -> Vec<&'a embedded::AltModel> { + rule.alts + .iter() + .filter(|alternative| { + alternative_label.is_none_or(|label| alternative.label.as_deref() == Some(label)) + }) + .collect() +} + +fn context_child_cardinalities( + rule: &embedded::RuleModel, + alternative_label: Option<&str>, +) -> BTreeMap { + choice_child_cardinalities( + context_alternatives(rule, alternative_label) + .into_iter() + .map(|alternative| alternative.children.clone()), + ) +} + +#[derive(Clone, Debug, Eq, PartialEq)] +struct ContextLabelAccessor { + source_name: String, + target: String, + token_types: Vec, + cardinality: embedded::ChildCardinality, + selector: ContextLabelSelector, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +enum ContextLabelSelector { + Nth(usize), + LastAfter(usize), + AllAfter(usize), +} + +fn context_label_accessors( + rule: &embedded::RuleModel, + alternative_label: Option<&str>, +) -> Vec { + let alternatives = context_alternatives(rule, alternative_label); + let labels = alternatives + .iter() + .flat_map(|alternative| { + alternative + .refs + .iter() + .filter_map(|element| element.label.clone()) + }) + .collect::>(); + labels + .into_iter() + .filter_map(|label| context_label_accessor(&alternatives, label)) + .collect() +} + +fn context_label_accessor( + alternatives: &[&embedded::AltModel], + label: String, +) -> Option { + let declarations = alternatives + .iter() + .flat_map(|alternative| alternative.refs.iter()) + .filter(|element| element.label.as_deref() == Some(label.as_str())) + .collect::>(); + let first = declarations.first()?; + if (first.target.is_empty() && first.token_types.is_empty()) + || declarations.iter().any(|element| { + !element.stable_accessor + || !same_context_ref_target(element, first) + || element.is_list != first.is_list + }) + { + return None; + } + + let target = first.target.clone(); + let token_types = first.token_types.clone(); + let is_list = first.is_list; + let mut selector = None; + let mut cardinalities = Vec::with_capacity(alternatives.len()); + for alternative in alternatives { + let matching = alternative + .refs + .iter() + .enumerate() + .filter(|(_, element)| element.label.as_deref() == Some(label.as_str())) + .collect::>(); + if matching.is_empty() { + let target_cardinality = sum_child_cardinalities( + alternative + .refs + .iter() + .filter(|element| context_ref_can_match_target(element, first)) + .map(|element| element.cardinality), + ); + if target_cardinality.max != Some(0) { + return None; + } + cardinalities.push(embedded::ChildCardinality::ZERO); + continue; + } + + let alternative_selector = + context_label_selector(alternative, &matching, &label, first, is_list)?; + if selector.is_some_and(|existing| existing != alternative_selector) { + return None; + } + selector = Some(alternative_selector); + cardinalities.push(if is_list { + sum_child_cardinalities(matching.iter().map(|(_, element)| element.cardinality)) + } else { + matching[0].1.cardinality + }); + } + + let mut cardinality = choice_cardinality(&cardinalities); + if !is_list { + cardinality = embedded::ChildCardinality { + min: usize::from(cardinality.min > 0), + max: Some(usize::from(cardinality.max != Some(0))), + }; + } + Some(ContextLabelAccessor { + source_name: label, + target, + token_types, + cardinality, + selector: selector?, + }) +} + +fn context_label_selector( + alternative: &embedded::AltModel, + matching: &[(usize, &embedded::ElementRef)], + label: &str, + target: &embedded::ElementRef, + is_list: bool, +) -> Option { + let first_position = matching[0].0; + let start = exact_target_cardinality(&alternative.refs[..first_position], target)?; + if is_list { + let has_unlabeled_target = alternative.refs[first_position..].iter().any(|element| { + context_ref_can_match_target(element, target) + && element.cardinality.max != Some(0) + && element.label.as_deref() != Some(label) + }); + return (!has_unlabeled_target).then_some(ContextLabelSelector::AllAfter(start)); + } + if matching.len() != 1 { + return None; + } + let element = matching[0].1; + if !element.cardinality.is_repeated() { + return Some(ContextLabelSelector::Nth(start)); + } + let has_following_target = alternative.refs[first_position + 1..] + .iter() + .any(|following| { + context_ref_can_match_target(following, target) && following.cardinality.max != Some(0) + }); + (!has_following_target).then_some(ContextLabelSelector::LastAfter(start)) +} + +fn same_context_ref_target(left: &embedded::ElementRef, right: &embedded::ElementRef) -> bool { + if left.token_types.is_empty() && right.token_types.is_empty() { + left.target == right.target + } else { + left.token_types == right.token_types + } +} + +fn context_ref_can_match_target( + element: &embedded::ElementRef, + target: &embedded::ElementRef, +) -> bool { + if element.token_types.is_empty() || target.token_types.is_empty() { + return same_context_ref_target(element, target); + } + element + .token_types + .iter() + .any(|token_type| target.token_types.contains(token_type)) +} + +fn exact_target_cardinality( + refs: &[embedded::ElementRef], + target: &embedded::ElementRef, +) -> Option { + refs.iter().try_fold(0_usize, |total, element| { + if !context_ref_can_match_target(element, target) { + return Some(total); + } + if !element.token_types.is_empty() + && !element + .token_types + .iter() + .all(|token_type| target.token_types.contains(token_type)) + { + return None; + } + let exact = element.cardinality.max?; + (element.cardinality.min == exact).then(|| total.saturating_add(exact)) + }) +} + +fn sum_child_cardinalities( + cardinalities: impl IntoIterator, +) -> embedded::ChildCardinality { + cardinalities.into_iter().fold( + embedded::ChildCardinality::ZERO, + |mut total, cardinality| { + total.min = total.min.saturating_add(cardinality.min); + total.max = match (total.max, cardinality.max) { + (Some(current), Some(next)) => Some(current.saturating_add(next)), + _ => None, + }; + total + }, + ) +} + +fn choice_cardinality(alternatives: &[embedded::ChildCardinality]) -> embedded::ChildCardinality { + let mut min = usize::MAX; + let mut max = Some(0_usize); + for cardinality in alternatives { + min = min.min(cardinality.min); + max = match (max, cardinality.max) { + (Some(current), Some(next)) => Some(current.max(next)), + _ => None, + }; + } + embedded::ChildCardinality { + min: if min == usize::MAX { 0 } else { min }, + max, + } +} + +fn allocate_context_method( + preferred: String, + fallback_stem: &str, + used: &mut BTreeSet, +) -> String { + if used.insert(preferred.clone()) { + return preferred; + } + allocate_numbered_listener_method(fallback_stem, used) +} + +fn accessor_stem(name: &str) -> String { + rust_function_name(name).trim_start_matches("r#").to_owned() +} + +fn render_rule_label_accessor( + out: &mut String, + method: &str, + view_name: &str, + child_view: &str, + child_index: usize, + label: &ContextLabelAccessor, +) { + if let ContextLabelSelector::AllAfter(skip) = label.selector { + let _ = writeln!( + out, + " pub fn {method}(&self) -> impl Iterator> + '_ {{\n __rule_children(self.__node, {child_index})\n .skip({skip})\n .map(move |node| {child_view}::__from_child_node(node, &self.__invocation_states))\n }}" + ); + return; + } + let lookup = match label.selector { + ContextLabelSelector::Nth(occurrence) => format!(".nth({occurrence})"), + ContextLabelSelector::LastAfter(skip) => format!(".skip({skip}).last()"), + ContextLabelSelector::AllAfter(_) => unreachable!("handled above"), + }; + if label.cardinality.is_required_single() { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Result<{child_view}<'a>, MissingChildError> {{\n __rule_children(self.__node, {child_index})\n {lookup}\n .map(|node| {child_view}::__from_child_node(node, &self.__invocation_states))\n .ok_or_else(|| MissingChildError::new(\"{view_name}\", \"{}\"))\n }}", + label.source_name + ); + } else { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Option<{child_view}<'a>> {{\n __rule_children(self.__node, {child_index})\n {lookup}\n .map(|node| {child_view}::__from_child_node(node, &self.__invocation_states))\n }}" + ); + } +} + +fn render_token_label_accessor( + out: &mut String, + method: &str, + view_name: &str, + label: &ContextLabelAccessor, +) { + let token_types = label + .token_types + .iter() + .map(ToString::to_string) + .collect::>() + .join(", "); + let children = if let [token_type] = label.token_types.as_slice() { + format!("__token_children(self.__node, {token_type})") + } else { + format!("__token_children_matching(self.__node, &[{token_types}])") + }; + if let ContextLabelSelector::AllAfter(skip) = label.selector { + let _ = writeln!( + out, + " pub fn {method}(&self) -> impl Iterator> + '_ {{\n {children}\n .skip({skip})\n .map(TerminalNode::new)\n }}" + ); + return; + } + let lookup = match label.selector { + ContextLabelSelector::Nth(occurrence) => format!(".nth({occurrence})"), + ContextLabelSelector::LastAfter(skip) => format!(".skip({skip}).last()"), + ContextLabelSelector::AllAfter(_) => unreachable!("handled above"), + }; + if label.cardinality.is_required_single() { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Result, MissingChildError> {{\n {children}\n {lookup}\n .map(TerminalNode::new)\n .ok_or_else(|| MissingChildError::new(\"{view_name}\", \"{}\"))\n }}", + label.source_name + ); + } else { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Option> {{\n {children}\n {lookup}\n .map(TerminalNode::new)\n }}" + ); + } +} + +fn render_context_child_accessors( + view_name: &str, + model: &embedded::EmbeddedModel, + context_names: &ContextSurfaceNames, + token_accessors: &[(String, i32)], + child_cardinalities: &BTreeMap, + label_accessors: &[ContextLabelAccessor], +) -> String { + let mut out = String::new(); + let _ = writeln!( + out, + " pub fn child_count(&self) -> usize {{\n match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.child_count(),\n __GeneratedRuleContext::Active {{ context, .. }} => context.child_count(),\n }}\n }}\n\n pub fn start(&self) -> __GeneratedTokenView {{\n let token = match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.start(),\n __GeneratedRuleContext::Active {{ context, tokens, .. }} => context.start(tokens),\n }};\n __GeneratedTokenView {{ text: token.map(|token| token.text().to_owned()).unwrap_or_default() }}\n }}" + ); + let mut used_methods = BTreeSet::from([ + "child_count".to_owned(), + "rule_node".to_owned(), + "start".to_owned(), + ]); + for (child_index, child) in model + .rules + .iter() + .enumerate() + .filter(|(_, child)| child_cardinalities.contains_key(child.name.as_str())) + { + let cardinality = child_cardinalities[child.name.as_str()]; + let stem = accessor_stem(&child.name); + let preferred = if cardinality.is_repeated() { + format!("{stem}_children") + } else { + rust_function_name(&child.name) + }; + let method = + allocate_context_method(preferred, &format!("{stem}_rule_child"), &mut used_methods); + let child_view = &context_names.rules[child_index].context_type; + if cardinality.is_repeated() { + let _ = writeln!( + out, + " pub fn {method}(&self) -> impl Iterator> + '_ {{\n __rule_children(self.__node, {child_index})\n .map(move |node| {child_view}::__from_child_node(node, &self.__invocation_states))\n }}" + ); + } else if cardinality.is_required_single() { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Result<{child_view}<'a>, MissingChildError> {{\n __rule_children(self.__node, {child_index})\n .next()\n .map(|node| {child_view}::__from_child_node(node, &self.__invocation_states))\n .ok_or_else(|| MissingChildError::new(\"{view_name}\", \"{}\"))\n }}", + child.name + ); + } else { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Option<{child_view}<'a>> {{\n __rule_children(self.__node, {child_index})\n .next()\n .map(|node| {child_view}::__from_child_node(node, &self.__invocation_states))\n }}" + ); + } + } + for (token_name, token_type) in token_accessors + .iter() + .filter(|(token_name, _)| child_cardinalities.contains_key(token_name.as_str())) + { + let cardinality = child_cardinalities[token_name.as_str()]; + let stem = accessor_stem(token_name); + let preferred = if cardinality.is_repeated() { + format!("{stem}_tokens") + } else { + format!("{stem}_token") + }; + let method = allocate_context_method( + preferred, + &format!("{stem}_terminal_child"), + &mut used_methods, + ); + if cardinality.is_repeated() { + let _ = writeln!( + out, + " pub fn {method}(&self) -> impl Iterator> + '_ {{\n __token_children(self.__node, {token_type}).map(TerminalNode::new)\n }}" + ); + } else if cardinality.is_required_single() { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Result, MissingChildError> {{\n __token_children(self.__node, {token_type})\n .next()\n .map(TerminalNode::new)\n .ok_or_else(|| MissingChildError::new(\"{view_name}\", \"{token_name}\"))\n }}" + ); + } else { + let _ = writeln!( + out, + " pub fn {method}(&self) -> Option> {{\n __token_children(self.__node, {token_type})\n .next()\n .map(TerminalNode::new)\n }}" + ); + } + } + for label in label_accessors { + let stem = accessor_stem(&label.source_name); + let method = allocate_context_method( + rust_function_name(&label.source_name), + &format!("{stem}_label"), + &mut used_methods, + ); + if label.token_types.is_empty() + && let Some(child_index) = model + .rules + .iter() + .position(|child| child.name == label.target) + { + let child_view = &context_names.rules[child_index].context_type; + render_rule_label_accessor( + &mut out, + &method, + view_name, + child_view, + child_index, + label, + ); + continue; + } + if label.token_types.is_empty() { + continue; + } + render_token_label_accessor(&mut out, &method, view_name, label); + } + out +} + /// Generates the typed context views, listener trait, and walker for the /// embedded `.test.stg` surface: /// /// * one `Context` view per parser rule (plus one per labeled -/// alternative) with positional child accessors (`ctx.e(0)` / -/// `ctx.e_all()`, `ctx.INT(0)` / `ctx.INT_all()`), `child_count()`, -/// `start()`, public attribute fields, and a `FromRuleNode` impl backing -/// `ctx.downcast_ref::()`; +/// alternative) with cardinality-aware rule, token, and label accessors, +/// `child_count()`, `start()`, public attribute fields, and a `FromRuleNode` +/// impl backing `ctx.downcast_ref::()`; /// * the `Listener` trait with defaulted `enter_/exit_` (and /// per-labeled-alternative) callbacks plus terminal/error-node visitors; /// * a module-local `ParseTreeWalker` whose bridge dispatches the runtime @@ -7443,22 +8463,33 @@ fn render_embedded_context_types( grammar_name: &str, data: &CodegenData<'_>, model: &embedded::EmbeddedModel, + options: ParserRenderOptions<'_>, ) -> String { let mut out = String::new(); let context_names = context_surface_names(model); - let listener_trait = format!( - "{}Listener", - grammar_name.strip_suffix("Parser").unwrap_or(grammar_name) - ); - let token_accessors: Vec<(String, i32)> = data - .symbolic_names - .iter() - .enumerate() - .filter_map(|(token_type, name)| { - let name = name.as_ref()?; - i32::try_from(token_type).ok().map(|ty| (name.clone(), ty)) - }) - .collect(); + let surface_name = grammar_name.strip_suffix("Parser").unwrap_or(grammar_name); + let listener_trait = format!("{surface_name}Listener"); + let visitor_trait = format!("{surface_name}Visitor"); + let visitable_trait = format!("{surface_name}Visitable"); + let tree_walker = format!("{surface_name}TreeWalker"); + let token_accessors = std::iter::once(("EOF".to_owned(), TOKEN_EOF)) + .chain( + data.symbolic_names + .iter() + .enumerate() + .filter_map(|(token_type, name)| { + let name = name.as_ref()?; + i32::try_from(token_type).ok().map(|ty| (name.clone(), ty)) + }), + ) + .collect::>(); + + if options.generate_visitor { + let _ = writeln!( + out, + "#[allow(dead_code)]\npub trait {visitable_trait}<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a>;\n}}\n\nimpl<'a> {visitable_trait}<'a> for antlr4_runtime::Node<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self }}\n}}\n\nimpl<'a> {visitable_trait}<'a> for RuleNodeView<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.node() }}\n}}\n" + ); + } out.push_str( r#"#[allow(dead_code)] @@ -7508,7 +8539,7 @@ impl std::fmt::Display for ErrorNode<'_> { } #[allow(dead_code)] -#[derive(Clone)] +#[derive(Clone, Copy)] enum __GeneratedRuleContext<'a> { Stored(RuleNodeView<'a>), Active { @@ -7518,6 +8549,84 @@ enum __GeneratedRuleContext<'a> { }, } +#[doc(hidden)] +#[derive(Clone, Copy, Debug)] +pub struct StoredTreeContext; + +#[derive(Clone, Copy, Debug)] +struct __ActiveParserContext; + +#[allow(dead_code)] +fn __context_children<'a>( + source: __GeneratedRuleContext<'a>, +) -> impl Iterator> + 'a { + let mut stored = match source { + __GeneratedRuleContext::Stored(node) => Some(node.children()), + __GeneratedRuleContext::Active { .. } => None, + }; + let mut active = match source { + __GeneratedRuleContext::Stored(_) => None, + __GeneratedRuleContext::Active { + context, + storage, + tokens, + } => Some(context.child_nodes(storage, tokens)), + }; + std::iter::from_fn(move || { + stored + .as_mut() + .and_then(Iterator::next) + .or_else(|| active.as_mut().and_then(Iterator::next)) + }) +} + +#[allow(dead_code)] +fn __rule_children<'a>( + source: __GeneratedRuleContext<'a>, + rule_index: usize, +) -> impl Iterator> + 'a { + __context_children(source).filter_map(move |child| { + let rule = child.as_rule()?; + (rule.rule_index() == rule_index).then_some(rule) + }) +} + +#[allow(dead_code)] +fn __token_children<'a>( + source: __GeneratedRuleContext<'a>, + token_type: i32, +) -> impl Iterator> + 'a { + __context_children(source).filter_map(move |child| { + let terminal = match child.kind() { + antlr4_runtime::NodeKind::Terminal => child.as_terminal(), + antlr4_runtime::NodeKind::Error => { + child.as_error().map(antlr4_runtime::ErrorNodeView::terminal) + } + antlr4_runtime::NodeKind::Rule => None, + }?; + (terminal.symbol().token_type() == token_type).then_some(terminal) + }) +} + +#[allow(dead_code)] +fn __token_children_matching<'a>( + source: __GeneratedRuleContext<'a>, + token_types: &'static [i32], +) -> impl Iterator> + 'a { + __context_children(source).filter_map(move |child| { + let terminal = match child.kind() { + antlr4_runtime::NodeKind::Terminal => child.as_terminal(), + antlr4_runtime::NodeKind::Error => { + child.as_error().map(antlr4_runtime::ErrorNodeView::terminal) + } + antlr4_runtime::NodeKind::Rule => None, + }?; + token_types + .contains(&terminal.symbol().token_type()) + .then_some(terminal) + }) +} + #[allow(dead_code)] trait __FromActiveRuleContext<'a>: Sized { fn __from_active( @@ -7540,6 +8649,13 @@ fn __active_context_view<'a, T: __FromActiveRuleContext<'a>>( "#, ); + if options.generate_visitor { + let _ = writeln!( + out, + "impl<'a> {visitable_trait}<'a> for TerminalNode<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.__node.node() }}\n}}\n\nimpl<'a> {visitable_trait}<'a> for &TerminalNode<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.__node.node() }}\n}}\n\nimpl<'a> {visitable_trait}<'a> for ErrorNode<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.__node.node() }}\n}}\n\nimpl<'a> {visitable_trait}<'a> for &ErrorNode<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.__node.node() }}\n}}\n" + ); + } + out.push_str(&render_context_kind_functions(model, &context_names)); for ContextViewName { surface, @@ -7549,18 +8665,15 @@ fn __active_context_view<'a, T: __FromActiveRuleContext<'a>>( { let view_name = &surface.context_type; let rule = &model.rules[*rule_index]; - let referenced_targets: BTreeSet<&str> = rule - .alts - .iter() - .filter(|alt| { - alternative_label - .as_ref() - .is_none_or(|label| alt.label.as_ref() == Some(label)) - }) - .flat_map(|alt| alt.refs.iter()) - .map(|element| element.target.as_str()) - .filter(|target| !target.is_empty()) - .collect(); + let context_kind = context_names.kind_id(*rule_index, alternative_label.as_deref()); + let stored_kind_guard = alternative_label.as_ref().map_or(String::new(), |_| { + format!(" || __context_kind(node) != {context_kind}") + }); + let active_kind_guard = alternative_label.as_ref().map_or(String::new(), |_| { + format!(" || __active_context_kind(context, storage, tokens) != {context_kind}") + }); + let child_cardinalities = context_child_cardinalities(rule, alternative_label.as_deref()); + let label_accessors = context_label_accessors(rule, alternative_label.as_deref()); let attrs_struct = embedded::attrs_struct_name(*rule_index); let mut fields = String::new(); let mut field_inits = String::new(); @@ -7571,237 +8684,264 @@ fn __active_context_view<'a, T: __FromActiveRuleContext<'a>>( } let _ = writeln!( out, - "#[allow(non_camel_case_types, dead_code)]\n#[derive(Clone)]\npub struct {view_name}<'a> {{\n __node: __GeneratedRuleContext<'a>,\n __invocation_states: Vec,\n{fields}}}\n" + "#[allow(non_camel_case_types, dead_code)]\n#[derive(Clone)]\npub struct {view_name}<'a, State = StoredTreeContext> {{\n __node: __GeneratedRuleContext<'a>,\n __invocation_states: Vec,\n __state: std::marker::PhantomData,\n{fields}}}\n" ); let _ = writeln!( out, - "impl<'a> FromRuleNode<'a> for {view_name}<'a> {{\n fn from_rule_node(node: RuleNodeView<'a>) -> Option {{\n if node.rule_index() != {rule_index} {{ return None; }}\n Some(Self::__from_node(node))\n }}\n}}\n\nimpl<'a> __FromActiveRuleContext<'a> for {view_name}<'a> {{\n fn __from_active(\n context: &'a antlr4_runtime::ParserRuleContext,\n invocation_states: Vec,\n storage: &'a antlr4_runtime::ParseTreeStorage,\n tokens: &'a antlr4_runtime::TokenStore,\n ) -> Option {{\n if context.rule_index() != {rule_index} {{ return None; }}\n let __default = {attrs_struct}::default();\n let __attrs = context.generated_attrs::<{attrs_struct}>().unwrap_or(&__default);\n Some(Self {{\n __node: __GeneratedRuleContext::Active {{ context, storage, tokens }},\n __invocation_states: invocation_states,\n{field_inits} }})\n }}\n}}\n" + "impl<'a> FromRuleNode<'a> for {view_name}<'a> {{\n fn from_rule_node(node: RuleNodeView<'a>) -> Option {{\n if node.rule_index() != {rule_index}{stored_kind_guard} {{ return None; }}\n Some(Self::__from_node(node))\n }}\n}}\n\nimpl<'a> AsRuleNode<'a> for {view_name}<'a> {{\n fn as_rule_node(&self) -> RuleNodeView<'a> {{ self.rule_node() }}\n}}\n\nimpl<'a> {view_name}<'a> {{\n pub fn rule_node(&self) -> RuleNodeView<'a> {{\n match self.__node {{\n __GeneratedRuleContext::Stored(node) => node,\n __GeneratedRuleContext::Active {{ .. }} => unreachable!(\"stored context type contains an active parser context\"),\n }}\n }}\n}}\n\nimpl<'a> __FromActiveRuleContext<'a> for {view_name}<'a, __ActiveParserContext> {{\n fn __from_active(\n context: &'a antlr4_runtime::ParserRuleContext,\n invocation_states: Vec,\n storage: &'a antlr4_runtime::ParseTreeStorage,\n tokens: &'a antlr4_runtime::TokenStore,\n ) -> Option {{\n if context.rule_index() != {rule_index}{active_kind_guard} {{ return None; }}\n let __default = {attrs_struct}::default();\n let __attrs = context.generated_attrs::<{attrs_struct}>().unwrap_or(&__default);\n Some(Self {{\n __node: __GeneratedRuleContext::Active {{ context, storage, tokens }},\n __invocation_states: invocation_states,\n __state: std::marker::PhantomData,\n{field_inits} }})\n }}\n}}\n" ); let mut accessors = String::new(); let _ = writeln!( accessors, - " fn __from_node(node: RuleNodeView<'a>) -> Self {{\n let invocation_states = node.invocation_states().collect();\n Self::__from_node_with_invocation_states(node, invocation_states)\n }}\n\n fn __from_child_node(node: RuleNodeView<'a>, parent_invocation_states: &[isize]) -> Self {{\n let mut invocation_states = Vec::with_capacity(parent_invocation_states.len() + 1);\n invocation_states.push(node.invoking_state());\n invocation_states.extend_from_slice(parent_invocation_states);\n Self::__from_node_with_invocation_states(node, invocation_states)\n }}\n\n fn __from_listener_node(node: RuleNodeView<'a>, invocation_states: Option<&[isize]>) -> Self {{\n invocation_states.map_or_else(\n || Self::__from_node(node),\n |states| Self::__from_node_with_invocation_states(node, states.to_vec()),\n )\n }}\n\n fn __from_node_with_invocation_states(node: RuleNodeView<'a>, invocation_states: Vec) -> Self {{\n let __default = {attrs_struct}::default();\n let __attrs = node.generated_attrs::<{attrs_struct}>().unwrap_or(&__default);\n Self {{\n __node: __GeneratedRuleContext::Stored(node),\n __invocation_states: invocation_states,\n{field_inits} }}\n }}\n" + " fn __from_node(node: RuleNodeView<'a>) -> Self {{\n let invocation_states = node.invocation_states().collect();\n Self::__from_node_with_invocation_states(node, invocation_states)\n }}\n\n fn __from_child_node(node: RuleNodeView<'a>, parent_invocation_states: &[isize]) -> Self {{\n let mut invocation_states = Vec::with_capacity(parent_invocation_states.len() + 1);\n invocation_states.push(node.invoking_state());\n invocation_states.extend_from_slice(parent_invocation_states);\n Self::__from_node_with_invocation_states(node, invocation_states)\n }}\n\n fn __from_listener_node(node: RuleNodeView<'a>, invocation_states: Option<&[isize]>) -> Self {{\n invocation_states.map_or_else(\n || Self::__from_node(node),\n |states| Self::__from_node_with_invocation_states(node, states.to_vec()),\n )\n }}\n\n fn __from_node_with_invocation_states(node: RuleNodeView<'a>, invocation_states: Vec) -> Self {{\n let __default = {attrs_struct}::default();\n let __attrs = node.generated_attrs::<{attrs_struct}>().unwrap_or(&__default);\n Self {{\n __node: __GeneratedRuleContext::Stored(node),\n __invocation_states: invocation_states,\n __state: std::marker::PhantomData,\n{field_inits} }}\n }}\n" ); - // A grammar rule claiming a built-in helper's name (`start`, - // `child_count`) takes the accessor slot; the built-in yields. - let rule_claims = |name: &str| { - model - .rules - .iter() - .any(|rule| rust_function_name(&rule.name) == name) - }; - if !rule_claims("child_count") { + let common_accessors = render_context_child_accessors( + view_name, + model, + &context_names, + &token_accessors, + &child_cardinalities, + &label_accessors, + ); + let _ = writeln!( + out, + "#[allow(dead_code, clippy::all)]\nimpl<'a> {view_name}<'a> {{\n{accessors}}}\n\n#[allow(dead_code, clippy::all)]\nimpl<'a, State> {view_name}<'a, State> {{\n{common_accessors}}}\n" + ); + if options.generate_visitor { let _ = writeln!( - accessors, - " pub fn child_count(&self) -> usize {{\n match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.child_count(),\n __GeneratedRuleContext::Active {{ context, .. }} => context.child_count(),\n }}\n }}" + out, + "impl<'a> {visitable_trait}<'a> for {view_name}<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.rule_node().node() }}\n}}\n\nimpl<'a> {visitable_trait}<'a> for &{view_name}<'a> {{\n fn into_parse_tree_node(self) -> antlr4_runtime::Node<'a> {{ self.rule_node().node() }}\n}}\n" ); } - if !rule_claims("start") { + // Java's RuleContext.toString(): bracketed invoking-state chain from + // this context to the root, the root's sentinel excluded. + let _ = writeln!( + out, + "impl std::fmt::Display for {view_name}<'_, State> {{\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {{\n let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect();\n write!(f, \"[{{}}]\", chain.join(\" \"))\n }}\n}}\n" + ); + } + + if options.generate_listener { + let mut trait_methods = String::new(); + let mut enter_arms = String::new(); + let mut exit_arms = String::new(); + for (kind_id, view) in context_names.views.iter().enumerate() { + let ContextSurfaceName { + context_type, + listener_method, + .. + } = &view.surface; let _ = writeln!( - accessors, - " pub fn start(&self) -> __GeneratedTokenView {{\n let token = match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.start(),\n __GeneratedRuleContext::Active {{ context, tokens, .. }} => context.start(tokens),\n }};\n __GeneratedTokenView {{ text: token.map(|token| token.text().to_owned()).unwrap_or_default() }}\n }}" + trait_methods, + " fn enter_{listener_method}(&mut self, _ctx: &{context_type}) -> Result<(), E> {{ Ok(()) }}\n fn exit_{listener_method}(&mut self, _ctx: &{context_type}) -> Result<(), E> {{ Ok(()) }}" ); - } - for (child_index, child) in model - .rules - .iter() - .enumerate() - .filter(|(_, child)| referenced_targets.contains(child.name.as_str())) - { - let method = rust_function_name(&child.name); - let child_view = &context_names.rules[child_index].context_type; let _ = writeln!( - accessors, - " pub fn {method}(&self, index: usize) -> {child_view}<'a> {{\n let node = match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.child_rules({child_index}).nth(index),\n __GeneratedRuleContext::Active {{ context, storage, tokens, .. }} => context.child_rules(storage, tokens, {child_index}).nth(index),\n }}.expect(\"missing rule child\");\n {child_view}::__from_child_node(node, &self.__invocation_states)\n }}\n pub fn {method}_all(&self) -> Vec<{child_view}<'a>> {{\n let nodes: Vec<_> = match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.child_rules({child_index}).collect(),\n __GeneratedRuleContext::Active {{ context, storage, tokens, .. }} => context.child_rules(storage, tokens, {child_index}).collect(),\n }};\n nodes.into_iter().map(|node| {child_view}::__from_child_node(node, &self.__invocation_states)).collect()\n }}" + enter_arms, + " {kind_id} => listener.enter_{listener_method}(&{context_type}::__from_listener_node(context, invocation_states.as_deref()))?," ); - } - for (token_name, token_type) in token_accessors - .iter() - .filter(|(token_name, _)| referenced_targets.contains(token_name.as_str())) - { let _ = writeln!( - accessors, - " #[allow(non_snake_case)]\n pub fn {token_name}(&self, index: usize) -> TerminalNode<'a> {{\n let node = match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.child_tokens({token_type}).nth(index),\n __GeneratedRuleContext::Active {{ context, storage, tokens, .. }} => context.child_tokens(storage, tokens, {token_type}).nth(index),\n }}.expect(\"missing token child\");\n TerminalNode::new(node)\n }}\n #[allow(non_snake_case)]\n pub fn {token_name}_all(&self) -> Vec> {{\n let nodes: Vec<_> = match &self.__node {{\n __GeneratedRuleContext::Stored(node) => node.child_tokens({token_type}).collect(),\n __GeneratedRuleContext::Active {{ context, storage, tokens, .. }} => context.child_tokens(storage, tokens, {token_type}).collect(),\n }};\n nodes.into_iter().map(TerminalNode::new).collect()\n }}" + exit_arms, + " {kind_id} => listener.exit_{listener_method}(&{context_type}::__from_listener_node(context, invocation_states.as_deref()))?," ); } let _ = writeln!( out, - "#[allow(dead_code, clippy::all)]\nimpl<'a> {view_name}<'a> {{\n{accessors}}}\n" + "#[allow(dead_code, unused_variables)]\npub trait {listener_trait} {{\n fn walk(&mut self, tree: antlr4_runtime::Node<'_>) -> Result<(), E>\n where\n Self: Sized,\n {{\n {tree_walker}::walk(self, tree)\n }}\n\n fn enter_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), E> {{ Ok(()) }}\n fn exit_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), E> {{ Ok(()) }}\n\n{trait_methods} fn visit_terminal(&mut self, _node: &TerminalNode) -> Result<(), E> {{ Ok(()) }}\n fn visit_error_node(&mut self, _node: &ErrorNode) -> Result<(), E> {{ Ok(()) }}\n fn output(&mut self) -> std::io::Stdout {{ std::io::stdout() }}\n}}\n" ); - // Java's RuleContext.toString(): bracketed invoking-state chain from - // this context to the root, the root's sentinel excluded. + let _ = writeln!( out, - "impl std::fmt::Display for {view_name}<'_> {{\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {{\n let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect();\n write!(f, \"[{{}}]\", chain.join(\" \"))\n }}\n}}\n" + r#"#[allow(dead_code)] +pub struct {tree_walker}; + +#[allow(dead_code)] +impl {tree_walker} {{ + pub fn walk>( + listener: &mut T, + tree: antlr4_runtime::Node<'_>, + ) -> Result<(), E> {{ + Self::__walk(listener, tree, None) + }} + + pub fn walk_with_invocation_states>( + listener: &mut T, + tree: antlr4_runtime::Node<'_>, + parent_invocation_states: Vec, + ) -> Result<(), E> {{ + Self::__walk(listener, tree, Some(parent_invocation_states)) + }} + + fn __walk>( + listener: &mut T, + tree: antlr4_runtime::Node<'_>, + mut invocation_states: Option>, + ) -> Result<(), E> {{ + enum Event<'tree> {{ + Enter(antlr4_runtime::Node<'tree>), + Exit(RuleNodeView<'tree>), + }} + + let mut stack = vec![Event::Enter(tree)]; + while let Some(event) = stack.pop() {{ + match event {{ + Event::Enter(node) => match node.kind() {{ + antlr4_runtime::NodeKind::Rule => {{ + let context = node.as_rule().expect("rule node kind checked"); + if let Some(states) = &mut invocation_states {{ + states.insert(0, context.invoking_state()); + }} + listener.enter_every_rule(context)?; + match __context_kind(context) {{ +{enter_arms} _ => {{}} + }} + stack.push(Event::Exit(context)); + stack.extend(context.children().rev().map(Event::Enter)); + }} + antlr4_runtime::NodeKind::Terminal => {{ + listener.visit_terminal(&TerminalNode::new( + node.as_terminal().expect("terminal node kind checked"), + ))?; + }} + antlr4_runtime::NodeKind::Error => {{ + listener.visit_error_node(&ErrorNode::new( + node.as_error().expect("error node kind checked"), + ))?; + }} + }}, + Event::Exit(context) => {{ + match __context_kind(context) {{ +{exit_arms} _ => {{}} + }} + listener.exit_every_rule(context)?; + if let Some(states) = &mut invocation_states {{ + states.remove(0); + }} + }} + }} + }} + Ok(()) + }} +}} + +pub type ParseTreeWalker = {tree_walker}; +"# ); } - // Listener trait with defaulted callbacks. - let mut trait_methods = String::new(); - let mut enter_arms = String::new(); - let mut exit_arms = String::new(); - for (rule_index, rule) in model.rules.iter().enumerate() { - let mut names = vec![context_names.rules[rule_index].clone()]; - for alt in &rule.alts { - if let Some(label) = &alt.label { - let surface = context_names.alternative(rule_index, label); - if !names.contains(surface) { - names.push(surface.clone()); - } - } - } - for ContextSurfaceName { - context_type: view, - listener_method: method, - } in &names - { + if options.generate_visitor { + let mut visitor_methods = String::new(); + let mut visitor_arms = String::new(); + for (kind_id, view) in context_names.views.iter().enumerate() { + let ContextSurfaceName { + context_type, + visitor_method, + .. + } = &view.surface; let _ = writeln!( - trait_methods, - " fn enter_{method}(&mut self, _ctx: &{view}) {{}}\n fn exit_{method}(&mut self, _ctx: &{view}) {{}}" + visitor_methods, + " fn visit_{visitor_method}(&mut self, ctx: &{context_type}) -> Self::Result {{\n self.visit_children(ctx)\n }}" + ); + let _ = writeln!( + visitor_arms, + " {kind_id} => {visitor_trait}::visit_{visitor_method}(self.0, &{context_type}::__from_listener_node(context, None))," ); } - // Dispatch: an unlabeled rule fires its plain callbacks; a rule with - // labeled alternatives fires the callback of the alternative that - // matched. Left-recursive operator alternatives are identified - // structurally (their first child is the rule itself), matching - // ANTLR's per-alternative context classes. - let op_labels: Vec = rule - .alts - .iter() - .filter(|alt| alt.is_lr_operator(&rule.name)) - .filter_map(|alt| alt.label.clone()) - .collect(); - let primary_labels: Vec = rule - .alts - .iter() - .filter(|alt| !alt.is_lr_operator(&rule.name)) - .filter_map(|alt| alt.label.clone()) - .collect(); - let has_labels = names.len() > 1; - let dispatch = |phase: &str| -> String { - if !has_labels { - let ContextSurfaceName { - context_type: view, - listener_method: method, - } = &names[0]; - return format!( - " self.0.{phase}_{method}(&{view}::__from_listener_node(context, self.1.as_deref()));\n" - ); - } - let mut out = String::new(); - let op = op_labels - .first() - .filter(|_| op_labels.iter().collect::>().len() == 1); - let primary = primary_labels - .first() - .filter(|_| primary_labels.iter().collect::>().len() == 1); - match (op, primary) { - (Some(op), Some(primary)) => { - let ContextSurfaceName { - context_type: op_view, - listener_method: op_method, - } = context_names.alternative(rule_index, op); - let ContextSurfaceName { - context_type: primary_view, - listener_method: primary_method, - } = context_names.alternative(rule_index, primary); - let _ = writeln!( - out, - " if context.child_rule_trees({rule_index}).next().is_some() {{ self.0.{phase}_{op_method}(&{op_view}::__from_listener_node(context, self.1.as_deref())); }} else {{ self.0.{phase}_{primary_method}(&{primary_view}::__from_listener_node(context, self.1.as_deref())); }}" - ); - } - _ => { - // No unambiguous per-alternative identity available; fire - // the rule-level callback only. - let ContextSurfaceName { - context_type: view, - listener_method: method, - } = &names[0]; - let _ = writeln!( - out, - " self.0.{phase}_{method}(&{view}::__from_listener_node(context, self.1.as_deref()));" - ); - } - } - out - }; - let enter_calls = dispatch("enter"); - let exit_calls = dispatch("exit"); let _ = writeln!( - enter_arms, - " {rule_index} => {{\n{enter_calls} }}" - ); - let _ = writeln!( - exit_arms, - " {rule_index} => {{\n{exit_calls} }}" - ); - } - let _ = writeln!( - out, - "#[allow(dead_code, unused_variables)]\npub trait {listener_trait} {{\n{trait_methods} fn visit_terminal(&mut self, _node: &TerminalNode) {{}}\n fn visit_error_node(&mut self, _node: &ErrorNode) {{}}\n fn output(&mut self) -> std::io::Stdout {{ std::io::stdout() }}\n}}\n" - ); + out, + r#"#[allow(dead_code, unused_variables)] +pub trait {visitor_trait}: Sized {{ + type Result; - // Bridge + module-local walker (shadows the runtime walker so rendered - // `ParseTreeWalker::walk(&mut listener, tree)` dispatches typed - // callbacks. - let _ = writeln!( - out, - r#"#[allow(dead_code)] -struct __ListenerBridge<'a, T: {listener_trait}>(&'a mut T, Option>); + fn default_result(&mut self) -> Self::Result; -impl antlr4_runtime::ParseTreeListener for __ListenerBridge<'_, T> {{ - fn enter_every_rule(&mut self, context: RuleNodeView<'_>) -> Result<(), antlr4_runtime::AntlrError> {{ - if let Some(invocation_states) = &mut self.1 {{ - invocation_states.insert(0, context.invoking_state()); - }} - match context.rule_index() {{ -{enter_arms} _ => {{}} - }} - Ok(()) + fn visit<'tree, T>(&mut self, tree: T) -> Self::Result + where + T: {visitable_trait}<'tree>, + {{ + let tree = {visitable_trait}::into_parse_tree_node(tree); + let mut bridge = __VisitorBridge(self); + antlr4_runtime::ParseTreeVisitor::visit(&mut bridge, tree) }} - fn exit_every_rule(&mut self, context: RuleNodeView<'_>) -> Result<(), antlr4_runtime::AntlrError> {{ - match context.rule_index() {{ -{exit_arms} _ => {{}} - }} - if let Some(invocation_states) = &mut self.1 {{ - invocation_states.remove(0); - }} - Ok(()) + fn visit_children<'tree, T>(&mut self, context: T) -> Self::Result + where + T: {visitable_trait}<'tree>, + {{ + let tree = {visitable_trait}::into_parse_tree_node(context); + let context = tree.as_rule().expect("visit_children requires a rule context"); + let mut bridge = __VisitorBridge(self); + antlr4_runtime::ParseTreeVisitor::visit_children(&mut bridge, context) }} - fn visit_terminal(&mut self, node: RuntimeTerminalNode<'_>) -> Result<(), antlr4_runtime::AntlrError> {{ - self.0.visit_terminal(&TerminalNode::new(node)); - Ok(()) + fn aggregate_result( + &mut self, + _aggregate: Self::Result, + next_result: Self::Result, + ) -> Self::Result {{ + next_result }} - fn visit_error_node(&mut self, node: RuntimeErrorNode<'_>) -> Result<(), antlr4_runtime::AntlrError> {{ - self.0.visit_error_node(&ErrorNode::new(node)); - Ok(()) + fn should_visit_next_child( + &mut self, + _context: RuleNodeView<'_>, + _current_result: &Self::Result, + ) -> bool {{ + true }} -}} -#[allow(dead_code)] -pub struct ParseTreeWalker; + fn visit_terminal(&mut self, _node: &TerminalNode) -> Self::Result {{ + self.default_result() + }} + + fn visit_error_node(&mut self, _node: &ErrorNode) -> Self::Result {{ + self.default_result() + }} + +{visitor_methods}}} #[allow(dead_code)] -impl ParseTreeWalker {{ - pub fn walk(listener: &mut T, tree: antlr4_runtime::Node<'_>) {{ - let mut bridge = __ListenerBridge(listener, None); - let _ = antlr4_runtime::ParseTreeWalker::walk(&mut bridge, tree); +struct __VisitorBridge<'a, T: {visitor_trait}>(&'a mut T); + +impl antlr4_runtime::ParseTreeVisitor for __VisitorBridge<'_, T> {{ + type Result = T::Result; + + fn visit_rule(&mut self, context: RuleNodeView<'_>) -> Self::Result {{ + match __context_kind(context) {{ +{visitor_arms} _ => {visitor_trait}::default_result(self.0), + }} }} - pub fn walk_with_invocation_states( - listener: &mut T, - tree: antlr4_runtime::Node<'_>, - parent_invocation_states: Vec, - ) {{ - let mut bridge = __ListenerBridge(listener, Some(parent_invocation_states)); - let _ = antlr4_runtime::ParseTreeWalker::walk(&mut bridge, tree); + fn visit_terminal(&mut self, node: RuntimeTerminalNode<'_>) -> Self::Result {{ + {visitor_trait}::visit_terminal(self.0, &TerminalNode::new(node)) + }} + + fn visit_error_node(&mut self, node: RuntimeErrorNode<'_>) -> Self::Result {{ + {visitor_trait}::visit_error_node(self.0, &ErrorNode::new(node)) + }} + + fn default_result(&mut self) -> Self::Result {{ + {visitor_trait}::default_result(self.0) + }} + + fn aggregate_result( + &mut self, + aggregate: Self::Result, + next_result: Self::Result, + ) -> Self::Result {{ + {visitor_trait}::aggregate_result(self.0, aggregate, next_result) + }} + + fn should_visit_next_child( + &mut self, + context: RuleNodeView<'_>, + current_result: &Self::Result, + ) -> bool {{ + {visitor_trait}::should_visit_next_child(self.0, context, current_result) }} }} "# - ); + ); + } out } @@ -8012,14 +9152,23 @@ fn render_parser_with_options( // (rendered through the target `.test.stg`); translate and splice them // instead of recognizing template markup. let embedded_data = if options.embedded { - Some(build_embedded_parser_data(data, &type_name, grammar_name)?) + Some(build_embedded_parser_data( + data, + &type_name, + grammar_name, + options, + )?) } else { None }; let structural_surface = if options.embedded { None } else { - Some(build_structural_parser_surface(data, grammar_name)?) + Some(build_structural_parser_surface( + data, + grammar_name, + options, + )?) }; let embedded_step_render = embedded_data.as_ref().map(embedded_step_render); let mut portable_local_data = if options.embedded { @@ -8099,7 +9248,8 @@ fn render_parser_with_options( generated_predicate_coordinates.extend(portable_local_data.predicates.keys().copied()); let has_action_dispatch = !action_states.is_empty(); let has_predicate_dispatch = !predicates.is_empty(); - let track_alt_numbers = uses_structural_alt_number_contexts(data); + let track_alt_numbers = uses_alt_number_contexts(data); + let track_context_alt_numbers = uses_structural_context_alt_numbers(data)?; let generated_rule_enabled = vec![true; data.rule_names.len()]; let generated_rules = parser_generated_rules( data, @@ -8137,6 +9287,7 @@ fn render_parser_with_options( &data.rule_names, &inline_action_statements, track_alt_numbers, + track_context_alt_numbers, embedded_step_render, portable_local_data.step_render(), ); @@ -8159,7 +9310,7 @@ fn render_parser_with_options( }; let parse_rule_fallback = render_parser_parse_rule_fallback( track_alt_numbers, - &predicates, + track_context_alt_numbers, &rule_args, has_action_dispatch, has_predicate_dispatch, @@ -8185,6 +9336,7 @@ fn render_parser_with_options( // configured fail/assume-false behavior. let adaptive_direct_allowed = !has_action_dispatch && !track_alt_numbers + && !track_context_alt_numbers && !has_predicate_dispatch && unknown_policy_literal.is_none(); let embedded_noop_states = BTreeSet::new(); @@ -8213,7 +9365,7 @@ fn render_parser_with_options( let generated_footer = GENERATED_MODULE_FOOTER; let embedded_imports = if embedded_data.is_some() || structural_surface.is_some() { - "#[allow(unused_imports)]\nuse std::io::Write as _;\n#[allow(unused_imports)]\nuse antlr4_runtime::{java_style_list, PredictionMode, BailErrorStrategy, TerminalNodeView as RuntimeTerminalNode, ErrorNodeView as RuntimeErrorNode, RuleNodeView, FromRuleNode, Token as _};\n" + "#[allow(unused_imports)]\nuse std::io::Write as _;\n#[allow(unused_imports)]\nuse antlr4_runtime::{java_style_list, PredictionMode, BailErrorStrategy, TerminalNodeView as RuntimeTerminalNode, ErrorNodeView as RuntimeErrorNode, RuleNodeView, AsRuleNode, FromRuleNode, MissingChildError, Token as _};\n" } else { "" }; @@ -8877,7 +10029,7 @@ fn is_unsupported_string_template_body(body: &str) -> bool { single_template_body(body).is_some() || template_sequence_bodies(body).is_some() } -fn uses_structural_alt_number_contexts(data: &CodegenData<'_>) -> bool { +fn uses_alt_number_contexts(data: &CodegenData<'_>) -> bool { let Some(semantic) = data.semantic else { return false; }; @@ -8888,6 +10040,38 @@ fn uses_structural_alt_number_contexts(data: &CodegenData<'_>) -> bool { .any(|option| option.name.value == "contextSuperClass") } +fn uses_structural_context_alt_numbers(data: &CodegenData<'_>) -> io::Result { + if data.semantic.is_none() { + return Ok(false); + } + let model = structural_embedded_model(data, false)?; + Ok(model.rules.iter().any(|rule| { + let left_recursive = rule + .alts + .iter() + .any(|alternative| alternative.is_lr_operator(&rule.name)); + if !left_recursive { + return rule + .alts + .iter() + .map(|alternative| alternative.label.as_deref()) + .collect::>() + .len() + > 1; + } + + [false, true].into_iter().any(|operator| { + rule.alts + .iter() + .filter(|alternative| alternative.is_lr_operator(&rule.name) == operator) + .map(|alternative| alternative.label.as_deref()) + .collect::>() + .len() + > 1 + }) + })) +} + fn parse_predicate_template(body: &str) -> Option { let body = body.trim(); if let Some(inner) = single_template_body(body) { @@ -11206,6 +12390,7 @@ mod tests { &rule_names, &BTreeMap::new(), true, + false, None, None, ); @@ -11243,6 +12428,7 @@ mod tests { &rule_names, &BTreeMap::new(), true, + false, None, None, ); @@ -11286,6 +12472,7 @@ mod tests { &[], &BTreeMap::new(), true, + false, Some(EmbeddedStepRender { force_adaptive: false, adaptive_decisions: &adaptive_decisions, @@ -11682,6 +12869,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -11714,6 +12902,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls, atn_preferred_rule_calls, }, @@ -11782,7 +12971,7 @@ mod tests { #[test] fn parse_rule_fallback_runs_parser_actions() { - let fallback = render_parser_parse_rule_fallback(false, &[], &[], true, false, None); + let fallback = render_parser_parse_rule_fallback(false, false, &[], true, false, None); assert!(fallback.contains( "parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence" @@ -11881,8 +13070,9 @@ mod tests { structural_embedded_model(&data, false).expect("structural model should resolve"); insta::assert_debug_snapshot!("left_recursive_label_alternatives", model.rules[1].alts); - let embedded = build_embedded_parser_data(&data, "TParser", "T") - .expect("embedded actions should resolve deleted left-recursive labels"); + let embedded = + build_embedded_parser_data(&data, "TParser", "T", ParserRenderOptions::default()) + .expect("embedded actions should resolve deleted left-recursive labels"); insta::assert_debug_snapshot!("left_recursive_label_actions", embedded.inline_actions); } @@ -11900,12 +13090,10 @@ mod tests { assert!(rendered.contains("ErrorNodeView as RuntimeErrorNode")); assert!(rendered.contains("pub struct ErrorNode<'a>")); - assert!(rendered.contains("fn visit_error_node(&mut self, _node: &ErrorNode)")); assert!( - rendered - .contains("fn visit_error_node(&mut self, node: RuntimeErrorNode<'_>) -> Result<") + rendered.contains("fn visit_error_node(&mut self, _node: &ErrorNode) -> Result<(), E>") ); - assert!(rendered.contains("self.0.visit_error_node(&ErrorNode::new(node));")); + assert!(rendered.contains("listener.visit_error_node(&ErrorNode::new(")); } #[test] @@ -11923,7 +13111,7 @@ mod tests { assert!(rendered.contains("invocation_states: Vec")); assert!(rendered.contains("__invocation_states: invocation_states")); assert!(rendered.contains("::__from_child_node(node, &self.__invocation_states)")); - assert!(rendered.contains("::__from_listener_node(context, self.1.as_deref())")); + assert!(rendered.contains("::__from_listener_node(context, invocation_states.as_deref())")); assert!(rendered.contains("pub fn walk_with_invocation_states")); assert!( !rendered.contains("__GeneratedRuleContext::Active { .. } => Vec::new()"), @@ -11936,43 +13124,173 @@ mod tests { let data = parser_fixture_data("context-name-collision/T.g4"); let model = structural_embedded_model(&data, false).expect("structural model should resolve"); + let names = context_surface_names(&model); - insta::assert_debug_snapshot!( - "context_surface_name_collision", - context_surface_names(&model) - ); + let every_rule = model + .rules + .iter() + .position(|rule| rule.name == "everyRule") + .expect("everyRule fixture rule"); + assert_ne!(names.rules[every_rule].listener_method, "every_rule"); + let stored_tree = model + .rules + .iter() + .position(|rule| rule.name == "storedTree") + .expect("storedTree fixture rule"); + assert_ne!(names.rules[stored_tree].context_type, "StoredTreeContext"); + + insta::assert_debug_snapshot!("context_surface_name_collision", names); } #[test] - fn typed_context_accessors_are_scoped_to_structural_children() { + fn typed_context_accessors_are_cardinality_aware_and_rust_shaped() { let rendered = render_parser( "TParser", &parser_fixture_data("left-recursive-labels/T.g4"), ) .expect("parser should render"); let s_context = rendered - .split_once("impl<'a> SContext<'a> {") + .split_once("impl<'a, State> SContext<'a, State> {") .expect("s context impl") .1 - .split_once("impl std::fmt::Display for SContext") + .split_once("impl std::fmt::Display for SContext") .expect("s context display impl") .0; - assert!(s_context.contains("pub fn e(&self")); + assert!(s_context.contains("pub fn e(&self) -> Result, MissingChildError>")); assert!(!s_context.contains("pub fn s(&self")); - assert!(!s_context.contains("pub fn INT(&self")); + assert!(!s_context.contains("_all(&self)")); let e_context = rendered - .split_once("impl<'a> EContext<'a> {") + .split_once("impl<'a, State> EContext<'a, State> {") .expect("e context impl") .1 - .split_once("impl std::fmt::Display for EContext") + .split_once("impl std::fmt::Display for EContext") .expect("e context display impl") .0; - assert!(e_context.contains("pub fn e(&self")); - assert!(e_context.contains("pub fn INT(&self")); - assert!(e_context.contains("pub fn STAR(&self")); - assert!(e_context.contains("pub fn PLUS(&self")); + assert!( + e_context.contains("pub fn e_children(&self) -> impl Iterator>") + ); + assert!(e_context.contains("pub fn int_token(&self) -> Option>")); + assert!(e_context.contains("pub fn star_token(&self) -> Option>")); + assert!(e_context.contains("pub fn plus_token(&self) -> Option>")); + assert!(e_context.contains("pub fn left(&self) -> Option>")); + assert!(e_context.contains("pub fn right(&self) -> Option>")); assert!(!e_context.contains("pub fn s(&self")); + assert!(!e_context.contains("pub fn INT(&self")); + assert!(!e_context.contains("_all(&self)")); + } + + #[test] + fn literal_labels_keep_terminal_action_semantics() { + let data = parser_fixture_data("typed-tree-walkers/Calculator.g4"); + let model = + structural_embedded_model(&data, false).expect("structural model should resolve"); + let labeled_tokens = model + .rules + .iter() + .find(|rule| rule.name == "labeledTokens") + .expect("labeledTokens rule"); + let literal = labeled_tokens + .alts + .iter() + .flat_map(|alternative| &alternative.refs) + .find(|element| element.label.as_deref() == Some("literal")) + .expect("literal label"); + + assert!(literal.is_block); + assert_eq!(literal.token_types.len(), 1); + } + + #[test] + fn structural_set_token_types_expand_literal_ranges() { + let data = parser_fixture_data("typed-tree-walkers/Calculator.g4"); + let vocabulary = &data + .semantic + .expect("semantic grammar") + .recognizer + .vocabulary; + let mut literals = vocabulary + .by_literal + .iter() + .map(|(literal, token_type)| (literal.clone(), *token_type)) + .collect::>(); + literals.sort_unstable_by_key(|(_, token_type)| *token_type); + assert!(literals.len() >= 3, "fixture needs three literal tokens"); + let (start, start_type) = literals[0].clone(); + let (stop, stop_type) = literals[2].clone(); + let range = SetElement::Range { + source: grammar::model::ElementId::new(0), + start, + stop, + span: SourceSpan::empty(grammar::frontend::SourceId::new(0)), + options: Vec::new(), + }; + let expected = (start_type..=stop_type).collect::>(); + + assert_eq!( + structural_set_token_types(false, std::slice::from_ref(&range), vocabulary), + expected + ); + assert_eq!( + structural_set_token_types(true, &[range], vocabulary), + (1..=vocabulary.max_token_type()) + .filter(|token_type| !expected.contains(token_type)) + .collect::>() + ); + } + + #[test] + fn typed_context_accessors_preserve_ebnf_list_and_single_labels() { + let data = parser_fixture_data("combined-contexts/Shapes.g4"); + let model = + structural_embedded_model(&data, false).expect("structural model should resolve"); + let start = model + .rules + .iter() + .find(|rule| rule.name == "start") + .expect("start rule"); + let many = start + .alts + .iter() + .find(|alternative| alternative.label.as_deref() == Some("Many")) + .expect("many alternative"); + let rest = many + .refs + .iter() + .filter(|element| element.label.as_deref() == Some("rest")) + .collect::>(); + assert_eq!(rest.len(), 2); + assert!(rest.iter().all(|element| element.stable_accessor)); + assert_eq!(rest[0].cardinality, embedded::ChildCardinality::ONE); + assert_eq!( + rest[1].cardinality, + embedded::ChildCardinality { min: 0, max: None } + ); + + let rendered = render_parser("ShapesParser", &data).expect("parser should render"); + let many_context = rendered + .split_once("impl<'a, State> ManyLabelContext<'a, State> {") + .expect("many context impl") + .1 + .split_once("impl std::fmt::Display for ManyLabelContext") + .expect("many context display impl") + .0; + assert!( + many_context.contains("pub fn rest(&self) -> impl Iterator>") + ); + + let latest_context = rendered + .split_once("impl<'a, State> LatestContext<'a, State> {") + .expect("latest context impl") + .1 + .split_once("impl std::fmt::Display for LatestContext") + .expect("latest context display impl") + .0; + assert!( + latest_context + .contains("pub fn value(&self) -> Result, MissingChildError>") + ); + assert!(latest_context.contains(".skip(0).last()")); } #[test] @@ -12343,6 +13661,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12391,6 +13710,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12458,6 +13778,7 @@ mod tests { }), inline_action_statements: &inline_actions, track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12496,6 +13817,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12539,6 +13861,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12584,6 +13907,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12637,6 +13961,7 @@ mod tests { }), inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -12691,6 +14016,7 @@ mod tests { portable_locals: None, inline_action_statements: &BTreeMap::new(), track_alt_numbers: false, + track_context_alt_numbers: false, direct_generated_rule_calls: &[], atn_preferred_rule_calls: &[], }, @@ -14302,6 +15628,7 @@ dispose = "hook" embedded: false, sem_unknown: SemUnknownPolicy::Error, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("empty action should not block generated parser output"); @@ -14485,6 +15812,7 @@ dispose = "hook" embedded: false, sem_unknown: SemUnknownPolicy::AssumeFalse, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("parser should render"); @@ -14508,6 +15836,7 @@ dispose = "hook" embedded: false, sem_unknown: SemUnknownPolicy::AssumeFalse, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("parser should render"); @@ -14542,6 +15871,7 @@ dispose = "hook" embedded: false, sem_unknown: SemUnknownPolicy::Hook, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("parser should render"); @@ -14589,6 +15919,7 @@ dispose = "hook" embedded: false, sem_unknown: SemUnknownPolicy::Hook, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("parser should render"); @@ -14638,6 +15969,7 @@ dispose = "hook" embedded: false, sem_unknown: SemUnknownPolicy::AssumeTrue, patterns: Some(&patterns), + ..ParserRenderOptions::default() }, ) .expect("parser should render"); @@ -14673,6 +16005,7 @@ dispose = "hook" embedded: false, sem_unknown: policy, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("parser should render"); @@ -14730,6 +16063,7 @@ dispose = "hook" embedded: false, sem_unknown: policy, patterns: None, + ..ParserRenderOptions::default() }, ) .expect("parser should render under a non-default policy"); diff --git a/src/bin/snapshots/antlr4_rust_gen__tests__context_surface_name_collision.snap b/src/bin/snapshots/antlr4_rust_gen__tests__context_surface_name_collision.snap index 8d9fcad6..8588e5dd 100644 --- a/src/bin/snapshots/antlr4_rust_gen__tests__context_surface_name_collision.snap +++ b/src/bin/snapshots/antlr4_rust_gen__tests__context_surface_name_collision.snap @@ -1,36 +1,36 @@ --- source: src/bin/antlr4-rust-gen.rs -expression: context_surface_names(&model) +expression: names --- ContextSurfaceNames { rules: [ ContextSurfaceName { context_type: "PrimaryExpressionStartContext", listener_method: "primary_expression_start", + visitor_method: "primary_expression_start", }, ContextSurfaceName { context_type: "ObjectCreationExpressionContext", listener_method: "object_creation_expression", + visitor_method: "object_creation_expression", }, - ], - alternatives: [ - { - "objectCreationExpression": ContextSurfaceName { - context_type: "ObjectCreationExpressionLabelContext", - listener_method: "object_creation_expression_label", - }, - "parenthesized": ContextSurfaceName { - context_type: "ParenthesizedLabelContext", - listener_method: "parenthesized_label", - }, + ContextSurfaceName { + context_type: "EveryRuleContext", + listener_method: "every_rule_rule", + visitor_method: "every_rule", + }, + ContextSurfaceName { + context_type: "StoredTreeRuleContext", + listener_method: "stored_tree", + visitor_method: "stored_tree", }, - {}, ], views: [ ContextViewName { surface: ContextSurfaceName { context_type: "PrimaryExpressionStartContext", listener_method: "primary_expression_start", + visitor_method: "primary_expression_start", }, rule_index: 0, alternative_label: None, @@ -39,6 +39,7 @@ ContextSurfaceNames { surface: ContextSurfaceName { context_type: "ObjectCreationExpressionLabelContext", listener_method: "object_creation_expression_label", + visitor_method: "object_creation_expression_label", }, rule_index: 0, alternative_label: Some( @@ -49,6 +50,7 @@ ContextSurfaceNames { surface: ContextSurfaceName { context_type: "ParenthesizedLabelContext", listener_method: "parenthesized_label", + visitor_method: "parenthesized_label", }, rule_index: 0, alternative_label: Some( @@ -59,9 +61,28 @@ ContextSurfaceNames { surface: ContextSurfaceName { context_type: "ObjectCreationExpressionContext", listener_method: "object_creation_expression", + visitor_method: "object_creation_expression", }, rule_index: 1, alternative_label: None, }, + ContextViewName { + surface: ContextSurfaceName { + context_type: "EveryRuleContext", + listener_method: "every_rule_rule", + visitor_method: "every_rule", + }, + rule_index: 2, + alternative_label: None, + }, + ContextViewName { + surface: ContextSurfaceName { + context_type: "StoredTreeRuleContext", + listener_method: "stored_tree", + visitor_method: "stored_tree", + }, + rule_index: 3, + alternative_label: None, + }, ], } diff --git a/src/bin/snapshots/antlr4_rust_gen__tests__left_recursive_label_alternatives.snap b/src/bin/snapshots/antlr4_rust_gen__tests__left_recursive_label_alternatives.snap index a2531921..308e790c 100644 --- a/src/bin/snapshots/antlr4_rust_gen__tests__left_recursive_label_alternatives.snap +++ b/src/bin/snapshots/antlr4_rust_gen__tests__left_recursive_label_alternatives.snap @@ -15,24 +15,64 @@ expression: "model.rules[1].alts" "left", ), target: "e", + token_types: [], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ElementRef { label: None, target: "STAR", + token_types: [ + 2, + ], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ElementRef { label: Some( "right", ), target: "e", + token_types: [], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ], + children: { + "STAR": ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + "e": ChildCardinality { + min: 2, + max: Some( + 2, + ), + }, + }, leading_target: Some( "e", ), @@ -49,24 +89,64 @@ expression: "model.rules[1].alts" "left", ), target: "e", + token_types: [], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ElementRef { label: None, target: "PLUS", + token_types: [ + 3, + ], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ElementRef { label: Some( "right", ), target: "e", + token_types: [], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ], + children: { + "PLUS": ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + "e": ChildCardinality { + min: 2, + max: Some( + 2, + ), + }, + }, leading_target: Some( "e", ), @@ -81,10 +161,28 @@ expression: "model.rules[1].alts" ElementRef { label: None, target: "INT", + token_types: [ + 1, + ], is_block: false, is_list: false, + cardinality: ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + stable_accessor: true, }, ], + children: { + "INT": ChildCardinality { + min: 1, + max: Some( + 1, + ), + }, + }, leading_target: None, }, ] diff --git a/src/bin_support/embedded.rs b/src/bin_support/embedded.rs index 29355e14..d716a86e 100644 --- a/src/bin_support/embedded.rs +++ b/src/bin_support/embedded.rs @@ -29,17 +29,54 @@ pub(crate) struct AttrDecl { pub(crate) ty: String, } +/// Number of children with one grammar target that an alternative can emit. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub(crate) struct ChildCardinality { + pub(crate) min: usize, + /// `None` denotes an unbounded maximum. + pub(crate) max: Option, +} + +impl ChildCardinality { + pub(crate) const ZERO: Self = Self { + min: 0, + max: Some(0), + }; + pub(crate) const ONE: Self = Self { + min: 1, + max: Some(1), + }; + + pub(crate) const fn is_required_single(self) -> bool { + self.min == 1 && matches!(self.max, Some(1)) + } + + pub(crate) const fn is_repeated(self) -> bool { + match self.max { + Some(max) => max > 1, + None => true, + } + } +} + /// One element reference inside an alternative: a rule ref, token ref, or a /// labeled sub-block, in source order. #[derive(Clone, Debug, Eq, PartialEq)] pub(crate) struct ElementRef { pub(crate) label: Option, - /// Referenced rule or token name; empty for a labeled `(...)` block, - /// `~set`, or string literal. + /// Referenced rule or token spelling; empty for token sets and wildcards. pub(crate) target: String, + /// Token types matched by this element. Empty for rule references. + pub(crate) token_types: Vec, pub(crate) is_block: bool, /// `label+=ref` list label. pub(crate) is_list: bool, + /// Cardinality of this element after its direct EBNF suffix. + pub(crate) cardinality: ChildCardinality, + /// Whether source-order occurrence lookup is unambiguous for a generated + /// label accessor. Single-alternative EBNF groups preserve it; choices opt + /// out because their flattened CST children do not retain the chosen path. + pub(crate) stable_accessor: bool, } /// One top-level alternative of a parser rule. @@ -50,6 +87,8 @@ pub(crate) struct AltModel { /// Byte span of the alternative inside the grammar source. pub(crate) span: (usize, usize), pub(crate) refs: Vec, + /// Aggregate child cardinality by referenced rule or symbolic token. + pub(crate) children: BTreeMap, /// Target of the first syntactic element when it is a bare (possibly /// labeled) rule/token reference; `None` for a leading literal, set, /// block, or action. ANTLR's left-recursion transformer only treats an @@ -370,11 +409,13 @@ pub(crate) fn translate_body(body: &str, ctx: &TranslationCtx<'_>) -> io::Result suffix = Some(&suffix_text[..suffix_len]); consumed = name_len + 1 + suffix_len; } else if name == "ctx" - && suffix_text[..suffix_len].ends_with("_all") + && (suffix_text[..suffix_len].ends_with("_children") + || suffix_text[..suffix_len].ends_with("_all")) && after_suffix.starts_with("()") { - // `$ctx._all()` — a generated list accessor call; - // consume the empty parens along with the suffix. + // `$ctx._children()` (or the legacy `_all()` form) is + // an active-context collection read. Consume the empty + // parens along with the suffix. suffix = Some(&suffix_text[..suffix_len]); let call_end = suffix_text[suffix_len..] .find(')') @@ -444,8 +485,11 @@ fn translate_reference( let element = ElementRef { label: None, target: name.to_owned(), + token_types: Vec::new(), is_block: false, is_list: false, + cardinality: ChildCardinality::ONE, + stable_accessor: false, }; let _ = target_rule; return translate_element_read(&element, usize::MAX, suffix, ctx, body); @@ -454,8 +498,11 @@ fn translate_reference( let element = ElementRef { label: None, target: name.to_owned(), + token_types: vec![ctx.token_types[name]], is_block: false, is_list: false, + cardinality: ChildCardinality::ONE, + stable_accessor: false, }; return translate_element_read(&element, usize::MAX, suffix, ctx, body); } @@ -478,14 +525,21 @@ fn text_expression(ctx: &TranslationCtx<'_>) -> String { } } -/// `$ctx.member` — a labeled element read (`$ctx.r`) or a generated list -/// accessor (`$ctx.elseIfStatement_all`). +/// `$ctx.member` — a labeled element read (`$ctx.r`) or a generated child +/// iterator (`$ctx.elseIfStatement_children()`). fn translate_ctx_member(member: &str, ctx: &TranslationCtx<'_>, body: &str) -> io::Result { if let Some((element, occurrence)) = ctx.resolve_label(member) { // `$ctx.r` denotes the labeled child's subtree (Java field of the // context); translate like `$r.ctx`. return translate_element_read(&element, occurrence, Some("ctx"), ctx, body); } + if let Some(rule_name) = member.strip_suffix("_children") { + if let Some(rule_index) = ctx.rule_index_by_name(rule_name) { + return Ok(format!( + "__ctx.child_rules(self.base.parse_tree_storage(), self.base.token_store(), {rule_index})" + )); + } + } if let Some(rule_name) = member.strip_suffix("_all") { if let Some(rule_index) = ctx.rule_index_by_name(rule_name) { return Ok(format!( @@ -514,11 +568,11 @@ fn translate_element_read( body: &str, ) -> io::Result { if element.is_list { - // `label+=x`: the label denotes the list of every `x` child. + // `label+=x`: expose the matching children as a lazy Rust iterator. if let Some(rule_index) = ctx.rule_index_by_name(&element.target) { return match suffix { None | Some("ctx") => Ok(format!( - "__ctx.child_rule_trees(self.base.parse_tree_storage(), self.base.token_store(), {rule_index}).collect::>()" + "__ctx.child_rule_trees(self.base.parse_tree_storage(), self.base.token_store(), {rule_index})" )), Some(other) => Err(io::Error::new( io::ErrorKind::InvalidData, @@ -528,7 +582,7 @@ fn translate_element_read( } if let Some(token_type) = ctx.token_types.get(&element.target) { return Ok(format!( - "__ctx.child_tokens(self.base.parse_tree_storage(), self.base.token_store(), {token_type}).collect::>()" + "__ctx.child_tokens(self.base.parse_tree_storage(), self.base.token_store(), {token_type})" )); } } @@ -781,16 +835,29 @@ mod tests { ElementRef { label: Some("left".to_owned()), target: "e".to_owned(), + token_types: Vec::new(), is_block: false, is_list: false, + cardinality: ChildCardinality::ONE, + stable_accessor: true, }, ElementRef { label: Some("right".to_owned()), target: "e".to_owned(), + token_types: Vec::new(), is_block: false, is_list: false, + cardinality: ChildCardinality::ONE, + stable_accessor: true, }, ], + children: BTreeMap::from([( + "e".to_owned(), + ChildCardinality { + min: 2, + max: Some(2), + }, + )]), leading_target: Some("e".to_owned()), }); let mut expression = rule("e"); @@ -836,6 +903,74 @@ mod tests { assert_eq!(tree, "(&__ctx).to_string_tree(Some(self))"); } + #[test] + fn translates_active_context_child_iterators() { + let m = model(vec![rule("s"), rule("elseIfStatement")]); + let toks = tokens(&[]); + let ctx = TranslationCtx { + model: &m, + rule_index: 0, + body_offset: None, + site: ActionSite::Body, + token_types: &toks, + }; + + let translated = + translate_body("$ctx.elseIfStatement_children()", &ctx).expect("translates"); + assert_eq!( + translated, + "__ctx.child_rules(self.base.parse_tree_storage(), self.base.token_store(), 1)" + ); + } + + #[test] + fn translates_list_labels_as_lazy_iterators() { + let mut start = rule("s"); + start.alts.push(AltModel { + label: None, + span: (0, 10), + refs: vec![ + ElementRef { + label: Some("args".to_owned()), + target: "e".to_owned(), + token_types: Vec::new(), + is_block: false, + is_list: true, + cardinality: ChildCardinality { min: 1, max: None }, + stable_accessor: true, + }, + ElementRef { + label: Some("ids".to_owned()), + target: "ID".to_owned(), + token_types: vec![1], + is_block: false, + is_list: true, + cardinality: ChildCardinality { min: 1, max: None }, + stable_accessor: true, + }, + ], + children: BTreeMap::new(), + leading_target: Some("e".to_owned()), + }); + let m = model(vec![start, rule("e")]); + let toks = tokens(&[("ID", 1)]); + let ctx = TranslationCtx { + model: &m, + rule_index: 0, + body_offset: None, + site: ActionSite::After, + token_types: &toks, + }; + + let rules = translate_body("let _: Vec<_> = $args.collect();", &ctx).expect("rule list"); + assert_eq!(rules.matches(".collect()").count(), 1, "{rules}"); + assert!(rules.contains("__ctx.child_rule_trees("), "{rules}"); + + let tokens = translate_body("let _: Vec<_> = $ids.collect();", &ctx).expect("token list"); + assert_eq!(tokens.matches(".collect()").count(), 1, "{tokens}"); + assert!(tokens.contains("__ctx.child_tokens("), "{tokens}"); + } + #[test] fn classifies_member_blocks() { let body = "i: i32 = 0;\n\ diff --git a/src/bin_support/grammar/frontend.rs b/src/bin_support/grammar/frontend.rs index 838d7ad8..71e2bebc 100644 --- a/src/bin_support/grammar/frontend.rs +++ b/src/bin_support/grammar/frontend.rs @@ -4,15 +4,15 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; use antlr4_runtime::{ - CommonTokenStream, ErrorListener, InputStream, Node, NodeKind, Parser, Recognizer, - TOKEN_EOF as RUNTIME_TOKEN_EOF, Token, + AsRuleNode, CommonTokenStream, ErrorListener, InputStream, Node, NodeId, NodeKind, Parser, + Recognizer, TOKEN_EOF as RUNTIME_TOKEN_EOF, Token, }; use super::generated::antlr_v4_lexer::{ AntlRv4Lexer, BLOCK_COMMENT, COLON, DOC_COMMENT, MODE, RANGE, RULE_REF, SEMI, STRING_LITERAL, UNTERMINATED_ARGUMENT, UNTERMINATED_CHAR_SET, UNTERMINATED_STRING_LITERAL, }; -use super::generated::antlr_v4_parser::AntlRv4Parser; +use super::generated::antlr_v4_parser::{self as grammar_parser, ANTLRv4Listener, AntlRv4Parser}; use super::lexer_adaptor::LexerAdaptor; #[repr(transparent)] @@ -632,62 +632,260 @@ fn copy_cst( tokens: &[SyntaxToken], root: Node<'_>, ) -> Result { - let mut nodes = Vec::new(); - let mut children = Vec::new(); - let root = copy_node(source, tokens, root, &mut nodes, &mut children)?; - Ok(Cst { - nodes: nodes.into_boxed_slice(), - children: children.into_boxed_slice(), - root, - }) + let mut builder = TypedCstBuilder::new(source, tokens); + builder.walk(root)?; + builder.finish() +} + +struct OpenRule { + syntax: SyntaxId, + runtime: NodeId, + rule_index: usize, + children: Vec, } -fn copy_node( +struct TypedCstBuilder<'tokens> { source: SourceId, - tokens: &[SyntaxToken], - node: Node<'_>, - nodes: &mut Vec, - children: &mut Vec, -) -> Result { - let node_index = - u32::try_from(nodes.len()).map_err(|_| invalid_span(source, "CST exceeds 2^32 nodes"))?; - let kind = match node.kind() { - NodeKind::Rule => SyntaxNodeKind::Rule { - rule_index: node.as_rule().expect("rule node kind checked").rule_index(), - }, - NodeKind::Terminal => SyntaxNodeKind::Terminal { - token_index: node - .as_terminal() - .expect("terminal node kind checked") - .token_id() - .index(), - }, - NodeKind::Error => SyntaxNodeKind::Error { - token_index: node - .as_error() - .expect("error node kind checked") - .token_id() - .index(), - }, + tokens: &'tokens [SyntaxToken], + nodes: Vec, + children: Vec, + open_rules: Vec, + root: Option, +} + +impl<'tokens> TypedCstBuilder<'tokens> { + const fn new(source: SourceId, tokens: &'tokens [SyntaxToken]) -> Self { + Self { + source, + tokens, + nodes: Vec::new(), + children: Vec::new(), + open_rules: Vec::new(), + root: None, + } + } + + fn finish(self) -> Result { + if !self.open_rules.is_empty() { + return Err(invalid_span( + self.source, + "typed CST traversal left parser rules open", + )); + } + let root = self + .root + .ok_or_else(|| invalid_span(self.source, "typed CST traversal produced no root"))?; + Ok(Cst { + nodes: self.nodes.into_boxed_slice(), + children: self.children.into_boxed_slice(), + root, + }) + } + + fn enter_rule_context<'tree>( + &mut self, + context: &impl AsRuleNode<'tree>, + expected_rule_index: usize, + ) -> Result<(), FrontendError> { + let rule = context.as_rule_node(); + if rule.rule_index() != expected_rule_index { + return Err(invalid_span( + self.source, + &format!( + "typed listener dispatched rule {} as {expected_rule_index}", + rule.rule_index() + ), + )); + } + let node = rule.node(); + let span = node_span(self.source, self.tokens, node)?; + let syntax = self.push_node( + SyntaxNodeKind::Rule { + rule_index: expected_rule_index, + }, + span, + )?; + self.open_rules.push(OpenRule { + syntax, + runtime: node.id(), + rule_index: expected_rule_index, + children: Vec::new(), + }); + Ok(()) + } + + fn exit_rule_context<'tree>( + &mut self, + context: &impl AsRuleNode<'tree>, + expected_rule_index: usize, + ) -> Result<(), FrontendError> { + let rule = context.as_rule_node(); + let frame = self.open_rules.pop().ok_or_else(|| { + invalid_span( + self.source, + "typed CST traversal exited a rule that was not entered", + ) + })?; + if frame.runtime != rule.node().id() || frame.rule_index != expected_rule_index { + return Err(invalid_span( + self.source, + "typed CST traversal exited parser rules out of order", + )); + } + let child_start = u32::try_from(self.children.len()) + .map_err(|_| invalid_span(self.source, "CST exceeds 2^32 edges"))?; + self.children.extend(frame.children); + let child_end = u32::try_from(self.children.len()) + .map_err(|_| invalid_span(self.source, "CST exceeds 2^32 edges"))?; + self.nodes[frame.syntax.index()].child_ids = child_start..child_end; + Ok(()) + } + + fn push_token(&mut self, token_index: usize, error: bool) -> Result<(), FrontendError> { + let token = self + .tokens + .get(token_index) + .ok_or_else(|| invalid_span(self.source, "CST references a missing token"))?; + let kind = if error { + SyntaxNodeKind::Error { token_index } + } else { + SyntaxNodeKind::Terminal { token_index } + }; + self.push_node(kind, token.span.clone())?; + Ok(()) + } + + fn push_node( + &mut self, + kind: SyntaxNodeKind, + span: SourceSpan, + ) -> Result { + let node_index = u32::try_from(self.nodes.len()) + .map_err(|_| invalid_span(self.source, "CST exceeds 2^32 nodes"))?; + let syntax = SyntaxId::for_source(self.source, node_index); + self.nodes.push(SyntaxNode { + kind, + span, + child_ids: 0..0, + }); + if let Some(parent) = self.open_rules.last_mut() { + parent.children.push(syntax); + } else if self.root.is_none() { + self.root = Some(syntax); + } else { + return Err(invalid_span( + self.source, + "typed CST traversal produced multiple roots", + )); + } + Ok(syntax) + } +} + +macro_rules! typed_cst_rule_callbacks { + ($( $enter:ident, $exit:ident => $context:ident, $rule:ident; )+) => { + $( + fn $enter( + &mut self, + context: &grammar_parser::$context<'_>, + ) -> Result<(), FrontendError> { + self.enter_rule_context(context, grammar_parser::$rule) + } + + fn $exit( + &mut self, + context: &grammar_parser::$context<'_>, + ) -> Result<(), FrontendError> { + self.exit_rule_context(context, grammar_parser::$rule) + } + )+ }; - let span = node_span(source, tokens, node)?; - nodes.push(SyntaxNode { - kind, - span, - child_ids: 0..0, - }); +} + +impl ANTLRv4Listener for TypedCstBuilder<'_> { + typed_cst_rule_callbacks! { + enter_grammar_spec, exit_grammar_spec => GrammarSpecContext, RULE_GRAMMAR_SPEC; + enter_grammar_decl, exit_grammar_decl => GrammarDeclContext, RULE_GRAMMAR_DECL; + enter_grammar_type, exit_grammar_type => GrammarTypeContext, RULE_GRAMMAR_TYPE; + enter_prequel_construct, exit_prequel_construct => PrequelConstructContext, RULE_PREQUEL_CONSTRUCT; + enter_options_spec, exit_options_spec => OptionsSpecContext, RULE_OPTIONS_SPEC; + enter_option, exit_option => OptionContext, RULE_OPTION; + enter_option_value, exit_option_value => OptionValueContext, RULE_OPTION_VALUE; + enter_delegate_grammars, exit_delegate_grammars => DelegateGrammarsContext, RULE_DELEGATE_GRAMMARS; + enter_delegate_grammar, exit_delegate_grammar => DelegateGrammarContext, RULE_DELEGATE_GRAMMAR; + enter_tokens_spec, exit_tokens_spec => TokensSpecContext, RULE_TOKENS_SPEC; + enter_channels_spec, exit_channels_spec => ChannelsSpecContext, RULE_CHANNELS_SPEC; + enter_id_list, exit_id_list => IdListContext, RULE_ID_LIST; + enter_action, exit_action => ActionContext, RULE_ACTION; + enter_action_scope_name, exit_action_scope_name => ActionScopeNameContext, RULE_ACTION_SCOPE_NAME; + enter_action_block, exit_action_block => ActionBlockContext, RULE_ACTION_BLOCK; + enter_arg_action_block, exit_arg_action_block => ArgActionBlockContext, RULE_ARG_ACTION_BLOCK; + enter_mode_spec, exit_mode_spec => ModeSpecContext, RULE_MODE_SPEC; + enter_rules, exit_rules => RulesContext, RULE_RULES; + enter_rule_spec, exit_rule_spec => RuleSpecContext, RULE_RULE_SPEC; + enter_parser_rule_spec, exit_parser_rule_spec => ParserRuleSpecContext, RULE_PARSER_RULE_SPEC; + enter_exception_group, exit_exception_group => ExceptionGroupContext, RULE_EXCEPTION_GROUP; + enter_exception_handler, exit_exception_handler => ExceptionHandlerContext, RULE_EXCEPTION_HANDLER; + enter_finally_clause, exit_finally_clause => FinallyClauseContext, RULE_FINALLY_CLAUSE; + enter_rule_prequel, exit_rule_prequel => RulePrequelContext, RULE_RULE_PREQUEL; + enter_rule_returns, exit_rule_returns => RuleReturnsContext, RULE_RULE_RETURNS; + enter_throws_spec, exit_throws_spec => ThrowsSpecContext, RULE_THROWS_SPEC; + enter_locals_spec, exit_locals_spec => LocalsSpecContext, RULE_LOCALS_SPEC; + enter_rule_action, exit_rule_action => RuleActionContext, RULE_RULE_ACTION; + enter_rule_modifiers, exit_rule_modifiers => RuleModifiersContext, RULE_RULE_MODIFIERS; + enter_rule_modifier, exit_rule_modifier => RuleModifierContext, RULE_RULE_MODIFIER; + enter_rule_block, exit_rule_block => RuleBlockContext, RULE_RULE_BLOCK; + enter_rule_alt_list, exit_rule_alt_list => RuleAltListContext, RULE_RULE_ALT_LIST; + enter_labeled_alt, exit_labeled_alt => LabeledAltContext, RULE_LABELED_ALT; + enter_lexer_rule_spec, exit_lexer_rule_spec => LexerRuleSpecContext, RULE_LEXER_RULE_SPEC; + enter_lexer_rule_block, exit_lexer_rule_block => LexerRuleBlockContext, RULE_LEXER_RULE_BLOCK; + enter_lexer_alt_list, exit_lexer_alt_list => LexerAltListContext, RULE_LEXER_ALT_LIST; + enter_lexer_alt, exit_lexer_alt => LexerAltContext, RULE_LEXER_ALT; + enter_lexer_elements, exit_lexer_elements => LexerElementsContext, RULE_LEXER_ELEMENTS; + enter_lexer_element, exit_lexer_element => LexerElementContext, RULE_LEXER_ELEMENT; + enter_lexer_block, exit_lexer_block => LexerBlockContext, RULE_LEXER_BLOCK; + enter_lexer_commands, exit_lexer_commands => LexerCommandsContext, RULE_LEXER_COMMANDS; + enter_lexer_command, exit_lexer_command => LexerCommandContext, RULE_LEXER_COMMAND; + enter_lexer_command_name, exit_lexer_command_name => LexerCommandNameContext, RULE_LEXER_COMMAND_NAME; + enter_lexer_command_expr, exit_lexer_command_expr => LexerCommandExprContext, RULE_LEXER_COMMAND_EXPR; + enter_alt_list, exit_alt_list => AltListContext, RULE_ALT_LIST; + enter_alternative, exit_alternative => AlternativeContext, RULE_ALTERNATIVE; + enter_element, exit_element => ElementContext, RULE_ELEMENT; + enter_predicate_options, exit_predicate_options => PredicateOptionsContext, RULE_PREDICATE_OPTIONS; + enter_predicate_option, exit_predicate_option => PredicateOptionContext, RULE_PREDICATE_OPTION; + enter_labeled_element, exit_labeled_element => LabeledElementContext, RULE_LABELED_ELEMENT; + enter_ebnf, exit_ebnf => EbnfContext, RULE_EBNF; + enter_block_suffix, exit_block_suffix => BlockSuffixContext, RULE_BLOCK_SUFFIX; + enter_ebnf_suffix, exit_ebnf_suffix => EbnfSuffixContext, RULE_EBNF_SUFFIX; + enter_lexer_atom, exit_lexer_atom => LexerAtomContext, RULE_LEXER_ATOM; + enter_atom, exit_atom => AtomContext, RULE_ATOM; + enter_wildcard, exit_wildcard => WildcardContext, RULE_WILDCARD; + enter_not_set, exit_not_set => NotSetContext, RULE_NOT_SET; + enter_block_set, exit_block_set => BlockSetContext, RULE_BLOCK_SET; + enter_set_element, exit_set_element => SetElementContext, RULE_SET_ELEMENT; + enter_block, exit_block => BlockContext, RULE_BLOCK; + enter_ruleref, exit_ruleref => RulerefContext, RULE_RULEREF; + enter_character_range, exit_character_range => CharacterRangeContext, RULE_CHARACTER_RANGE; + enter_terminal_def, exit_terminal_def => TerminalDefContext, RULE_TERMINAL_DEF; + enter_element_options, exit_element_options => ElementOptionsContext, RULE_ELEMENT_OPTIONS; + enter_element_option, exit_element_option => ElementOptionContext, RULE_ELEMENT_OPTION; + enter_identifier, exit_identifier => IdentifierContext, RULE_IDENTIFIER; + enter_qualified_identifier, exit_qualified_identifier => QualifiedIdentifierContext, RULE_QUALIFIED_IDENTIFIER; + } - let mut direct_children = Vec::new(); - for child in node.children() { - direct_children.push(copy_node(source, tokens, child, nodes, children)?); + fn visit_terminal( + &mut self, + node: &grammar_parser::TerminalNode<'_>, + ) -> Result<(), FrontendError> { + self.push_token(node.symbol().token_id().index(), false) + } + + fn visit_error_node( + &mut self, + node: &grammar_parser::ErrorNode<'_>, + ) -> Result<(), FrontendError> { + self.push_token(node.symbol().token_id().index(), true) } - let child_start = u32::try_from(children.len()) - .map_err(|_| invalid_span(source, "CST exceeds 2^32 edges"))?; - children.extend(direct_children); - let child_end = u32::try_from(children.len()) - .map_err(|_| invalid_span(source, "CST exceeds 2^32 edges"))?; - nodes[node_index as usize].child_ids = child_start..child_end; - Ok(SyntaxId::for_source(source, node_index)) } fn node_span( diff --git a/src/bin_support/grammar/generated/antlr_v4_parser.rs b/src/bin_support/grammar/generated/antlr_v4_parser.rs index 7f2f8692..1c6d0984 100644 --- a/src/bin_support/grammar/generated/antlr_v4_parser.rs +++ b/src/bin_support/grammar/generated/antlr_v4_parser.rs @@ -13,7 +13,7 @@ use std::sync::OnceLock; #[allow(unused_imports)] use std::io::Write as _; #[allow(unused_imports)] -use antlr4_runtime::{java_style_list, PredictionMode, BailErrorStrategy, TerminalNodeView as RuntimeTerminalNode, ErrorNodeView as RuntimeErrorNode, RuleNodeView, FromRuleNode, Token as _}; +use antlr4_runtime::{java_style_list, PredictionMode, BailErrorStrategy, TerminalNodeView as RuntimeTerminalNode, ErrorNodeView as RuntimeErrorNode, RuleNodeView, AsRuleNode, FromRuleNode, MissingChildError, Token as _}; pub const EOF: i32 = antlr4_runtime::TOKEN_EOF; @@ -611,7 +611,7 @@ impl std::fmt::Display for ErrorNode<'_> { } #[allow(dead_code)] -#[derive(Clone)] +#[derive(Clone, Copy)] enum __GeneratedRuleContext<'a> { Stored(RuleNodeView<'a>), Active { @@ -621,6 +621,84 @@ enum __GeneratedRuleContext<'a> { }, } +#[doc(hidden)] +#[derive(Clone, Copy, Debug)] +pub struct StoredTreeContext; + +#[derive(Clone, Copy, Debug)] +struct __ActiveParserContext; + +#[allow(dead_code)] +fn __context_children<'a>( + source: __GeneratedRuleContext<'a>, +) -> impl Iterator> + 'a { + let mut stored = match source { + __GeneratedRuleContext::Stored(node) => Some(node.children()), + __GeneratedRuleContext::Active { .. } => None, + }; + let mut active = match source { + __GeneratedRuleContext::Stored(_) => None, + __GeneratedRuleContext::Active { + context, + storage, + tokens, + } => Some(context.child_nodes(storage, tokens)), + }; + std::iter::from_fn(move || { + stored + .as_mut() + .and_then(Iterator::next) + .or_else(|| active.as_mut().and_then(Iterator::next)) + }) +} + +#[allow(dead_code)] +fn __rule_children<'a>( + source: __GeneratedRuleContext<'a>, + rule_index: usize, +) -> impl Iterator> + 'a { + __context_children(source).filter_map(move |child| { + let rule = child.as_rule()?; + (rule.rule_index() == rule_index).then_some(rule) + }) +} + +#[allow(dead_code)] +fn __token_children<'a>( + source: __GeneratedRuleContext<'a>, + token_type: i32, +) -> impl Iterator> + 'a { + __context_children(source).filter_map(move |child| { + let terminal = match child.kind() { + antlr4_runtime::NodeKind::Terminal => child.as_terminal(), + antlr4_runtime::NodeKind::Error => { + child.as_error().map(antlr4_runtime::ErrorNodeView::terminal) + } + antlr4_runtime::NodeKind::Rule => None, + }?; + (terminal.symbol().token_type() == token_type).then_some(terminal) + }) +} + +#[allow(dead_code)] +fn __token_children_matching<'a>( + source: __GeneratedRuleContext<'a>, + token_types: &'static [i32], +) -> impl Iterator> + 'a { + __context_children(source).filter_map(move |child| { + let terminal = match child.kind() { + antlr4_runtime::NodeKind::Terminal => child.as_terminal(), + antlr4_runtime::NodeKind::Error => { + child.as_error().map(antlr4_runtime::ErrorNodeView::terminal) + } + antlr4_runtime::NodeKind::Rule => None, + }?; + token_types + .contains(&terminal.symbol().token_type()) + .then_some(terminal) + }) +} + #[allow(dead_code)] trait __FromActiveRuleContext<'a>: Sized { fn __from_active( @@ -641,11 +719,26 @@ fn __active_context_view<'a, T: __FromActiveRuleContext<'a>>( T::__from_active(context, invocation_states, storage, tokens) } +#[allow(dead_code)] +fn __context_kind(context: RuleNodeView<'_>) -> usize { + context.rule_index() +} + +#[allow(dead_code)] +fn __active_context_kind( + context: &antlr4_runtime::ParserRuleContext, + _storage: &antlr4_runtime::ParseTreeStorage, + _tokens: &antlr4_runtime::TokenStore, +) -> usize { + context.rule_index() +} + #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct GrammarSpecContext<'a> { +pub struct GrammarSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for GrammarSpecContext<'a> { @@ -655,7 +748,20 @@ impl<'a> FromRuleNode<'a> for GrammarSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for GrammarSpecContext<'a> { +impl<'a> AsRuleNode<'a> for GrammarSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> GrammarSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for GrammarSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -668,6 +774,7 @@ impl<'a> __FromActiveRuleContext<'a> for GrammarSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -699,15 +806,21 @@ impl<'a> GrammarSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> GrammarSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -715,65 +828,35 @@ impl<'a> GrammarSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn grammar_decl(&self, index: usize) -> GrammarDeclContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(1).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 1).nth(index), - }.expect("missing rule child"); - GrammarDeclContext::__from_child_node(node, &self.__invocation_states) - } - pub fn grammar_decl_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(1).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 1).collect(), - }; - nodes.into_iter().map(|node| GrammarDeclContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn prequel_construct(&self, index: usize) -> PrequelConstructContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(3).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 3).nth(index), - }.expect("missing rule child"); - PrequelConstructContext::__from_child_node(node, &self.__invocation_states) - } - pub fn prequel_construct_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(3).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 3).collect(), - }; - nodes.into_iter().map(|node| PrequelConstructContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn mode_spec(&self, index: usize) -> ModeSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(16).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 16).nth(index), - }.expect("missing rule child"); - ModeSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn mode_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(16).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 16).collect(), - }; - nodes.into_iter().map(|node| ModeSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rules(&self, index: usize) -> RulesContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(17).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 17).nth(index), - }.expect("missing rule child"); - RulesContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rules_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(17).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 17).collect(), - }; - nodes.into_iter().map(|node| RulesContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn grammar_decl(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 1) + .next() + .map(|node| GrammarDeclContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("GrammarSpecContext", "grammarDecl")) + } + pub fn prequel_construct_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 3) + .map(move |node| PrequelConstructContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn mode_spec_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 16) + .map(move |node| ModeSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rules(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 17) + .next() + .map(|node| RulesContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("GrammarSpecContext", "rules")) + } + pub fn eof_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, -1) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("GrammarSpecContext", "EOF")) } } -impl std::fmt::Display for GrammarSpecContext<'_> { +impl std::fmt::Display for GrammarSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -782,9 +865,10 @@ impl std::fmt::Display for GrammarSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct GrammarDeclContext<'a> { +pub struct GrammarDeclContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for GrammarDeclContext<'a> { @@ -794,7 +878,20 @@ impl<'a> FromRuleNode<'a> for GrammarDeclContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for GrammarDeclContext<'a> { +impl<'a> AsRuleNode<'a> for GrammarDeclContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> GrammarDeclContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for GrammarDeclContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -807,6 +904,7 @@ impl<'a> __FromActiveRuleContext<'a> for GrammarDeclContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -838,15 +936,21 @@ impl<'a> GrammarDeclContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> GrammarDeclContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -854,53 +958,27 @@ impl<'a> GrammarDeclContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn grammar_type(&self, index: usize) -> GrammarTypeContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(2).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 2).nth(index), - }.expect("missing rule child"); - GrammarTypeContext::__from_child_node(node, &self.__invocation_states) - } - pub fn grammar_type_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(2).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 2).collect(), - }; - nodes.into_iter().map(|node| GrammarTypeContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn SEMI(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn SEMI_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn grammar_type(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 2) + .next() + .map(|node| GrammarTypeContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("GrammarDeclContext", "grammarType")) + } + pub fn identifier(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("GrammarDeclContext", "identifier")) + } + pub fn semi_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 56) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("GrammarDeclContext", "SEMI")) } } -impl std::fmt::Display for GrammarDeclContext<'_> { +impl std::fmt::Display for GrammarDeclContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -909,9 +987,10 @@ impl std::fmt::Display for GrammarDeclContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct GrammarTypeContext<'a> { +pub struct GrammarTypeContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for GrammarTypeContext<'a> { @@ -921,7 +1000,20 @@ impl<'a> FromRuleNode<'a> for GrammarTypeContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for GrammarTypeContext<'a> { +impl<'a> AsRuleNode<'a> for GrammarTypeContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> GrammarTypeContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for GrammarTypeContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -934,6 +1026,7 @@ impl<'a> __FromActiveRuleContext<'a> for GrammarTypeContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -965,15 +1058,21 @@ impl<'a> GrammarTypeContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> GrammarTypeContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -981,57 +1080,25 @@ impl<'a> GrammarTypeContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - #[allow(non_snake_case)] - pub fn LEXER(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(41).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 41).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LEXER_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(41).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 41).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn PARSER(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(42).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 42).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn PARSER_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(42).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 42).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn GRAMMAR(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(43).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 43).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn GRAMMAR_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(43).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 43).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn lexer_token(&self) -> Option> { + __token_children(self.__node, 41) + .next() + .map(TerminalNode::new) + } + pub fn parser_token(&self) -> Option> { + __token_children(self.__node, 42) + .next() + .map(TerminalNode::new) + } + pub fn grammar_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 43) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("GrammarTypeContext", "GRAMMAR")) } } -impl std::fmt::Display for GrammarTypeContext<'_> { +impl std::fmt::Display for GrammarTypeContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1040,9 +1107,10 @@ impl std::fmt::Display for GrammarTypeContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct PrequelConstructContext<'a> { +pub struct PrequelConstructContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for PrequelConstructContext<'a> { @@ -1052,7 +1120,20 @@ impl<'a> FromRuleNode<'a> for PrequelConstructContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for PrequelConstructContext<'a> { +impl<'a> AsRuleNode<'a> for PrequelConstructContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> PrequelConstructContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for PrequelConstructContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1065,6 +1146,7 @@ impl<'a> __FromActiveRuleContext<'a> for PrequelConstructContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1096,15 +1178,21 @@ impl<'a> PrequelConstructContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> PrequelConstructContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1112,79 +1200,34 @@ impl<'a> PrequelConstructContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn options_spec(&self, index: usize) -> OptionsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).nth(index), - }.expect("missing rule child"); - OptionsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn options_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).collect(), - }; - nodes.into_iter().map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn delegate_grammars(&self, index: usize) -> DelegateGrammarsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(7).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 7).nth(index), - }.expect("missing rule child"); - DelegateGrammarsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn delegate_grammars_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(7).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 7).collect(), - }; - nodes.into_iter().map(|node| DelegateGrammarsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn tokens_spec(&self, index: usize) -> TokensSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(9).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 9).nth(index), - }.expect("missing rule child"); - TokensSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn tokens_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(9).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 9).collect(), - }; - nodes.into_iter().map(|node| TokensSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn channels_spec(&self, index: usize) -> ChannelsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(10).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 10).nth(index), - }.expect("missing rule child"); - ChannelsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn channels_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(10).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 10).collect(), - }; - nodes.into_iter().map(|node| ChannelsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn action(&self, index: usize) -> ActionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(12).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 12).nth(index), - }.expect("missing rule child"); - ActionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(12).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 12).collect(), - }; - nodes.into_iter().map(|node| ActionContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn options_spec(&self) -> Option> { + __rule_children(self.__node, 4) + .next() + .map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn delegate_grammars(&self) -> Option> { + __rule_children(self.__node, 7) + .next() + .map(|node| DelegateGrammarsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn tokens_spec(&self) -> Option> { + __rule_children(self.__node, 9) + .next() + .map(|node| TokensSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn channels_spec(&self) -> Option> { + __rule_children(self.__node, 10) + .next() + .map(|node| ChannelsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn action(&self) -> Option> { + __rule_children(self.__node, 12) + .next() + .map(|node| ActionContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for PrequelConstructContext<'_> { +impl std::fmt::Display for PrequelConstructContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1193,9 +1236,10 @@ impl std::fmt::Display for PrequelConstructContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct OptionsSpecContext<'a> { +pub struct OptionsSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for OptionsSpecContext<'a> { @@ -1205,7 +1249,20 @@ impl<'a> FromRuleNode<'a> for OptionsSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for OptionsSpecContext<'a> { +impl<'a> AsRuleNode<'a> for OptionsSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> OptionsSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for OptionsSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1218,6 +1275,7 @@ impl<'a> __FromActiveRuleContext<'a> for OptionsSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1249,15 +1307,21 @@ impl<'a> OptionsSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> OptionsSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1265,71 +1329,28 @@ impl<'a> OptionsSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn option(&self, index: usize) -> OptionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(5).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 5).nth(index), - }.expect("missing rule child"); - OptionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn option_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(5).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 5).collect(), - }; - nodes.into_iter().map(|node| OptionContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn OPTIONS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(36).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 36).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn OPTIONS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(36).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 36).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn SEMI(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn SEMI_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RBRACE(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(59).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 59).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RBRACE_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(59).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 59).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn option_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 5) + .map(move |node| OptionContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn options_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 36) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("OptionsSpecContext", "OPTIONS")) + } + pub fn semi_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 56).map(TerminalNode::new) + } + pub fn rbrace_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 59) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("OptionsSpecContext", "RBRACE")) } } -impl std::fmt::Display for OptionsSpecContext<'_> { +impl std::fmt::Display for OptionsSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1338,9 +1359,10 @@ impl std::fmt::Display for OptionsSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct OptionContext<'a> { +pub struct OptionContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for OptionContext<'a> { @@ -1350,7 +1372,20 @@ impl<'a> FromRuleNode<'a> for OptionContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for OptionContext<'a> { +impl<'a> AsRuleNode<'a> for OptionContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> OptionContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for OptionContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1363,6 +1398,7 @@ impl<'a> __FromActiveRuleContext<'a> for OptionContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1394,15 +1430,21 @@ impl<'a> OptionContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> OptionContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1410,53 +1452,27 @@ impl<'a> OptionContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn option_value(&self, index: usize) -> OptionValueContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(6).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 6).nth(index), - }.expect("missing rule child"); - OptionValueContext::__from_child_node(node, &self.__invocation_states) - } - pub fn option_value_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(6).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 6).collect(), - }; - nodes.into_iter().map(|node| OptionValueContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn ASSIGN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn ASSIGN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn option_value(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 6) + .next() + .map(|node| OptionValueContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("OptionContext", "optionValue")) + } + pub fn identifier(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("OptionContext", "identifier")) + } + pub fn assign_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 7) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("OptionContext", "ASSIGN")) } } -impl std::fmt::Display for OptionContext<'_> { +impl std::fmt::Display for OptionContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1465,9 +1481,10 @@ impl std::fmt::Display for OptionContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct OptionValueContext<'a> { +pub struct OptionValueContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for OptionValueContext<'a> { @@ -1477,7 +1494,20 @@ impl<'a> FromRuleNode<'a> for OptionValueContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for OptionValueContext<'a> { +impl<'a> AsRuleNode<'a> for OptionValueContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> OptionValueContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for OptionValueContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1490,6 +1520,7 @@ impl<'a> __FromActiveRuleContext<'a> for OptionValueContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1521,15 +1552,21 @@ impl<'a> OptionValueContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> OptionValueContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1537,85 +1574,31 @@ impl<'a> OptionValueContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn INT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn INT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn DOT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(70).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 70).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn DOT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(70).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 70).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Option> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn identifier_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 65) + .map(move |node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn string_literal_token(&self) -> Option> { + __token_children(self.__node, 11) + .next() + .map(TerminalNode::new) + } + pub fn int_token(&self) -> Option> { + __token_children(self.__node, 33) + .next() + .map(TerminalNode::new) + } + pub fn dot_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 70).map(TerminalNode::new) } } -impl std::fmt::Display for OptionValueContext<'_> { +impl std::fmt::Display for OptionValueContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1624,9 +1607,10 @@ impl std::fmt::Display for OptionValueContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct DelegateGrammarsContext<'a> { +pub struct DelegateGrammarsContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for DelegateGrammarsContext<'a> { @@ -1636,7 +1620,20 @@ impl<'a> FromRuleNode<'a> for DelegateGrammarsContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for DelegateGrammarsContext<'a> { +impl<'a> AsRuleNode<'a> for DelegateGrammarsContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> DelegateGrammarsContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for DelegateGrammarsContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1649,6 +1646,7 @@ impl<'a> __FromActiveRuleContext<'a> for DelegateGrammarsContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1680,15 +1678,21 @@ impl<'a> DelegateGrammarsContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> DelegateGrammarsContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1696,71 +1700,28 @@ impl<'a> DelegateGrammarsContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn delegate_grammar(&self, index: usize) -> DelegateGrammarContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(8).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 8).nth(index), - }.expect("missing rule child"); - DelegateGrammarContext::__from_child_node(node, &self.__invocation_states) - } - pub fn delegate_grammar_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(8).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 8).collect(), - }; - nodes.into_iter().map(|node| DelegateGrammarContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn IMPORT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(39).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 39).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn IMPORT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(39).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 39).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn COMMA(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COMMA_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn SEMI(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn SEMI_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn delegate_grammar_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 8) + .map(move |node| DelegateGrammarContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn import_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 39) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("DelegateGrammarsContext", "IMPORT")) + } + pub fn comma_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 55).map(TerminalNode::new) + } + pub fn semi_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 56) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("DelegateGrammarsContext", "SEMI")) } } -impl std::fmt::Display for DelegateGrammarsContext<'_> { +impl std::fmt::Display for DelegateGrammarsContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1769,9 +1730,10 @@ impl std::fmt::Display for DelegateGrammarsContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct DelegateGrammarContext<'a> { +pub struct DelegateGrammarContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for DelegateGrammarContext<'a> { @@ -1781,7 +1743,20 @@ impl<'a> FromRuleNode<'a> for DelegateGrammarContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for DelegateGrammarContext<'a> { +impl<'a> AsRuleNode<'a> for DelegateGrammarContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> DelegateGrammarContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for DelegateGrammarContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1794,6 +1769,7 @@ impl<'a> __FromActiveRuleContext<'a> for DelegateGrammarContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1825,15 +1801,21 @@ impl<'a> DelegateGrammarContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> DelegateGrammarContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1841,39 +1823,18 @@ impl<'a> DelegateGrammarContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn ASSIGN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn ASSIGN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 65) + .map(move |node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn assign_token(&self) -> Option> { + __token_children(self.__node, 7) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for DelegateGrammarContext<'_> { +impl std::fmt::Display for DelegateGrammarContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -1882,9 +1843,10 @@ impl std::fmt::Display for DelegateGrammarContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct TokensSpecContext<'a> { +pub struct TokensSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for TokensSpecContext<'a> { @@ -1894,7 +1856,20 @@ impl<'a> FromRuleNode<'a> for TokensSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for TokensSpecContext<'a> { +impl<'a> AsRuleNode<'a> for TokensSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> TokensSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for TokensSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -1907,6 +1882,7 @@ impl<'a> __FromActiveRuleContext<'a> for TokensSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -1938,15 +1914,21 @@ impl<'a> TokensSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> TokensSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -1954,55 +1936,26 @@ impl<'a> TokensSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn id_list(&self, index: usize) -> IdListContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 11).nth(index), - }.expect("missing rule child"); - IdListContext::__from_child_node(node, &self.__invocation_states) - } - pub fn id_list_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(|node| IdListContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn TOKENS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(37).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 37).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn TOKENS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(37).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 37).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RBRACE(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(59).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 59).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RBRACE_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(59).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 59).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn id_list(&self) -> Option> { + __rule_children(self.__node, 11) + .next() + .map(|node| IdListContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn tokens_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 37) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("TokensSpecContext", "TOKENS")) + } + pub fn rbrace_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 59) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("TokensSpecContext", "RBRACE")) } } -impl std::fmt::Display for TokensSpecContext<'_> { +impl std::fmt::Display for TokensSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2011,9 +1964,10 @@ impl std::fmt::Display for TokensSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ChannelsSpecContext<'a> { +pub struct ChannelsSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ChannelsSpecContext<'a> { @@ -2023,7 +1977,20 @@ impl<'a> FromRuleNode<'a> for ChannelsSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ChannelsSpecContext<'a> { +impl<'a> AsRuleNode<'a> for ChannelsSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ChannelsSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ChannelsSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2036,6 +2003,7 @@ impl<'a> __FromActiveRuleContext<'a> for ChannelsSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2067,15 +2035,21 @@ impl<'a> ChannelsSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ChannelsSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2083,55 +2057,26 @@ impl<'a> ChannelsSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn id_list(&self, index: usize) -> IdListContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 11).nth(index), - }.expect("missing rule child"); - IdListContext::__from_child_node(node, &self.__invocation_states) - } - pub fn id_list_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(|node| IdListContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn CHANNELS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(38).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 38).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn CHANNELS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(38).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 38).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RBRACE(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(59).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 59).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RBRACE_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(59).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 59).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn id_list(&self) -> Option> { + __rule_children(self.__node, 11) + .next() + .map(|node| IdListContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn channels_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 38) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ChannelsSpecContext", "CHANNELS")) + } + pub fn rbrace_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 59) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ChannelsSpecContext", "RBRACE")) } } -impl std::fmt::Display for ChannelsSpecContext<'_> { +impl std::fmt::Display for ChannelsSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2140,9 +2085,10 @@ impl std::fmt::Display for ChannelsSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct IdListContext<'a> { +pub struct IdListContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for IdListContext<'a> { @@ -2152,7 +2098,20 @@ impl<'a> FromRuleNode<'a> for IdListContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for IdListContext<'a> { +impl<'a> AsRuleNode<'a> for IdListContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> IdListContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for IdListContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2165,6 +2124,7 @@ impl<'a> __FromActiveRuleContext<'a> for IdListContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2196,15 +2156,21 @@ impl<'a> IdListContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> IdListContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2212,39 +2178,16 @@ impl<'a> IdListContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn COMMA(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COMMA_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 65) + .map(move |node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn comma_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 55).map(TerminalNode::new) } } -impl std::fmt::Display for IdListContext<'_> { +impl std::fmt::Display for IdListContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2253,9 +2196,10 @@ impl std::fmt::Display for IdListContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ActionContext<'a> { +pub struct ActionContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ActionContext<'a> { @@ -2265,7 +2209,20 @@ impl<'a> FromRuleNode<'a> for ActionContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ActionContext<'a> { +impl<'a> AsRuleNode<'a> for ActionContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ActionContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ActionContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2278,6 +2235,7 @@ impl<'a> __FromActiveRuleContext<'a> for ActionContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2309,15 +2267,21 @@ impl<'a> ActionContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ActionContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2325,83 +2289,37 @@ impl<'a> ActionContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_scope_name(&self, index: usize) -> ActionScopeNameContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(13).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 13).nth(index), - }.expect("missing rule child"); - ActionScopeNameContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_scope_name_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(13).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 13).collect(), - }; - nodes.into_iter().map(|node| ActionScopeNameContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn COLONCOLON(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(54).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 54).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COLONCOLON_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(54).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 54).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn AT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(71).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 71).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn AT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(71).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 71).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_scope_name(&self) -> Option> { + __rule_children(self.__node, 13) + .next() + .map(|node| ActionScopeNameContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ActionContext", "actionBlock")) + } + pub fn identifier(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ActionContext", "identifier")) + } + pub fn coloncolon_token(&self) -> Option> { + __token_children(self.__node, 54) + .next() + .map(TerminalNode::new) + } + pub fn at_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 71) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ActionContext", "AT")) } } -impl std::fmt::Display for ActionContext<'_> { +impl std::fmt::Display for ActionContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2410,9 +2328,10 @@ impl std::fmt::Display for ActionContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ActionScopeNameContext<'a> { +pub struct ActionScopeNameContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ActionScopeNameContext<'a> { @@ -2422,7 +2341,20 @@ impl<'a> FromRuleNode<'a> for ActionScopeNameContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ActionScopeNameContext<'a> { +impl<'a> AsRuleNode<'a> for ActionScopeNameContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ActionScopeNameContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ActionScopeNameContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2435,6 +2367,7 @@ impl<'a> __FromActiveRuleContext<'a> for ActionScopeNameContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2466,15 +2399,21 @@ impl<'a> ActionScopeNameContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } - pub fn child_count(&self) -> usize { +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ActionScopeNameContext<'a, State> { + pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2482,55 +2421,24 @@ impl<'a> ActionScopeNameContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LEXER(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(41).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 41).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LEXER_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(41).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 41).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn PARSER(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(42).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 42).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn PARSER_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(42).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 42).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier(&self) -> Option> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_token(&self) -> Option> { + __token_children(self.__node, 41) + .next() + .map(TerminalNode::new) + } + pub fn parser_token(&self) -> Option> { + __token_children(self.__node, 42) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for ActionScopeNameContext<'_> { +impl std::fmt::Display for ActionScopeNameContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2539,9 +2447,10 @@ impl std::fmt::Display for ActionScopeNameContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ActionBlockContext<'a> { +pub struct ActionBlockContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ActionBlockContext<'a> { @@ -2551,7 +2460,20 @@ impl<'a> FromRuleNode<'a> for ActionBlockContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ActionBlockContext<'a> { +impl<'a> AsRuleNode<'a> for ActionBlockContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ActionBlockContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ActionBlockContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2564,6 +2486,7 @@ impl<'a> __FromActiveRuleContext<'a> for ActionBlockContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2595,15 +2518,21 @@ impl<'a> ActionBlockContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ActionBlockContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2611,25 +2540,15 @@ impl<'a> ActionBlockContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - #[allow(non_snake_case)] - pub fn ACTION(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(4).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 4).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn ACTION_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(4).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 4).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 4) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ActionBlockContext", "ACTION")) } } -impl std::fmt::Display for ActionBlockContext<'_> { +impl std::fmt::Display for ActionBlockContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2638,9 +2557,10 @@ impl std::fmt::Display for ActionBlockContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ArgActionBlockContext<'a> { +pub struct ArgActionBlockContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ArgActionBlockContext<'a> { @@ -2650,7 +2570,20 @@ impl<'a> FromRuleNode<'a> for ArgActionBlockContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ArgActionBlockContext<'a> { +impl<'a> AsRuleNode<'a> for ArgActionBlockContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ArgActionBlockContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ArgActionBlockContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2663,6 +2596,7 @@ impl<'a> __FromActiveRuleContext<'a> for ArgActionBlockContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2694,15 +2628,21 @@ impl<'a> ArgActionBlockContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ArgActionBlockContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2710,57 +2650,24 @@ impl<'a> ArgActionBlockContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - #[allow(non_snake_case)] - pub fn BEGIN_ARGUMENT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(35).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 35).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn BEGIN_ARGUMENT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(35).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 35).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn END_ARGUMENT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(75).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 75).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn END_ARGUMENT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(75).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 75).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn ARGUMENT_CONTENT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(77).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 77).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn ARGUMENT_CONTENT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(77).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 77).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn begin_argument_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 35) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ArgActionBlockContext", "BEGIN_ARGUMENT")) + } + pub fn end_argument_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 75) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ArgActionBlockContext", "END_ARGUMENT")) + } + pub fn argument_content_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 77).map(TerminalNode::new) } } -impl std::fmt::Display for ArgActionBlockContext<'_> { +impl std::fmt::Display for ArgActionBlockContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2769,9 +2676,10 @@ impl std::fmt::Display for ArgActionBlockContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ModeSpecContext<'a> { +pub struct ModeSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ModeSpecContext<'a> { @@ -2781,7 +2689,20 @@ impl<'a> FromRuleNode<'a> for ModeSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ModeSpecContext<'a> { +impl<'a> AsRuleNode<'a> for ModeSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ModeSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ModeSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2794,6 +2715,7 @@ impl<'a> __FromActiveRuleContext<'a> for ModeSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2825,15 +2747,21 @@ impl<'a> ModeSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ModeSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2841,69 +2769,31 @@ impl<'a> ModeSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_rule_spec(&self, index: usize) -> LexerRuleSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(33).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 33).nth(index), - }.expect("missing rule child"); - LexerRuleSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_rule_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(33).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 33).collect(), - }; - nodes.into_iter().map(|node| LexerRuleSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn MODE(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(52).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 52).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn MODE_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(52).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 52).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn SEMI(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn SEMI_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn lexer_rule_spec_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 33) + .map(move |node| LexerRuleSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn identifier(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ModeSpecContext", "identifier")) + } + pub fn mode_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 52) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ModeSpecContext", "MODE")) + } + pub fn semi_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 56) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ModeSpecContext", "SEMI")) } } -impl std::fmt::Display for ModeSpecContext<'_> { +impl std::fmt::Display for ModeSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -2912,9 +2802,10 @@ impl std::fmt::Display for ModeSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RulesContext<'a> { +pub struct RulesContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RulesContext<'a> { @@ -2924,7 +2815,20 @@ impl<'a> FromRuleNode<'a> for RulesContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RulesContext<'a> { +impl<'a> AsRuleNode<'a> for RulesContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RulesContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RulesContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -2937,6 +2841,7 @@ impl<'a> __FromActiveRuleContext<'a> for RulesContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -2968,15 +2873,21 @@ impl<'a> RulesContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RulesContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -2984,23 +2895,13 @@ impl<'a> RulesContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn rule_spec(&self, index: usize) -> RuleSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(18).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 18).nth(index), - }.expect("missing rule child"); - RuleSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(18).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 18).collect(), - }; - nodes.into_iter().map(|node| RuleSpecContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn rule_spec_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 18) + .map(move |node| RuleSpecContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for RulesContext<'_> { +impl std::fmt::Display for RulesContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3009,9 +2910,10 @@ impl std::fmt::Display for RulesContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleSpecContext<'a> { +pub struct RuleSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleSpecContext<'a> { @@ -3021,7 +2923,20 @@ impl<'a> FromRuleNode<'a> for RuleSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleSpecContext<'a> { +impl<'a> AsRuleNode<'a> for RuleSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3034,6 +2949,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3065,15 +2981,21 @@ impl<'a> RuleSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3081,37 +3003,19 @@ impl<'a> RuleSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn parser_rule_spec(&self, index: usize) -> ParserRuleSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(19).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 19).nth(index), - }.expect("missing rule child"); - ParserRuleSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn parser_rule_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(19).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 19).collect(), - }; - nodes.into_iter().map(|node| ParserRuleSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn lexer_rule_spec(&self, index: usize) -> LexerRuleSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(33).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 33).nth(index), - }.expect("missing rule child"); - LexerRuleSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_rule_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(33).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 33).collect(), - }; - nodes.into_iter().map(|node| LexerRuleSpecContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn parser_rule_spec(&self) -> Option> { + __rule_children(self.__node, 19) + .next() + .map(|node| ParserRuleSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_rule_spec(&self) -> Option> { + __rule_children(self.__node, 33) + .next() + .map(|node| LexerRuleSpecContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for RuleSpecContext<'_> { +impl std::fmt::Display for RuleSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3120,9 +3024,10 @@ impl std::fmt::Display for RuleSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ParserRuleSpecContext<'a> { +pub struct ParserRuleSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ParserRuleSpecContext<'a> { @@ -3132,7 +3037,20 @@ impl<'a> FromRuleNode<'a> for ParserRuleSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ParserRuleSpecContext<'a> { +impl<'a> AsRuleNode<'a> for ParserRuleSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ParserRuleSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ParserRuleSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3145,6 +3063,7 @@ impl<'a> __FromActiveRuleContext<'a> for ParserRuleSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3176,15 +3095,21 @@ impl<'a> ParserRuleSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ParserRuleSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3192,169 +3117,68 @@ impl<'a> ParserRuleSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn arg_action_block(&self, index: usize) -> ArgActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).nth(index), - }.expect("missing rule child"); - ArgActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn arg_action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).collect(), - }; - nodes.into_iter().map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn exception_group(&self, index: usize) -> ExceptionGroupContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(20).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 20).nth(index), - }.expect("missing rule child"); - ExceptionGroupContext::__from_child_node(node, &self.__invocation_states) - } - pub fn exception_group_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(20).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 20).collect(), - }; - nodes.into_iter().map(|node| ExceptionGroupContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rule_prequel(&self, index: usize) -> RulePrequelContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(23).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 23).nth(index), - }.expect("missing rule child"); - RulePrequelContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_prequel_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(23).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 23).collect(), - }; - nodes.into_iter().map(|node| RulePrequelContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rule_returns(&self, index: usize) -> RuleReturnsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(24).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 24).nth(index), - }.expect("missing rule child"); - RuleReturnsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_returns_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(24).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 24).collect(), - }; - nodes.into_iter().map(|node| RuleReturnsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn throws_spec(&self, index: usize) -> ThrowsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(25).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 25).nth(index), - }.expect("missing rule child"); - ThrowsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn throws_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(25).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 25).collect(), - }; - nodes.into_iter().map(|node| ThrowsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn locals_spec(&self, index: usize) -> LocalsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(26).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 26).nth(index), - }.expect("missing rule child"); - LocalsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn locals_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(26).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 26).collect(), - }; - nodes.into_iter().map(|node| LocalsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rule_modifiers(&self, index: usize) -> RuleModifiersContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(28).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 28).nth(index), - }.expect("missing rule child"); - RuleModifiersContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_modifiers_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(28).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 28).collect(), - }; - nodes.into_iter().map(|node| RuleModifiersContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rule_block(&self, index: usize) -> RuleBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(30).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 30).nth(index), - }.expect("missing rule child"); - RuleBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(30).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 30).collect(), - }; - nodes.into_iter().map(|node| RuleBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn RULE_REF(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(9).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 9).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RULE_REF_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(9).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 9).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn COLON(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(53).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 53).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COLON_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(53).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 53).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn SEMI(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn SEMI_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } -} - -impl std::fmt::Display for ParserRuleSpecContext<'_> { + pub fn arg_action_block(&self) -> Option> { + __rule_children(self.__node, 15) + .next() + .map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn exception_group(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 20) + .next() + .map(|node| ExceptionGroupContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ParserRuleSpecContext", "exceptionGroup")) + } + pub fn rule_prequel_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 23) + .map(move |node| RulePrequelContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rule_returns(&self) -> Option> { + __rule_children(self.__node, 24) + .next() + .map(|node| RuleReturnsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn throws_spec(&self) -> Option> { + __rule_children(self.__node, 25) + .next() + .map(|node| ThrowsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn locals_spec(&self) -> Option> { + __rule_children(self.__node, 26) + .next() + .map(|node| LocalsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rule_modifiers(&self) -> Option> { + __rule_children(self.__node, 28) + .next() + .map(|node| RuleModifiersContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rule_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 30) + .next() + .map(|node| RuleBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ParserRuleSpecContext", "ruleBlock")) + } + pub fn rule_ref_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 9) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ParserRuleSpecContext", "RULE_REF")) + } + pub fn colon_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 53) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ParserRuleSpecContext", "COLON")) + } + pub fn semi_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 56) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ParserRuleSpecContext", "SEMI")) + } +} + +impl std::fmt::Display for ParserRuleSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3363,9 +3187,10 @@ impl std::fmt::Display for ParserRuleSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ExceptionGroupContext<'a> { +pub struct ExceptionGroupContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ExceptionGroupContext<'a> { @@ -3375,7 +3200,20 @@ impl<'a> FromRuleNode<'a> for ExceptionGroupContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ExceptionGroupContext<'a> { +impl<'a> AsRuleNode<'a> for ExceptionGroupContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ExceptionGroupContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ExceptionGroupContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3388,6 +3226,7 @@ impl<'a> __FromActiveRuleContext<'a> for ExceptionGroupContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3419,15 +3258,21 @@ impl<'a> ExceptionGroupContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ExceptionGroupContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3435,37 +3280,18 @@ impl<'a> ExceptionGroupContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn exception_handler(&self, index: usize) -> ExceptionHandlerContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(21).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 21).nth(index), - }.expect("missing rule child"); - ExceptionHandlerContext::__from_child_node(node, &self.__invocation_states) - } - pub fn exception_handler_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(21).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 21).collect(), - }; - nodes.into_iter().map(|node| ExceptionHandlerContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn finally_clause(&self, index: usize) -> FinallyClauseContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(22).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 22).nth(index), - }.expect("missing rule child"); - FinallyClauseContext::__from_child_node(node, &self.__invocation_states) - } - pub fn finally_clause_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(22).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 22).collect(), - }; - nodes.into_iter().map(|node| FinallyClauseContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn exception_handler_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 21) + .map(move |node| ExceptionHandlerContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn finally_clause(&self) -> Option> { + __rule_children(self.__node, 22) + .next() + .map(|node| FinallyClauseContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for ExceptionGroupContext<'_> { +impl std::fmt::Display for ExceptionGroupContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3474,9 +3300,10 @@ impl std::fmt::Display for ExceptionGroupContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ExceptionHandlerContext<'a> { +pub struct ExceptionHandlerContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ExceptionHandlerContext<'a> { @@ -3486,7 +3313,20 @@ impl<'a> FromRuleNode<'a> for ExceptionHandlerContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ExceptionHandlerContext<'a> { +impl<'a> AsRuleNode<'a> for ExceptionHandlerContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ExceptionHandlerContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ExceptionHandlerContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3499,6 +3339,7 @@ impl<'a> __FromActiveRuleContext<'a> for ExceptionHandlerContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3530,15 +3371,21 @@ impl<'a> ExceptionHandlerContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ExceptionHandlerContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3546,53 +3393,27 @@ impl<'a> ExceptionHandlerContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn arg_action_block(&self, index: usize) -> ArgActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).nth(index), - }.expect("missing rule child"); - ArgActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn arg_action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).collect(), - }; - nodes.into_iter().map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn CATCH(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(50).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 50).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn CATCH_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(50).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 50).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ExceptionHandlerContext", "actionBlock")) + } + pub fn arg_action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 15) + .next() + .map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("ExceptionHandlerContext", "argActionBlock")) + } + pub fn catch_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 50) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ExceptionHandlerContext", "CATCH")) } } -impl std::fmt::Display for ExceptionHandlerContext<'_> { +impl std::fmt::Display for ExceptionHandlerContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3601,9 +3422,10 @@ impl std::fmt::Display for ExceptionHandlerContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct FinallyClauseContext<'a> { +pub struct FinallyClauseContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for FinallyClauseContext<'a> { @@ -3613,7 +3435,20 @@ impl<'a> FromRuleNode<'a> for FinallyClauseContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for FinallyClauseContext<'a> { +impl<'a> AsRuleNode<'a> for FinallyClauseContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> FinallyClauseContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for FinallyClauseContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3626,6 +3461,7 @@ impl<'a> __FromActiveRuleContext<'a> for FinallyClauseContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3657,15 +3493,21 @@ impl<'a> FinallyClauseContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> FinallyClauseContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3673,39 +3515,21 @@ impl<'a> FinallyClauseContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn FINALLY(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(51).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 51).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn FINALLY_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(51).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 51).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("FinallyClauseContext", "actionBlock")) + } + pub fn finally_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 51) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("FinallyClauseContext", "FINALLY")) } } -impl std::fmt::Display for FinallyClauseContext<'_> { +impl std::fmt::Display for FinallyClauseContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3714,9 +3538,10 @@ impl std::fmt::Display for FinallyClauseContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RulePrequelContext<'a> { +pub struct RulePrequelContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RulePrequelContext<'a> { @@ -3726,7 +3551,20 @@ impl<'a> FromRuleNode<'a> for RulePrequelContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RulePrequelContext<'a> { +impl<'a> AsRuleNode<'a> for RulePrequelContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RulePrequelContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RulePrequelContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3739,6 +3577,7 @@ impl<'a> __FromActiveRuleContext<'a> for RulePrequelContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3770,15 +3609,21 @@ impl<'a> RulePrequelContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RulePrequelContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3786,37 +3631,19 @@ impl<'a> RulePrequelContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn options_spec(&self, index: usize) -> OptionsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).nth(index), - }.expect("missing rule child"); - OptionsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn options_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).collect(), - }; - nodes.into_iter().map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rule_action(&self, index: usize) -> RuleActionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(27).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 27).nth(index), - }.expect("missing rule child"); - RuleActionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_action_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(27).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 27).collect(), - }; - nodes.into_iter().map(|node| RuleActionContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn options_spec(&self) -> Option> { + __rule_children(self.__node, 4) + .next() + .map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rule_action(&self) -> Option> { + __rule_children(self.__node, 27) + .next() + .map(|node| RuleActionContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for RulePrequelContext<'_> { +impl std::fmt::Display for RulePrequelContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3825,9 +3652,10 @@ impl std::fmt::Display for RulePrequelContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleReturnsContext<'a> { +pub struct RuleReturnsContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleReturnsContext<'a> { @@ -3837,7 +3665,20 @@ impl<'a> FromRuleNode<'a> for RuleReturnsContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleReturnsContext<'a> { +impl<'a> AsRuleNode<'a> for RuleReturnsContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleReturnsContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleReturnsContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3850,6 +3691,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleReturnsContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3881,15 +3723,21 @@ impl<'a> RuleReturnsContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleReturnsContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -3897,39 +3745,21 @@ impl<'a> RuleReturnsContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn arg_action_block(&self, index: usize) -> ArgActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).nth(index), - }.expect("missing rule child"); - ArgActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn arg_action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).collect(), - }; - nodes.into_iter().map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn RETURNS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(47).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 47).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RETURNS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(47).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 47).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn arg_action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 15) + .next() + .map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("RuleReturnsContext", "argActionBlock")) + } + pub fn returns_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 47) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("RuleReturnsContext", "RETURNS")) } } -impl std::fmt::Display for RuleReturnsContext<'_> { +impl std::fmt::Display for RuleReturnsContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -3938,9 +3768,10 @@ impl std::fmt::Display for RuleReturnsContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ThrowsSpecContext<'a> { +pub struct ThrowsSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ThrowsSpecContext<'a> { @@ -3950,7 +3781,20 @@ impl<'a> FromRuleNode<'a> for ThrowsSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ThrowsSpecContext<'a> { +impl<'a> AsRuleNode<'a> for ThrowsSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ThrowsSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ThrowsSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -3963,6 +3807,7 @@ impl<'a> __FromActiveRuleContext<'a> for ThrowsSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -3994,15 +3839,21 @@ impl<'a> ThrowsSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ThrowsSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4010,55 +3861,22 @@ impl<'a> ThrowsSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn qualified_identifier(&self, index: usize) -> QualifiedIdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(66).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 66).nth(index), - }.expect("missing rule child"); - QualifiedIdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn qualified_identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(66).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 66).collect(), - }; - nodes.into_iter().map(|node| QualifiedIdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn THROWS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(49).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 49).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn THROWS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(49).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 49).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn COMMA(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COMMA_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn qualified_identifier_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 66) + .map(move |node| QualifiedIdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn throws_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 49) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ThrowsSpecContext", "THROWS")) + } + pub fn comma_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 55).map(TerminalNode::new) } } -impl std::fmt::Display for ThrowsSpecContext<'_> { +impl std::fmt::Display for ThrowsSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4067,9 +3885,10 @@ impl std::fmt::Display for ThrowsSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LocalsSpecContext<'a> { +pub struct LocalsSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LocalsSpecContext<'a> { @@ -4079,7 +3898,20 @@ impl<'a> FromRuleNode<'a> for LocalsSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LocalsSpecContext<'a> { +impl<'a> AsRuleNode<'a> for LocalsSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LocalsSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LocalsSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4092,6 +3924,7 @@ impl<'a> __FromActiveRuleContext<'a> for LocalsSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4123,15 +3956,21 @@ impl<'a> LocalsSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LocalsSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4139,39 +3978,21 @@ impl<'a> LocalsSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn arg_action_block(&self, index: usize) -> ArgActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).nth(index), - }.expect("missing rule child"); - ArgActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn arg_action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).collect(), - }; - nodes.into_iter().map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LOCALS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(48).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 48).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LOCALS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(48).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 48).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn arg_action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 15) + .next() + .map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LocalsSpecContext", "argActionBlock")) + } + pub fn locals_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 48) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LocalsSpecContext", "LOCALS")) } } -impl std::fmt::Display for LocalsSpecContext<'_> { +impl std::fmt::Display for LocalsSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4180,9 +4001,10 @@ impl std::fmt::Display for LocalsSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleActionContext<'a> { +pub struct RuleActionContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleActionContext<'a> { @@ -4192,7 +4014,20 @@ impl<'a> FromRuleNode<'a> for RuleActionContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleActionContext<'a> { +impl<'a> AsRuleNode<'a> for RuleActionContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleActionContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleActionContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4205,6 +4040,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleActionContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4236,15 +4072,21 @@ impl<'a> RuleActionContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleActionContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4252,53 +4094,27 @@ impl<'a> RuleActionContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn AT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(71).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 71).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn AT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(71).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 71).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("RuleActionContext", "actionBlock")) + } + pub fn identifier(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("RuleActionContext", "identifier")) + } + pub fn at_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 71) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("RuleActionContext", "AT")) } } -impl std::fmt::Display for RuleActionContext<'_> { +impl std::fmt::Display for RuleActionContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4307,9 +4123,10 @@ impl std::fmt::Display for RuleActionContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleModifiersContext<'a> { +pub struct RuleModifiersContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleModifiersContext<'a> { @@ -4319,7 +4136,20 @@ impl<'a> FromRuleNode<'a> for RuleModifiersContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleModifiersContext<'a> { +impl<'a> AsRuleNode<'a> for RuleModifiersContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleModifiersContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleModifiersContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4332,6 +4162,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleModifiersContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4363,15 +4194,21 @@ impl<'a> RuleModifiersContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleModifiersContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4379,23 +4216,13 @@ impl<'a> RuleModifiersContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn rule_modifier(&self, index: usize) -> RuleModifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(29).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 29).nth(index), - }.expect("missing rule child"); - RuleModifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_modifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(29).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 29).collect(), - }; - nodes.into_iter().map(|node| RuleModifierContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn rule_modifier_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 29) + .map(move |node| RuleModifierContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for RuleModifiersContext<'_> { +impl std::fmt::Display for RuleModifiersContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4404,9 +4231,10 @@ impl std::fmt::Display for RuleModifiersContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleModifierContext<'a> { +pub struct RuleModifierContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleModifierContext<'a> { @@ -4416,7 +4244,20 @@ impl<'a> FromRuleNode<'a> for RuleModifierContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleModifierContext<'a> { +impl<'a> AsRuleNode<'a> for RuleModifierContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleModifierContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleModifierContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4429,6 +4270,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleModifierContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4460,15 +4302,21 @@ impl<'a> RuleModifierContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleModifierContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4478,7 +4326,7 @@ impl<'a> RuleModifierContext<'a> { } } -impl std::fmt::Display for RuleModifierContext<'_> { +impl std::fmt::Display for RuleModifierContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4487,9 +4335,10 @@ impl std::fmt::Display for RuleModifierContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleBlockContext<'a> { +pub struct RuleBlockContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleBlockContext<'a> { @@ -4499,7 +4348,20 @@ impl<'a> FromRuleNode<'a> for RuleBlockContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleBlockContext<'a> { +impl<'a> AsRuleNode<'a> for RuleBlockContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleBlockContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleBlockContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4512,6 +4374,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleBlockContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4543,15 +4406,21 @@ impl<'a> RuleBlockContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } - pub fn child_count(&self) -> usize { +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleBlockContext<'a, State> { + pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4559,23 +4428,15 @@ impl<'a> RuleBlockContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn rule_alt_list(&self, index: usize) -> RuleAltListContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(31).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 31).nth(index), - }.expect("missing rule child"); - RuleAltListContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_alt_list_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(31).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 31).collect(), - }; - nodes.into_iter().map(|node| RuleAltListContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn rule_alt_list(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 31) + .next() + .map(|node| RuleAltListContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("RuleBlockContext", "ruleAltList")) } } -impl std::fmt::Display for RuleBlockContext<'_> { +impl std::fmt::Display for RuleBlockContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4584,9 +4445,10 @@ impl std::fmt::Display for RuleBlockContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RuleAltListContext<'a> { +pub struct RuleAltListContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RuleAltListContext<'a> { @@ -4596,7 +4458,20 @@ impl<'a> FromRuleNode<'a> for RuleAltListContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RuleAltListContext<'a> { +impl<'a> AsRuleNode<'a> for RuleAltListContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RuleAltListContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RuleAltListContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4609,6 +4484,7 @@ impl<'a> __FromActiveRuleContext<'a> for RuleAltListContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4640,15 +4516,21 @@ impl<'a> RuleAltListContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RuleAltListContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4656,39 +4538,16 @@ impl<'a> RuleAltListContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn labeled_alt(&self, index: usize) -> LabeledAltContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(32).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 32).nth(index), - }.expect("missing rule child"); - LabeledAltContext::__from_child_node(node, &self.__invocation_states) - } - pub fn labeled_alt_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(32).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 32).collect(), - }; - nodes.into_iter().map(|node| LabeledAltContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn OR(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn OR_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn labeled_alt_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 32) + .map(move |node| LabeledAltContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn or_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 67).map(TerminalNode::new) } } -impl std::fmt::Display for RuleAltListContext<'_> { +impl std::fmt::Display for RuleAltListContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4697,9 +4556,10 @@ impl std::fmt::Display for RuleAltListContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LabeledAltContext<'a> { +pub struct LabeledAltContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LabeledAltContext<'a> { @@ -4709,7 +4569,20 @@ impl<'a> FromRuleNode<'a> for LabeledAltContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LabeledAltContext<'a> { +impl<'a> AsRuleNode<'a> for LabeledAltContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LabeledAltContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LabeledAltContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4722,6 +4595,7 @@ impl<'a> __FromActiveRuleContext<'a> for LabeledAltContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4753,15 +4627,21 @@ impl<'a> LabeledAltContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LabeledAltContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4769,53 +4649,25 @@ impl<'a> LabeledAltContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn alternative(&self, index: usize) -> AlternativeContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(45).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 45).nth(index), - }.expect("missing rule child"); - AlternativeContext::__from_child_node(node, &self.__invocation_states) - } - pub fn alternative_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(45).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 45).collect(), - }; - nodes.into_iter().map(|node| AlternativeContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn POUND(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(72).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 72).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn POUND_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(72).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 72).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn alternative(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 45) + .next() + .map(|node| AlternativeContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LabeledAltContext", "alternative")) + } + pub fn identifier(&self) -> Option> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn pound_token(&self) -> Option> { + __token_children(self.__node, 72) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for LabeledAltContext<'_> { +impl std::fmt::Display for LabeledAltContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4824,9 +4676,10 @@ impl std::fmt::Display for LabeledAltContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerRuleSpecContext<'a> { +pub struct LexerRuleSpecContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerRuleSpecContext<'a> { @@ -4836,7 +4689,20 @@ impl<'a> FromRuleNode<'a> for LexerRuleSpecContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerRuleSpecContext<'a> { +impl<'a> AsRuleNode<'a> for LexerRuleSpecContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerRuleSpecContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerRuleSpecContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -4849,6 +4715,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerRuleSpecContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -4880,15 +4747,21 @@ impl<'a> LexerRuleSpecContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerRuleSpecContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -4896,101 +4769,43 @@ impl<'a> LexerRuleSpecContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn options_spec(&self, index: usize) -> OptionsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).nth(index), - }.expect("missing rule child"); - OptionsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn options_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).collect(), - }; - nodes.into_iter().map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn lexer_rule_block(&self, index: usize) -> LexerRuleBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(34).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 34).nth(index), - }.expect("missing rule child"); - LexerRuleBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_rule_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(34).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 34).collect(), - }; - nodes.into_iter().map(|node| LexerRuleBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn TOKEN_REF(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(12).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 12).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn TOKEN_REF_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(12).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 12).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn FRAGMENT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(40).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 40).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn FRAGMENT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(40).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 40).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn COLON(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(53).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 53).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COLON_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(53).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 53).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn SEMI(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn SEMI_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn options_spec(&self) -> Option> { + __rule_children(self.__node, 4) + .next() + .map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_rule_block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 34) + .next() + .map(|node| LexerRuleBlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LexerRuleSpecContext", "lexerRuleBlock")) + } + pub fn token_ref_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 12) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LexerRuleSpecContext", "TOKEN_REF")) + } + pub fn fragment_token(&self) -> Option> { + __token_children(self.__node, 40) + .next() + .map(TerminalNode::new) + } + pub fn colon_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 53) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LexerRuleSpecContext", "COLON")) + } + pub fn semi_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 56) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LexerRuleSpecContext", "SEMI")) } } -impl std::fmt::Display for LexerRuleSpecContext<'_> { +impl std::fmt::Display for LexerRuleSpecContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -4999,9 +4814,10 @@ impl std::fmt::Display for LexerRuleSpecContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerRuleBlockContext<'a> { +pub struct LexerRuleBlockContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerRuleBlockContext<'a> { @@ -5011,7 +4827,20 @@ impl<'a> FromRuleNode<'a> for LexerRuleBlockContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerRuleBlockContext<'a> { +impl<'a> AsRuleNode<'a> for LexerRuleBlockContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerRuleBlockContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerRuleBlockContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5024,6 +4853,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerRuleBlockContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5055,15 +4885,21 @@ impl<'a> LexerRuleBlockContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerRuleBlockContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5071,23 +4907,15 @@ impl<'a> LexerRuleBlockContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_alt_list(&self, index: usize) -> LexerAltListContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(35).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 35).nth(index), - }.expect("missing rule child"); - LexerAltListContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_alt_list_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(35).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 35).collect(), - }; - nodes.into_iter().map(|node| LexerAltListContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn lexer_alt_list(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 35) + .next() + .map(|node| LexerAltListContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LexerRuleBlockContext", "lexerAltList")) } } -impl std::fmt::Display for LexerRuleBlockContext<'_> { +impl std::fmt::Display for LexerRuleBlockContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5096,9 +4924,10 @@ impl std::fmt::Display for LexerRuleBlockContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerAltListContext<'a> { +pub struct LexerAltListContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerAltListContext<'a> { @@ -5108,7 +4937,20 @@ impl<'a> FromRuleNode<'a> for LexerAltListContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerAltListContext<'a> { +impl<'a> AsRuleNode<'a> for LexerAltListContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerAltListContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerAltListContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5121,6 +4963,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerAltListContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5152,15 +4995,21 @@ impl<'a> LexerAltListContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerAltListContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5168,39 +5017,16 @@ impl<'a> LexerAltListContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_alt(&self, index: usize) -> LexerAltContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(36).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 36).nth(index), - }.expect("missing rule child"); - LexerAltContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_alt_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(36).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 36).collect(), - }; - nodes.into_iter().map(|node| LexerAltContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn OR(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn OR_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn lexer_alt_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 36) + .map(move |node| LexerAltContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn or_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 67).map(TerminalNode::new) } } -impl std::fmt::Display for LexerAltListContext<'_> { +impl std::fmt::Display for LexerAltListContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5209,9 +5035,10 @@ impl std::fmt::Display for LexerAltListContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerAltContext<'a> { +pub struct LexerAltContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerAltContext<'a> { @@ -5221,7 +5048,20 @@ impl<'a> FromRuleNode<'a> for LexerAltContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerAltContext<'a> { +impl<'a> AsRuleNode<'a> for LexerAltContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerAltContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerAltContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5234,6 +5074,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerAltContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5265,15 +5106,21 @@ impl<'a> LexerAltContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerAltContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5281,37 +5128,19 @@ impl<'a> LexerAltContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_elements(&self, index: usize) -> LexerElementsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(37).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 37).nth(index), - }.expect("missing rule child"); - LexerElementsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_elements_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(37).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 37).collect(), - }; - nodes.into_iter().map(|node| LexerElementsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn lexer_commands(&self, index: usize) -> LexerCommandsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(40).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 40).nth(index), - }.expect("missing rule child"); - LexerCommandsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_commands_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(40).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 40).collect(), - }; - nodes.into_iter().map(|node| LexerCommandsContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn lexer_elements(&self) -> Option> { + __rule_children(self.__node, 37) + .next() + .map(|node| LexerElementsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_commands(&self) -> Option> { + __rule_children(self.__node, 40) + .next() + .map(|node| LexerCommandsContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for LexerAltContext<'_> { +impl std::fmt::Display for LexerAltContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5320,9 +5149,10 @@ impl std::fmt::Display for LexerAltContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerElementsContext<'a> { +pub struct LexerElementsContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerElementsContext<'a> { @@ -5332,7 +5162,20 @@ impl<'a> FromRuleNode<'a> for LexerElementsContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerElementsContext<'a> { +impl<'a> AsRuleNode<'a> for LexerElementsContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerElementsContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerElementsContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5345,6 +5188,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerElementsContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5376,15 +5220,21 @@ impl<'a> LexerElementsContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerElementsContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5392,23 +5242,13 @@ impl<'a> LexerElementsContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_element(&self, index: usize) -> LexerElementContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(38).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 38).nth(index), - }.expect("missing rule child"); - LexerElementContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_element_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(38).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 38).collect(), - }; - nodes.into_iter().map(|node| LexerElementContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn lexer_element_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 38) + .map(move |node| LexerElementContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for LexerElementsContext<'_> { +impl std::fmt::Display for LexerElementsContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5417,9 +5257,10 @@ impl std::fmt::Display for LexerElementsContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerElementContext<'a> { +pub struct LexerElementContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerElementContext<'a> { @@ -5429,7 +5270,20 @@ impl<'a> FromRuleNode<'a> for LexerElementContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerElementContext<'a> { +impl<'a> AsRuleNode<'a> for LexerElementContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerElementContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerElementContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5442,6 +5296,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerElementContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5473,15 +5328,21 @@ impl<'a> LexerElementContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerElementContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5489,81 +5350,34 @@ impl<'a> LexerElementContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn lexer_block(&self, index: usize) -> LexerBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(39).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 39).nth(index), - }.expect("missing rule child"); - LexerBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(39).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 39).collect(), - }; - nodes.into_iter().map(|node| LexerBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn ebnf_suffix(&self, index: usize) -> EbnfSuffixContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(52).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 52).nth(index), - }.expect("missing rule child"); - EbnfSuffixContext::__from_child_node(node, &self.__invocation_states) - } - pub fn ebnf_suffix_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(52).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 52).collect(), - }; - nodes.into_iter().map(|node| EbnfSuffixContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn lexer_atom(&self, index: usize) -> LexerAtomContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(53).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 53).nth(index), - }.expect("missing rule child"); - LexerAtomContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_atom_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(53).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 53).collect(), - }; - nodes.into_iter().map(|node| LexerAtomContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn QUESTION(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 63).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn QUESTION_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Option> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_block(&self) -> Option> { + __rule_children(self.__node, 39) + .next() + .map(|node| LexerBlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn ebnf_suffix(&self) -> Option> { + __rule_children(self.__node, 52) + .next() + .map(|node| EbnfSuffixContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_atom(&self) -> Option> { + __rule_children(self.__node, 53) + .next() + .map(|node| LexerAtomContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn question_token(&self) -> Option> { + __token_children(self.__node, 63) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for LexerElementContext<'_> { +impl std::fmt::Display for LexerElementContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5572,9 +5386,10 @@ impl std::fmt::Display for LexerElementContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerBlockContext<'a> { +pub struct LexerBlockContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerBlockContext<'a> { @@ -5584,7 +5399,20 @@ impl<'a> FromRuleNode<'a> for LexerBlockContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerBlockContext<'a> { +impl<'a> AsRuleNode<'a> for LexerBlockContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerBlockContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerBlockContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5597,6 +5425,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerBlockContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5628,15 +5457,21 @@ impl<'a> LexerBlockContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerBlockContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5644,55 +5479,27 @@ impl<'a> LexerBlockContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_alt_list(&self, index: usize) -> LexerAltListContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(35).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 35).nth(index), - }.expect("missing rule child"); - LexerAltListContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_alt_list_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(35).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 35).collect(), - }; - nodes.into_iter().map(|node| LexerAltListContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn lexer_alt_list(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 35) + .next() + .map(|node| LexerAltListContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LexerBlockContext", "lexerAltList")) + } + pub fn lparen_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 57) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LexerBlockContext", "LPAREN")) + } + pub fn rparen_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 58) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LexerBlockContext", "RPAREN")) } } -impl std::fmt::Display for LexerBlockContext<'_> { +impl std::fmt::Display for LexerBlockContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5701,9 +5508,10 @@ impl std::fmt::Display for LexerBlockContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerCommandsContext<'a> { +pub struct LexerCommandsContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerCommandsContext<'a> { @@ -5713,7 +5521,20 @@ impl<'a> FromRuleNode<'a> for LexerCommandsContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerCommandsContext<'a> { +impl<'a> AsRuleNode<'a> for LexerCommandsContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerCommandsContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerCommandsContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5726,6 +5547,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerCommandsContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5757,15 +5579,21 @@ impl<'a> LexerCommandsContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerCommandsContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5773,55 +5601,22 @@ impl<'a> LexerCommandsContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_command(&self, index: usize) -> LexerCommandContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(41).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 41).nth(index), - }.expect("missing rule child"); - LexerCommandContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_command_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(41).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 41).collect(), - }; - nodes.into_iter().map(|node| LexerCommandContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn COMMA(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COMMA_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RARROW(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(60).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 60).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RARROW_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(60).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 60).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn lexer_command_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 41) + .map(move |node| LexerCommandContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn comma_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 55).map(TerminalNode::new) + } + pub fn rarrow_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 60) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("LexerCommandsContext", "RARROW")) } } -impl std::fmt::Display for LexerCommandsContext<'_> { +impl std::fmt::Display for LexerCommandsContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5830,9 +5625,10 @@ impl std::fmt::Display for LexerCommandsContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerCommandContext<'a> { +pub struct LexerCommandContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerCommandContext<'a> { @@ -5842,7 +5638,20 @@ impl<'a> FromRuleNode<'a> for LexerCommandContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerCommandContext<'a> { +impl<'a> AsRuleNode<'a> for LexerCommandContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerCommandContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerCommandContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5855,6 +5664,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerCommandContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -5886,15 +5696,21 @@ impl<'a> LexerCommandContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerCommandContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -5902,69 +5718,30 @@ impl<'a> LexerCommandContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn lexer_command_name(&self, index: usize) -> LexerCommandNameContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(42).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 42).nth(index), - }.expect("missing rule child"); - LexerCommandNameContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_command_name_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(42).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 42).collect(), - }; - nodes.into_iter().map(|node| LexerCommandNameContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn lexer_command_expr(&self, index: usize) -> LexerCommandExprContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(43).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 43).nth(index), - }.expect("missing rule child"); - LexerCommandExprContext::__from_child_node(node, &self.__invocation_states) - } - pub fn lexer_command_expr_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(43).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 43).collect(), - }; - nodes.into_iter().map(|node| LexerCommandExprContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn lexer_command_name(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 42) + .next() + .map(|node| LexerCommandNameContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LexerCommandContext", "lexerCommandName")) + } + pub fn lexer_command_expr(&self) -> Option> { + __rule_children(self.__node, 43) + .next() + .map(|node| LexerCommandExprContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lparen_token(&self) -> Option> { + __token_children(self.__node, 57) + .next() + .map(TerminalNode::new) + } + pub fn rparen_token(&self) -> Option> { + __token_children(self.__node, 58) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for LexerCommandContext<'_> { +impl std::fmt::Display for LexerCommandContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -5973,9 +5750,10 @@ impl std::fmt::Display for LexerCommandContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerCommandNameContext<'a> { +pub struct LexerCommandNameContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerCommandNameContext<'a> { @@ -5985,7 +5763,20 @@ impl<'a> FromRuleNode<'a> for LexerCommandNameContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerCommandNameContext<'a> { +impl<'a> AsRuleNode<'a> for LexerCommandNameContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerCommandNameContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerCommandNameContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -5998,6 +5789,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerCommandNameContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6029,15 +5821,21 @@ impl<'a> LexerCommandNameContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerCommandNameContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6045,39 +5843,19 @@ impl<'a> LexerCommandNameContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn MODE(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(52).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 52).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn MODE_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(52).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 52).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier(&self) -> Option> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn mode_token(&self) -> Option> { + __token_children(self.__node, 52) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for LexerCommandNameContext<'_> { +impl std::fmt::Display for LexerCommandNameContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6086,9 +5864,10 @@ impl std::fmt::Display for LexerCommandNameContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerCommandExprContext<'a> { +pub struct LexerCommandExprContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerCommandExprContext<'a> { @@ -6098,7 +5877,20 @@ impl<'a> FromRuleNode<'a> for LexerCommandExprContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerCommandExprContext<'a> { +impl<'a> AsRuleNode<'a> for LexerCommandExprContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerCommandExprContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerCommandExprContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6111,6 +5903,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerCommandExprContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6142,15 +5935,21 @@ impl<'a> LexerCommandExprContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerCommandExprContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6158,39 +5957,19 @@ impl<'a> LexerCommandExprContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn INT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn INT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier(&self) -> Option> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn int_token(&self) -> Option> { + __token_children(self.__node, 33) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for LexerCommandExprContext<'_> { +impl std::fmt::Display for LexerCommandExprContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6199,9 +5978,10 @@ impl std::fmt::Display for LexerCommandExprContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct AltListContext<'a> { +pub struct AltListContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for AltListContext<'a> { @@ -6211,7 +5991,20 @@ impl<'a> FromRuleNode<'a> for AltListContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for AltListContext<'a> { +impl<'a> AsRuleNode<'a> for AltListContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> AltListContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for AltListContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6224,6 +6017,7 @@ impl<'a> __FromActiveRuleContext<'a> for AltListContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6255,15 +6049,21 @@ impl<'a> AltListContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> AltListContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6271,39 +6071,16 @@ impl<'a> AltListContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn alternative(&self, index: usize) -> AlternativeContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(45).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 45).nth(index), - }.expect("missing rule child"); - AlternativeContext::__from_child_node(node, &self.__invocation_states) - } - pub fn alternative_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(45).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 45).collect(), - }; - nodes.into_iter().map(|node| AlternativeContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn OR(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn OR_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn alternative_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 45) + .map(move |node| AlternativeContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn or_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 67).map(TerminalNode::new) } } -impl std::fmt::Display for AltListContext<'_> { +impl std::fmt::Display for AltListContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6312,9 +6089,10 @@ impl std::fmt::Display for AltListContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct AlternativeContext<'a> { +pub struct AlternativeContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for AlternativeContext<'a> { @@ -6324,7 +6102,20 @@ impl<'a> FromRuleNode<'a> for AlternativeContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for AlternativeContext<'a> { +impl<'a> AsRuleNode<'a> for AlternativeContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> AlternativeContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for AlternativeContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6337,6 +6128,7 @@ impl<'a> __FromActiveRuleContext<'a> for AlternativeContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6368,15 +6160,21 @@ impl<'a> AlternativeContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> AlternativeContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6384,37 +6182,18 @@ impl<'a> AlternativeContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn element(&self, index: usize) -> ElementContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(46).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 46).nth(index), - }.expect("missing rule child"); - ElementContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(46).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 46).collect(), - }; - nodes.into_iter().map(|node| ElementContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn element_options(&self, index: usize) -> ElementOptionsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).nth(index), - }.expect("missing rule child"); - ElementOptionsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_options_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn element_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 46) + .map(move |node| ElementContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn element_options(&self) -> Option> { + __rule_children(self.__node, 63) + .next() + .map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for AlternativeContext<'_> { +impl std::fmt::Display for AlternativeContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6423,9 +6202,10 @@ impl std::fmt::Display for AlternativeContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ElementContext<'a> { +pub struct ElementContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ElementContext<'a> { @@ -6435,7 +6215,20 @@ impl<'a> FromRuleNode<'a> for ElementContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ElementContext<'a> { +impl<'a> AsRuleNode<'a> for ElementContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ElementContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ElementContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6448,6 +6241,7 @@ impl<'a> __FromActiveRuleContext<'a> for ElementContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6479,15 +6273,21 @@ impl<'a> ElementContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ElementContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6495,109 +6295,44 @@ impl<'a> ElementContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn predicate_options(&self, index: usize) -> PredicateOptionsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(47).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 47).nth(index), - }.expect("missing rule child"); - PredicateOptionsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn predicate_options_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(47).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 47).collect(), - }; - nodes.into_iter().map(|node| PredicateOptionsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn labeled_element(&self, index: usize) -> LabeledElementContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(49).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 49).nth(index), - }.expect("missing rule child"); - LabeledElementContext::__from_child_node(node, &self.__invocation_states) - } - pub fn labeled_element_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(49).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 49).collect(), - }; - nodes.into_iter().map(|node| LabeledElementContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn ebnf(&self, index: usize) -> EbnfContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(50).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 50).nth(index), - }.expect("missing rule child"); - EbnfContext::__from_child_node(node, &self.__invocation_states) - } - pub fn ebnf_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(50).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 50).collect(), - }; - nodes.into_iter().map(|node| EbnfContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn ebnf_suffix(&self, index: usize) -> EbnfSuffixContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(52).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 52).nth(index), - }.expect("missing rule child"); - EbnfSuffixContext::__from_child_node(node, &self.__invocation_states) - } - pub fn ebnf_suffix_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(52).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 52).collect(), - }; - nodes.into_iter().map(|node| EbnfSuffixContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn atom(&self, index: usize) -> AtomContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(54).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 54).nth(index), - }.expect("missing rule child"); - AtomContext::__from_child_node(node, &self.__invocation_states) - } - pub fn atom_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(54).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 54).collect(), - }; - nodes.into_iter().map(|node| AtomContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn QUESTION(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 63).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn QUESTION_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Option> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) } -} - -impl std::fmt::Display for ElementContext<'_> { + pub fn predicate_options(&self) -> Option> { + __rule_children(self.__node, 47) + .next() + .map(|node| PredicateOptionsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn labeled_element(&self) -> Option> { + __rule_children(self.__node, 49) + .next() + .map(|node| LabeledElementContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn ebnf(&self) -> Option> { + __rule_children(self.__node, 50) + .next() + .map(|node| EbnfContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn ebnf_suffix(&self) -> Option> { + __rule_children(self.__node, 52) + .next() + .map(|node| EbnfSuffixContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn atom(&self) -> Option> { + __rule_children(self.__node, 54) + .next() + .map(|node| AtomContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn question_token(&self) -> Option> { + __token_children(self.__node, 63) + .next() + .map(TerminalNode::new) + } +} + +impl std::fmt::Display for ElementContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6606,9 +6341,10 @@ impl std::fmt::Display for ElementContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct PredicateOptionsContext<'a> { +pub struct PredicateOptionsContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for PredicateOptionsContext<'a> { @@ -6618,7 +6354,20 @@ impl<'a> FromRuleNode<'a> for PredicateOptionsContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for PredicateOptionsContext<'a> { +impl<'a> AsRuleNode<'a> for PredicateOptionsContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> PredicateOptionsContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for PredicateOptionsContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6631,6 +6380,7 @@ impl<'a> __FromActiveRuleContext<'a> for PredicateOptionsContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6662,15 +6412,21 @@ impl<'a> PredicateOptionsContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> PredicateOptionsContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6678,71 +6434,28 @@ impl<'a> PredicateOptionsContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn predicate_option(&self, index: usize) -> PredicateOptionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(48).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 48).nth(index), - }.expect("missing rule child"); - PredicateOptionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn predicate_option_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(48).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 48).collect(), - }; - nodes.into_iter().map(|node| PredicateOptionContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn COMMA(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COMMA_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn LT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(61).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 61).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(61).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 61).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn GT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(62).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 62).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn GT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(62).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 62).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn predicate_option_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 48) + .map(move |node| PredicateOptionContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn comma_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 55).map(TerminalNode::new) + } + pub fn lt_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 61) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("PredicateOptionsContext", "LT")) + } + pub fn gt_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 62) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("PredicateOptionsContext", "GT")) } } -impl std::fmt::Display for PredicateOptionsContext<'_> { +impl std::fmt::Display for PredicateOptionsContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6751,9 +6464,10 @@ impl std::fmt::Display for PredicateOptionsContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct PredicateOptionContext<'a> { +pub struct PredicateOptionContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for PredicateOptionContext<'a> { @@ -6763,7 +6477,20 @@ impl<'a> FromRuleNode<'a> for PredicateOptionContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for PredicateOptionContext<'a> { +impl<'a> AsRuleNode<'a> for PredicateOptionContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> PredicateOptionContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for PredicateOptionContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6776,6 +6503,7 @@ impl<'a> __FromActiveRuleContext<'a> for PredicateOptionContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6807,15 +6535,21 @@ impl<'a> PredicateOptionContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> PredicateOptionContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6823,99 +6557,39 @@ impl<'a> PredicateOptionContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn action_block(&self, index: usize) -> ActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).nth(index), - }.expect("missing rule child"); - ActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(14).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 14).collect(), - }; - nodes.into_iter().map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn element_option(&self, index: usize) -> ElementOptionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(64).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 64).nth(index), - }.expect("missing rule child"); - ElementOptionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_option_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(64).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 64).collect(), - }; - nodes.into_iter().map(|node| ElementOptionContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn ASSIGN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn ASSIGN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn INT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn INT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn action_block(&self) -> Option> { + __rule_children(self.__node, 14) + .next() + .map(|node| ActionBlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn element_option(&self) -> Option> { + __rule_children(self.__node, 64) + .next() + .map(|node| ElementOptionContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn identifier(&self) -> Option> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn assign_token(&self) -> Option> { + __token_children(self.__node, 7) + .next() + .map(TerminalNode::new) + } + pub fn string_literal_token(&self) -> Option> { + __token_children(self.__node, 11) + .next() + .map(TerminalNode::new) + } + pub fn int_token(&self) -> Option> { + __token_children(self.__node, 33) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for PredicateOptionContext<'_> { +impl std::fmt::Display for PredicateOptionContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -6924,9 +6598,10 @@ impl std::fmt::Display for PredicateOptionContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LabeledElementContext<'a> { +pub struct LabeledElementContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LabeledElementContext<'a> { @@ -6936,7 +6611,20 @@ impl<'a> FromRuleNode<'a> for LabeledElementContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LabeledElementContext<'a> { +impl<'a> AsRuleNode<'a> for LabeledElementContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LabeledElementContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LabeledElementContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -6949,6 +6637,7 @@ impl<'a> __FromActiveRuleContext<'a> for LabeledElementContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -6980,15 +6669,21 @@ impl<'a> LabeledElementContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LabeledElementContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -6996,51 +6691,25 @@ impl<'a> LabeledElementContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn atom(&self, index: usize) -> AtomContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(54).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 54).nth(index), - }.expect("missing rule child"); - AtomContext::__from_child_node(node, &self.__invocation_states) - } - pub fn atom_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(54).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 54).collect(), - }; - nodes.into_iter().map(|node| AtomContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn block(&self, index: usize) -> BlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(59).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 59).nth(index), - }.expect("missing rule child"); - BlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(59).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 59).collect(), - }; - nodes.into_iter().map(|node| BlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn atom(&self) -> Option> { + __rule_children(self.__node, 54) + .next() + .map(|node| AtomContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn block(&self) -> Option> { + __rule_children(self.__node, 59) + .next() + .map(|node| BlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn identifier(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("LabeledElementContext", "identifier")) } } -impl std::fmt::Display for LabeledElementContext<'_> { +impl std::fmt::Display for LabeledElementContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7049,9 +6718,10 @@ impl std::fmt::Display for LabeledElementContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct EbnfContext<'a> { +pub struct EbnfContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for EbnfContext<'a> { @@ -7061,7 +6731,20 @@ impl<'a> FromRuleNode<'a> for EbnfContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for EbnfContext<'a> { +impl<'a> AsRuleNode<'a> for EbnfContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> EbnfContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for EbnfContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7074,6 +6757,7 @@ impl<'a> __FromActiveRuleContext<'a> for EbnfContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7105,15 +6789,21 @@ impl<'a> EbnfContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> EbnfContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7121,37 +6811,20 @@ impl<'a> EbnfContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn block_suffix(&self, index: usize) -> BlockSuffixContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(51).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 51).nth(index), - }.expect("missing rule child"); - BlockSuffixContext::__from_child_node(node, &self.__invocation_states) - } - pub fn block_suffix_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(51).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 51).collect(), - }; - nodes.into_iter().map(|node| BlockSuffixContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn block(&self, index: usize) -> BlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(59).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 59).nth(index), - }.expect("missing rule child"); - BlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(59).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 59).collect(), - }; - nodes.into_iter().map(|node| BlockContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn block_suffix(&self) -> Option> { + __rule_children(self.__node, 51) + .next() + .map(|node| BlockSuffixContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn block(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 59) + .next() + .map(|node| BlockContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("EbnfContext", "block")) } } -impl std::fmt::Display for EbnfContext<'_> { +impl std::fmt::Display for EbnfContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7160,9 +6833,10 @@ impl std::fmt::Display for EbnfContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct BlockSuffixContext<'a> { +pub struct BlockSuffixContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for BlockSuffixContext<'a> { @@ -7172,7 +6846,20 @@ impl<'a> FromRuleNode<'a> for BlockSuffixContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for BlockSuffixContext<'a> { +impl<'a> AsRuleNode<'a> for BlockSuffixContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> BlockSuffixContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for BlockSuffixContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7185,6 +6872,7 @@ impl<'a> __FromActiveRuleContext<'a> for BlockSuffixContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7216,15 +6904,21 @@ impl<'a> BlockSuffixContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> BlockSuffixContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7232,23 +6926,15 @@ impl<'a> BlockSuffixContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn ebnf_suffix(&self, index: usize) -> EbnfSuffixContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(52).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 52).nth(index), - }.expect("missing rule child"); - EbnfSuffixContext::__from_child_node(node, &self.__invocation_states) - } - pub fn ebnf_suffix_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(52).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 52).collect(), - }; - nodes.into_iter().map(|node| EbnfSuffixContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn ebnf_suffix(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 52) + .next() + .map(|node| EbnfSuffixContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("BlockSuffixContext", "ebnfSuffix")) } } -impl std::fmt::Display for BlockSuffixContext<'_> { +impl std::fmt::Display for BlockSuffixContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7257,9 +6943,10 @@ impl std::fmt::Display for BlockSuffixContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct EbnfSuffixContext<'a> { +pub struct EbnfSuffixContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for EbnfSuffixContext<'a> { @@ -7269,7 +6956,20 @@ impl<'a> FromRuleNode<'a> for EbnfSuffixContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for EbnfSuffixContext<'a> { +impl<'a> AsRuleNode<'a> for EbnfSuffixContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> EbnfSuffixContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for EbnfSuffixContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7282,6 +6982,7 @@ impl<'a> __FromActiveRuleContext<'a> for EbnfSuffixContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7313,15 +7014,21 @@ impl<'a> EbnfSuffixContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> EbnfSuffixContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7329,57 +7036,22 @@ impl<'a> EbnfSuffixContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - #[allow(non_snake_case)] - pub fn QUESTION(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 63).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn QUESTION_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn STAR(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(64).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 64).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STAR_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(64).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 64).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn PLUS(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(66).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 66).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn PLUS_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(66).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 66).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn question_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 63).map(TerminalNode::new) + } + pub fn star_token(&self) -> Option> { + __token_children(self.__node, 64) + .next() + .map(TerminalNode::new) + } + pub fn plus_token(&self) -> Option> { + __token_children(self.__node, 66) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for EbnfSuffixContext<'_> { +impl std::fmt::Display for EbnfSuffixContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7388,9 +7060,10 @@ impl std::fmt::Display for EbnfSuffixContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct LexerAtomContext<'a> { +pub struct LexerAtomContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for LexerAtomContext<'a> { @@ -7400,7 +7073,20 @@ impl<'a> FromRuleNode<'a> for LexerAtomContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for LexerAtomContext<'a> { +impl<'a> AsRuleNode<'a> for LexerAtomContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> LexerAtomContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for LexerAtomContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7413,6 +7099,7 @@ impl<'a> __FromActiveRuleContext<'a> for LexerAtomContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7444,15 +7131,21 @@ impl<'a> LexerAtomContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> LexerAtomContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7460,97 +7153,39 @@ impl<'a> LexerAtomContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn wildcard(&self, index: usize) -> WildcardContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 55).nth(index), - }.expect("missing rule child"); - WildcardContext::__from_child_node(node, &self.__invocation_states) - } - pub fn wildcard_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(|node| WildcardContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn not_set(&self, index: usize) -> NotSetContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 56).nth(index), - }.expect("missing rule child"); - NotSetContext::__from_child_node(node, &self.__invocation_states) - } - pub fn not_set_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(|node| NotSetContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn character_range(&self, index: usize) -> CharacterRangeContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(61).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 61).nth(index), - }.expect("missing rule child"); - CharacterRangeContext::__from_child_node(node, &self.__invocation_states) - } - pub fn character_range_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(61).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 61).collect(), - }; - nodes.into_iter().map(|node| CharacterRangeContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn terminal_def(&self, index: usize) -> TerminalDefContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(62).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 62).nth(index), - }.expect("missing rule child"); - TerminalDefContext::__from_child_node(node, &self.__invocation_states) - } - pub fn terminal_def_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(62).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 62).collect(), - }; - nodes.into_iter().map(|node| TerminalDefContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LEXER_CHAR_SET(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(8).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 8).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LEXER_CHAR_SET_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(8).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 8).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RULE_REF(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(9).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 9).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RULE_REF_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(9).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 9).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn wildcard(&self) -> Option> { + __rule_children(self.__node, 55) + .next() + .map(|node| WildcardContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn not_set(&self) -> Option> { + __rule_children(self.__node, 56) + .next() + .map(|node| NotSetContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn character_range(&self) -> Option> { + __rule_children(self.__node, 61) + .next() + .map(|node| CharacterRangeContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn terminal_def(&self) -> Option> { + __rule_children(self.__node, 62) + .next() + .map(|node| TerminalDefContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_char_set_token(&self) -> Option> { + __token_children(self.__node, 8) + .next() + .map(TerminalNode::new) + } + pub fn rule_ref_token(&self) -> Option> { + __token_children(self.__node, 9) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for LexerAtomContext<'_> { +impl std::fmt::Display for LexerAtomContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7559,9 +7194,10 @@ impl std::fmt::Display for LexerAtomContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct AtomContext<'a> { +pub struct AtomContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for AtomContext<'a> { @@ -7571,7 +7207,20 @@ impl<'a> FromRuleNode<'a> for AtomContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for AtomContext<'a> { +impl<'a> AsRuleNode<'a> for AtomContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> AtomContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for AtomContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7584,6 +7233,7 @@ impl<'a> __FromActiveRuleContext<'a> for AtomContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7615,15 +7265,21 @@ impl<'a> AtomContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> AtomContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7631,65 +7287,29 @@ impl<'a> AtomContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn wildcard(&self, index: usize) -> WildcardContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 55).nth(index), - }.expect("missing rule child"); - WildcardContext::__from_child_node(node, &self.__invocation_states) - } - pub fn wildcard_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(|node| WildcardContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn not_set(&self, index: usize) -> NotSetContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(56).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 56).nth(index), - }.expect("missing rule child"); - NotSetContext::__from_child_node(node, &self.__invocation_states) - } - pub fn not_set_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(56).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 56).collect(), - }; - nodes.into_iter().map(|node| NotSetContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn ruleref(&self, index: usize) -> RulerefContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(60).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 60).nth(index), - }.expect("missing rule child"); - RulerefContext::__from_child_node(node, &self.__invocation_states) - } - pub fn ruleref_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(60).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 60).collect(), - }; - nodes.into_iter().map(|node| RulerefContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn terminal_def(&self, index: usize) -> TerminalDefContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(62).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 62).nth(index), - }.expect("missing rule child"); - TerminalDefContext::__from_child_node(node, &self.__invocation_states) - } - pub fn terminal_def_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(62).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 62).collect(), - }; - nodes.into_iter().map(|node| TerminalDefContext::__from_child_node(node, &self.__invocation_states)).collect() + pub fn wildcard(&self) -> Option> { + __rule_children(self.__node, 55) + .next() + .map(|node| WildcardContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn not_set(&self) -> Option> { + __rule_children(self.__node, 56) + .next() + .map(|node| NotSetContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn ruleref(&self) -> Option> { + __rule_children(self.__node, 60) + .next() + .map(|node| RulerefContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn terminal_def(&self) -> Option> { + __rule_children(self.__node, 62) + .next() + .map(|node| TerminalDefContext::__from_child_node(node, &self.__invocation_states)) } } -impl std::fmt::Display for AtomContext<'_> { +impl std::fmt::Display for AtomContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7698,9 +7318,10 @@ impl std::fmt::Display for AtomContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct WildcardContext<'a> { +pub struct WildcardContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for WildcardContext<'a> { @@ -7710,7 +7331,20 @@ impl<'a> FromRuleNode<'a> for WildcardContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for WildcardContext<'a> { +impl<'a> AsRuleNode<'a> for WildcardContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> WildcardContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for WildcardContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7723,6 +7357,7 @@ impl<'a> __FromActiveRuleContext<'a> for WildcardContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7754,15 +7389,21 @@ impl<'a> WildcardContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> WildcardContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7770,39 +7411,20 @@ impl<'a> WildcardContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn element_options(&self, index: usize) -> ElementOptionsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).nth(index), - }.expect("missing rule child"); - ElementOptionsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_options_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn DOT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(70).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 70).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn DOT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(70).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 70).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn element_options(&self) -> Option> { + __rule_children(self.__node, 63) + .next() + .map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn dot_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 70) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("WildcardContext", "DOT")) } } -impl std::fmt::Display for WildcardContext<'_> { +impl std::fmt::Display for WildcardContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7811,9 +7433,10 @@ impl std::fmt::Display for WildcardContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct NotSetContext<'a> { +pub struct NotSetContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for NotSetContext<'a> { @@ -7823,7 +7446,20 @@ impl<'a> FromRuleNode<'a> for NotSetContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for NotSetContext<'a> { +impl<'a> AsRuleNode<'a> for NotSetContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> NotSetContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for NotSetContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7836,6 +7472,7 @@ impl<'a> __FromActiveRuleContext<'a> for NotSetContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7867,15 +7504,21 @@ impl<'a> NotSetContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> NotSetContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -7883,53 +7526,25 @@ impl<'a> NotSetContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn block_set(&self, index: usize) -> BlockSetContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(57).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 57).nth(index), - }.expect("missing rule child"); - BlockSetContext::__from_child_node(node, &self.__invocation_states) - } - pub fn block_set_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(57).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 57).collect(), - }; - nodes.into_iter().map(|node| BlockSetContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn set_element(&self, index: usize) -> SetElementContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(58).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 58).nth(index), - }.expect("missing rule child"); - SetElementContext::__from_child_node(node, &self.__invocation_states) - } - pub fn set_element_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(58).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 58).collect(), - }; - nodes.into_iter().map(|node| SetElementContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn NOT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(73).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 73).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn NOT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(73).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 73).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn block_set(&self) -> Option> { + __rule_children(self.__node, 57) + .next() + .map(|node| BlockSetContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn set_element(&self) -> Option> { + __rule_children(self.__node, 58) + .next() + .map(|node| SetElementContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn not_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 73) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("NotSetContext", "NOT")) } } -impl std::fmt::Display for NotSetContext<'_> { +impl std::fmt::Display for NotSetContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -7938,9 +7553,10 @@ impl std::fmt::Display for NotSetContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct BlockSetContext<'a> { +pub struct BlockSetContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for BlockSetContext<'a> { @@ -7950,7 +7566,20 @@ impl<'a> FromRuleNode<'a> for BlockSetContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for BlockSetContext<'a> { +impl<'a> AsRuleNode<'a> for BlockSetContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> BlockSetContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for BlockSetContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -7963,6 +7592,7 @@ impl<'a> __FromActiveRuleContext<'a> for BlockSetContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -7994,15 +7624,21 @@ impl<'a> BlockSetContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> BlockSetContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8010,71 +7646,28 @@ impl<'a> BlockSetContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn set_element(&self, index: usize) -> SetElementContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(58).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 58).nth(index), - }.expect("missing rule child"); - SetElementContext::__from_child_node(node, &self.__invocation_states) - } - pub fn set_element_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(58).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 58).collect(), - }; - nodes.into_iter().map(|node| SetElementContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn OR(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn OR_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(67).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 67).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn set_element_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 58) + .map(move |node| SetElementContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lparen_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 57) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("BlockSetContext", "LPAREN")) + } + pub fn rparen_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 58) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("BlockSetContext", "RPAREN")) + } + pub fn or_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 67).map(TerminalNode::new) } } -impl std::fmt::Display for BlockSetContext<'_> { +impl std::fmt::Display for BlockSetContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8083,9 +7676,10 @@ impl std::fmt::Display for BlockSetContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct SetElementContext<'a> { +pub struct SetElementContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for SetElementContext<'a> { @@ -8095,7 +7689,20 @@ impl<'a> FromRuleNode<'a> for SetElementContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for SetElementContext<'a> { +impl<'a> AsRuleNode<'a> for SetElementContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> SetElementContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for SetElementContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -8108,6 +7715,7 @@ impl<'a> __FromActiveRuleContext<'a> for SetElementContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8139,15 +7747,21 @@ impl<'a> SetElementContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> SetElementContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8155,85 +7769,34 @@ impl<'a> SetElementContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn character_range(&self, index: usize) -> CharacterRangeContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(61).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 61).nth(index), - }.expect("missing rule child"); - CharacterRangeContext::__from_child_node(node, &self.__invocation_states) - } - pub fn character_range_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(61).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 61).collect(), - }; - nodes.into_iter().map(|node| CharacterRangeContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn element_options(&self, index: usize) -> ElementOptionsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).nth(index), - }.expect("missing rule child"); - ElementOptionsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_options_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn LEXER_CHAR_SET(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(8).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 8).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LEXER_CHAR_SET_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(8).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 8).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn TOKEN_REF(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(12).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 12).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn TOKEN_REF_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(12).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 12).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn character_range(&self) -> Option> { + __rule_children(self.__node, 61) + .next() + .map(|node| CharacterRangeContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn element_options(&self) -> Option> { + __rule_children(self.__node, 63) + .next() + .map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn lexer_char_set_token(&self) -> Option> { + __token_children(self.__node, 8) + .next() + .map(TerminalNode::new) + } + pub fn string_literal_token(&self) -> Option> { + __token_children(self.__node, 11) + .next() + .map(TerminalNode::new) + } + pub fn token_ref_token(&self) -> Option> { + __token_children(self.__node, 12) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for SetElementContext<'_> { +impl std::fmt::Display for SetElementContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8242,9 +7805,10 @@ impl std::fmt::Display for SetElementContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct BlockContext<'a> { +pub struct BlockContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for BlockContext<'a> { @@ -8254,7 +7818,20 @@ impl<'a> FromRuleNode<'a> for BlockContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for BlockContext<'a> { +impl<'a> AsRuleNode<'a> for BlockContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> BlockContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for BlockContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -8267,6 +7844,7 @@ impl<'a> __FromActiveRuleContext<'a> for BlockContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8298,15 +7876,21 @@ impl<'a> BlockContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> BlockContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8314,99 +7898,41 @@ impl<'a> BlockContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn options_spec(&self, index: usize) -> OptionsSpecContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).nth(index), - }.expect("missing rule child"); - OptionsSpecContext::__from_child_node(node, &self.__invocation_states) - } - pub fn options_spec_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(4).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 4).collect(), - }; - nodes.into_iter().map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn rule_action(&self, index: usize) -> RuleActionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(27).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 27).nth(index), - }.expect("missing rule child"); - RuleActionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn rule_action_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(27).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 27).collect(), - }; - nodes.into_iter().map(|node| RuleActionContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn alt_list(&self, index: usize) -> AltListContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(44).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 44).nth(index), - }.expect("missing rule child"); - AltListContext::__from_child_node(node, &self.__invocation_states) - } - pub fn alt_list_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(44).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 44).collect(), - }; - nodes.into_iter().map(|node| AltListContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn COLON(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(53).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 53).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COLON_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(53).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 53).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn LPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(57).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 57).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RPAREN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RPAREN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(58).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 58).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn options_spec(&self) -> Option> { + __rule_children(self.__node, 4) + .next() + .map(|node| OptionsSpecContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rule_action_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 27) + .map(move |node| RuleActionContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn alt_list(&self) -> Result, MissingChildError> { + __rule_children(self.__node, 44) + .next() + .map(|node| AltListContext::__from_child_node(node, &self.__invocation_states)) + .ok_or_else(|| MissingChildError::new("BlockContext", "altList")) + } + pub fn colon_token(&self) -> Option> { + __token_children(self.__node, 53) + .next() + .map(TerminalNode::new) + } + pub fn lparen_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 57) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("BlockContext", "LPAREN")) + } + pub fn rparen_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 58) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("BlockContext", "RPAREN")) } } -impl std::fmt::Display for BlockContext<'_> { +impl std::fmt::Display for BlockContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8415,9 +7941,10 @@ impl std::fmt::Display for BlockContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct RulerefContext<'a> { +pub struct RulerefContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for RulerefContext<'a> { @@ -8427,7 +7954,20 @@ impl<'a> FromRuleNode<'a> for RulerefContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for RulerefContext<'a> { +impl<'a> AsRuleNode<'a> for RulerefContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> RulerefContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for RulerefContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -8440,6 +7980,7 @@ impl<'a> __FromActiveRuleContext<'a> for RulerefContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8471,15 +8012,21 @@ impl<'a> RulerefContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> RulerefContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8487,53 +8034,25 @@ impl<'a> RulerefContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn arg_action_block(&self, index: usize) -> ArgActionBlockContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).nth(index), - }.expect("missing rule child"); - ArgActionBlockContext::__from_child_node(node, &self.__invocation_states) - } - pub fn arg_action_block_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(15).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 15).collect(), - }; - nodes.into_iter().map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn element_options(&self, index: usize) -> ElementOptionsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).nth(index), - }.expect("missing rule child"); - ElementOptionsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_options_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn RULE_REF(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(9).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 9).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RULE_REF_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(9).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 9).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn arg_action_block(&self) -> Option> { + __rule_children(self.__node, 15) + .next() + .map(|node| ArgActionBlockContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn element_options(&self) -> Option> { + __rule_children(self.__node, 63) + .next() + .map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn rule_ref_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 9) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("RulerefContext", "RULE_REF")) } } -impl std::fmt::Display for RulerefContext<'_> { +impl std::fmt::Display for RulerefContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8542,9 +8061,10 @@ impl std::fmt::Display for RulerefContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct CharacterRangeContext<'a> { +pub struct CharacterRangeContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for CharacterRangeContext<'a> { @@ -8554,11 +8074,24 @@ impl<'a> FromRuleNode<'a> for CharacterRangeContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for CharacterRangeContext<'a> { - fn __from_active( - context: &'a antlr4_runtime::ParserRuleContext, - invocation_states: Vec, - storage: &'a antlr4_runtime::ParseTreeStorage, +impl<'a> AsRuleNode<'a> for CharacterRangeContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> CharacterRangeContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for CharacterRangeContext<'a, __ActiveParserContext> { + fn __from_active( + context: &'a antlr4_runtime::ParserRuleContext, + invocation_states: Vec, + storage: &'a antlr4_runtime::ParseTreeStorage, tokens: &'a antlr4_runtime::TokenStore, ) -> Option { if context.rule_index() != 61 { return None; } @@ -8567,6 +8100,7 @@ impl<'a> __FromActiveRuleContext<'a> for CharacterRangeContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8598,15 +8132,21 @@ impl<'a> CharacterRangeContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> CharacterRangeContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8614,41 +8154,18 @@ impl<'a> CharacterRangeContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - #[allow(non_snake_case)] - pub fn STRING_LITERAL(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn RANGE(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(69).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 69).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn RANGE_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(69).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 69).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn string_literal_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 11).map(TerminalNode::new) + } + pub fn range_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 69) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("CharacterRangeContext", "RANGE")) } } -impl std::fmt::Display for CharacterRangeContext<'_> { +impl std::fmt::Display for CharacterRangeContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8657,9 +8174,10 @@ impl std::fmt::Display for CharacterRangeContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct TerminalDefContext<'a> { +pub struct TerminalDefContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for TerminalDefContext<'a> { @@ -8669,7 +8187,20 @@ impl<'a> FromRuleNode<'a> for TerminalDefContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for TerminalDefContext<'a> { +impl<'a> AsRuleNode<'a> for TerminalDefContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> TerminalDefContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for TerminalDefContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -8682,6 +8213,7 @@ impl<'a> __FromActiveRuleContext<'a> for TerminalDefContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8713,15 +8245,21 @@ impl<'a> TerminalDefContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> TerminalDefContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8729,55 +8267,24 @@ impl<'a> TerminalDefContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn element_options(&self, index: usize) -> ElementOptionsContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).nth(index), - }.expect("missing rule child"); - ElementOptionsContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_options_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(63).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 63).collect(), - }; - nodes.into_iter().map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn TOKEN_REF(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(12).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 12).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn TOKEN_REF_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(12).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 12).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn element_options(&self) -> Option> { + __rule_children(self.__node, 63) + .next() + .map(|node| ElementOptionsContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn string_literal_token(&self) -> Option> { + __token_children(self.__node, 11) + .next() + .map(TerminalNode::new) + } + pub fn token_ref_token(&self) -> Option> { + __token_children(self.__node, 12) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for TerminalDefContext<'_> { +impl std::fmt::Display for TerminalDefContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8786,9 +8293,10 @@ impl std::fmt::Display for TerminalDefContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ElementOptionsContext<'a> { +pub struct ElementOptionsContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ElementOptionsContext<'a> { @@ -8798,7 +8306,20 @@ impl<'a> FromRuleNode<'a> for ElementOptionsContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ElementOptionsContext<'a> { +impl<'a> AsRuleNode<'a> for ElementOptionsContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ElementOptionsContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ElementOptionsContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -8811,6 +8332,7 @@ impl<'a> __FromActiveRuleContext<'a> for ElementOptionsContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8842,15 +8364,21 @@ impl<'a> ElementOptionsContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ElementOptionsContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -8858,71 +8386,28 @@ impl<'a> ElementOptionsContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn element_option(&self, index: usize) -> ElementOptionContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(64).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 64).nth(index), - }.expect("missing rule child"); - ElementOptionContext::__from_child_node(node, &self.__invocation_states) - } - pub fn element_option_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(64).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 64).collect(), - }; - nodes.into_iter().map(|node| ElementOptionContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn COMMA(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn COMMA_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(55).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 55).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn LT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(61).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 61).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn LT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(61).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 61).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn GT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(62).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 62).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn GT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(62).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 62).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn element_option_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 64) + .map(move |node| ElementOptionContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn comma_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 55).map(TerminalNode::new) + } + pub fn lt_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 61) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ElementOptionsContext", "LT")) + } + pub fn gt_token(&self) -> Result, MissingChildError> { + __token_children(self.__node, 62) + .next() + .map(TerminalNode::new) + .ok_or_else(|| MissingChildError::new("ElementOptionsContext", "GT")) } } -impl std::fmt::Display for ElementOptionsContext<'_> { +impl std::fmt::Display for ElementOptionsContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -8931,9 +8416,10 @@ impl std::fmt::Display for ElementOptionsContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct ElementOptionContext<'a> { +pub struct ElementOptionContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for ElementOptionContext<'a> { @@ -8943,7 +8429,20 @@ impl<'a> FromRuleNode<'a> for ElementOptionContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for ElementOptionContext<'a> { +impl<'a> AsRuleNode<'a> for ElementOptionContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> ElementOptionContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for ElementOptionContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -8956,6 +8455,7 @@ impl<'a> __FromActiveRuleContext<'a> for ElementOptionContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -8987,15 +8487,21 @@ impl<'a> ElementOptionContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> ElementOptionContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -9003,85 +8509,34 @@ impl<'a> ElementOptionContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - pub fn qualified_identifier(&self, index: usize) -> QualifiedIdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(66).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 66).nth(index), - }.expect("missing rule child"); - QualifiedIdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn qualified_identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(66).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 66).collect(), - }; - nodes.into_iter().map(|node| QualifiedIdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn ASSIGN(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn ASSIGN_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(7).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 7).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn STRING_LITERAL_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(11).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 11).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() - } - #[allow(non_snake_case)] - pub fn INT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn INT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(33).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 33).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier(&self) -> Option> { + __rule_children(self.__node, 65) + .next() + .map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn qualified_identifier(&self) -> Option> { + __rule_children(self.__node, 66) + .next() + .map(|node| QualifiedIdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn assign_token(&self) -> Option> { + __token_children(self.__node, 7) + .next() + .map(TerminalNode::new) + } + pub fn string_literal_token(&self) -> Option> { + __token_children(self.__node, 11) + .next() + .map(TerminalNode::new) + } + pub fn int_token(&self) -> Option> { + __token_children(self.__node, 33) + .next() + .map(TerminalNode::new) } } -impl std::fmt::Display for ElementOptionContext<'_> { +impl std::fmt::Display for ElementOptionContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -9090,9 +8545,10 @@ impl std::fmt::Display for ElementOptionContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct IdentifierContext<'a> { +pub struct IdentifierContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for IdentifierContext<'a> { @@ -9102,7 +8558,20 @@ impl<'a> FromRuleNode<'a> for IdentifierContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for IdentifierContext<'a> { +impl<'a> AsRuleNode<'a> for IdentifierContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> IdentifierContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for IdentifierContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -9115,6 +8584,7 @@ impl<'a> __FromActiveRuleContext<'a> for IdentifierContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -9146,15 +8616,21 @@ impl<'a> IdentifierContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> IdentifierContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -9164,7 +8640,7 @@ impl<'a> IdentifierContext<'a> { } } -impl std::fmt::Display for IdentifierContext<'_> { +impl std::fmt::Display for IdentifierContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -9173,9 +8649,10 @@ impl std::fmt::Display for IdentifierContext<'_> { #[allow(non_camel_case_types, dead_code)] #[derive(Clone)] -pub struct QualifiedIdentifierContext<'a> { +pub struct QualifiedIdentifierContext<'a, State = StoredTreeContext> { __node: __GeneratedRuleContext<'a>, __invocation_states: Vec, + __state: std::marker::PhantomData, } impl<'a> FromRuleNode<'a> for QualifiedIdentifierContext<'a> { @@ -9185,7 +8662,20 @@ impl<'a> FromRuleNode<'a> for QualifiedIdentifierContext<'a> { } } -impl<'a> __FromActiveRuleContext<'a> for QualifiedIdentifierContext<'a> { +impl<'a> AsRuleNode<'a> for QualifiedIdentifierContext<'a> { + fn as_rule_node(&self) -> RuleNodeView<'a> { self.rule_node() } +} + +impl<'a> QualifiedIdentifierContext<'a> { + pub fn rule_node(&self) -> RuleNodeView<'a> { + match self.__node { + __GeneratedRuleContext::Stored(node) => node, + __GeneratedRuleContext::Active { .. } => unreachable!("stored context type contains an active parser context"), + } + } +} + +impl<'a> __FromActiveRuleContext<'a> for QualifiedIdentifierContext<'a, __ActiveParserContext> { fn __from_active( context: &'a antlr4_runtime::ParserRuleContext, invocation_states: Vec, @@ -9198,6 +8688,7 @@ impl<'a> __FromActiveRuleContext<'a> for QualifiedIdentifierContext<'a> { Some(Self { __node: __GeneratedRuleContext::Active { context, storage, tokens }, __invocation_states: invocation_states, + __state: std::marker::PhantomData, }) } } @@ -9229,15 +8720,21 @@ impl<'a> QualifiedIdentifierContext<'a> { Self { __node: __GeneratedRuleContext::Stored(node), __invocation_states: invocation_states, + __state: std::marker::PhantomData, } } +} + +#[allow(dead_code, clippy::all)] +impl<'a, State> QualifiedIdentifierContext<'a, State> { pub fn child_count(&self) -> usize { match &self.__node { __GeneratedRuleContext::Stored(node) => node.child_count(), __GeneratedRuleContext::Active { context, .. } => context.child_count(), } } + pub fn start(&self) -> __GeneratedTokenView { let token = match &self.__node { __GeneratedRuleContext::Stored(node) => node.start(), @@ -9245,39 +8742,16 @@ impl<'a> QualifiedIdentifierContext<'a> { }; __GeneratedTokenView { text: token.map(|token| token.text().to_owned()).unwrap_or_default() } } - pub fn identifier(&self, index: usize) -> IdentifierContext<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).nth(index), - }.expect("missing rule child"); - IdentifierContext::__from_child_node(node, &self.__invocation_states) - } - pub fn identifier_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_rules(65).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_rules(storage, tokens, 65).collect(), - }; - nodes.into_iter().map(|node| IdentifierContext::__from_child_node(node, &self.__invocation_states)).collect() - } - #[allow(non_snake_case)] - pub fn DOT(&self, index: usize) -> TerminalNode<'a> { - let node = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(70).nth(index), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 70).nth(index), - }.expect("missing token child"); - TerminalNode::new(node) - } - #[allow(non_snake_case)] - pub fn DOT_all(&self) -> Vec> { - let nodes: Vec<_> = match &self.__node { - __GeneratedRuleContext::Stored(node) => node.child_tokens(70).collect(), - __GeneratedRuleContext::Active { context, storage, tokens, .. } => context.child_tokens(storage, tokens, 70).collect(), - }; - nodes.into_iter().map(TerminalNode::new).collect() + pub fn identifier_children(&self) -> impl Iterator> + '_ { + __rule_children(self.__node, 65) + .map(move |node| IdentifierContext::__from_child_node(node, &self.__invocation_states)) + } + pub fn dot_tokens(&self) -> impl Iterator> + '_ { + __token_children(self.__node, 70).map(TerminalNode::new) } } -impl std::fmt::Display for QualifiedIdentifierContext<'_> { +impl std::fmt::Display for QualifiedIdentifierContext<'_, State> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let chain: Vec = self.__invocation_states.iter().map(|state| state.to_string()).collect(); write!(f, "[{}]", chain.join(" ")) @@ -9285,602 +8759,363 @@ impl std::fmt::Display for QualifiedIdentifierContext<'_> { } #[allow(dead_code, unused_variables)] -pub trait ANTLRv4Listener { - fn enter_grammar_spec(&mut self, _ctx: &GrammarSpecContext) {} - fn exit_grammar_spec(&mut self, _ctx: &GrammarSpecContext) {} - fn enter_grammar_decl(&mut self, _ctx: &GrammarDeclContext) {} - fn exit_grammar_decl(&mut self, _ctx: &GrammarDeclContext) {} - fn enter_grammar_type(&mut self, _ctx: &GrammarTypeContext) {} - fn exit_grammar_type(&mut self, _ctx: &GrammarTypeContext) {} - fn enter_prequel_construct(&mut self, _ctx: &PrequelConstructContext) {} - fn exit_prequel_construct(&mut self, _ctx: &PrequelConstructContext) {} - fn enter_options_spec(&mut self, _ctx: &OptionsSpecContext) {} - fn exit_options_spec(&mut self, _ctx: &OptionsSpecContext) {} - fn enter_option(&mut self, _ctx: &OptionContext) {} - fn exit_option(&mut self, _ctx: &OptionContext) {} - fn enter_option_value(&mut self, _ctx: &OptionValueContext) {} - fn exit_option_value(&mut self, _ctx: &OptionValueContext) {} - fn enter_delegate_grammars(&mut self, _ctx: &DelegateGrammarsContext) {} - fn exit_delegate_grammars(&mut self, _ctx: &DelegateGrammarsContext) {} - fn enter_delegate_grammar(&mut self, _ctx: &DelegateGrammarContext) {} - fn exit_delegate_grammar(&mut self, _ctx: &DelegateGrammarContext) {} - fn enter_tokens_spec(&mut self, _ctx: &TokensSpecContext) {} - fn exit_tokens_spec(&mut self, _ctx: &TokensSpecContext) {} - fn enter_channels_spec(&mut self, _ctx: &ChannelsSpecContext) {} - fn exit_channels_spec(&mut self, _ctx: &ChannelsSpecContext) {} - fn enter_id_list(&mut self, _ctx: &IdListContext) {} - fn exit_id_list(&mut self, _ctx: &IdListContext) {} - fn enter_action(&mut self, _ctx: &ActionContext) {} - fn exit_action(&mut self, _ctx: &ActionContext) {} - fn enter_action_scope_name(&mut self, _ctx: &ActionScopeNameContext) {} - fn exit_action_scope_name(&mut self, _ctx: &ActionScopeNameContext) {} - fn enter_action_block(&mut self, _ctx: &ActionBlockContext) {} - fn exit_action_block(&mut self, _ctx: &ActionBlockContext) {} - fn enter_arg_action_block(&mut self, _ctx: &ArgActionBlockContext) {} - fn exit_arg_action_block(&mut self, _ctx: &ArgActionBlockContext) {} - fn enter_mode_spec(&mut self, _ctx: &ModeSpecContext) {} - fn exit_mode_spec(&mut self, _ctx: &ModeSpecContext) {} - fn enter_rules(&mut self, _ctx: &RulesContext) {} - fn exit_rules(&mut self, _ctx: &RulesContext) {} - fn enter_rule_spec(&mut self, _ctx: &RuleSpecContext) {} - fn exit_rule_spec(&mut self, _ctx: &RuleSpecContext) {} - fn enter_parser_rule_spec(&mut self, _ctx: &ParserRuleSpecContext) {} - fn exit_parser_rule_spec(&mut self, _ctx: &ParserRuleSpecContext) {} - fn enter_exception_group(&mut self, _ctx: &ExceptionGroupContext) {} - fn exit_exception_group(&mut self, _ctx: &ExceptionGroupContext) {} - fn enter_exception_handler(&mut self, _ctx: &ExceptionHandlerContext) {} - fn exit_exception_handler(&mut self, _ctx: &ExceptionHandlerContext) {} - fn enter_finally_clause(&mut self, _ctx: &FinallyClauseContext) {} - fn exit_finally_clause(&mut self, _ctx: &FinallyClauseContext) {} - fn enter_rule_prequel(&mut self, _ctx: &RulePrequelContext) {} - fn exit_rule_prequel(&mut self, _ctx: &RulePrequelContext) {} - fn enter_rule_returns(&mut self, _ctx: &RuleReturnsContext) {} - fn exit_rule_returns(&mut self, _ctx: &RuleReturnsContext) {} - fn enter_throws_spec(&mut self, _ctx: &ThrowsSpecContext) {} - fn exit_throws_spec(&mut self, _ctx: &ThrowsSpecContext) {} - fn enter_locals_spec(&mut self, _ctx: &LocalsSpecContext) {} - fn exit_locals_spec(&mut self, _ctx: &LocalsSpecContext) {} - fn enter_rule_action(&mut self, _ctx: &RuleActionContext) {} - fn exit_rule_action(&mut self, _ctx: &RuleActionContext) {} - fn enter_rule_modifiers(&mut self, _ctx: &RuleModifiersContext) {} - fn exit_rule_modifiers(&mut self, _ctx: &RuleModifiersContext) {} - fn enter_rule_modifier(&mut self, _ctx: &RuleModifierContext) {} - fn exit_rule_modifier(&mut self, _ctx: &RuleModifierContext) {} - fn enter_rule_block(&mut self, _ctx: &RuleBlockContext) {} - fn exit_rule_block(&mut self, _ctx: &RuleBlockContext) {} - fn enter_rule_alt_list(&mut self, _ctx: &RuleAltListContext) {} - fn exit_rule_alt_list(&mut self, _ctx: &RuleAltListContext) {} - fn enter_labeled_alt(&mut self, _ctx: &LabeledAltContext) {} - fn exit_labeled_alt(&mut self, _ctx: &LabeledAltContext) {} - fn enter_lexer_rule_spec(&mut self, _ctx: &LexerRuleSpecContext) {} - fn exit_lexer_rule_spec(&mut self, _ctx: &LexerRuleSpecContext) {} - fn enter_lexer_rule_block(&mut self, _ctx: &LexerRuleBlockContext) {} - fn exit_lexer_rule_block(&mut self, _ctx: &LexerRuleBlockContext) {} - fn enter_lexer_alt_list(&mut self, _ctx: &LexerAltListContext) {} - fn exit_lexer_alt_list(&mut self, _ctx: &LexerAltListContext) {} - fn enter_lexer_alt(&mut self, _ctx: &LexerAltContext) {} - fn exit_lexer_alt(&mut self, _ctx: &LexerAltContext) {} - fn enter_lexer_elements(&mut self, _ctx: &LexerElementsContext) {} - fn exit_lexer_elements(&mut self, _ctx: &LexerElementsContext) {} - fn enter_lexer_element(&mut self, _ctx: &LexerElementContext) {} - fn exit_lexer_element(&mut self, _ctx: &LexerElementContext) {} - fn enter_lexer_block(&mut self, _ctx: &LexerBlockContext) {} - fn exit_lexer_block(&mut self, _ctx: &LexerBlockContext) {} - fn enter_lexer_commands(&mut self, _ctx: &LexerCommandsContext) {} - fn exit_lexer_commands(&mut self, _ctx: &LexerCommandsContext) {} - fn enter_lexer_command(&mut self, _ctx: &LexerCommandContext) {} - fn exit_lexer_command(&mut self, _ctx: &LexerCommandContext) {} - fn enter_lexer_command_name(&mut self, _ctx: &LexerCommandNameContext) {} - fn exit_lexer_command_name(&mut self, _ctx: &LexerCommandNameContext) {} - fn enter_lexer_command_expr(&mut self, _ctx: &LexerCommandExprContext) {} - fn exit_lexer_command_expr(&mut self, _ctx: &LexerCommandExprContext) {} - fn enter_alt_list(&mut self, _ctx: &AltListContext) {} - fn exit_alt_list(&mut self, _ctx: &AltListContext) {} - fn enter_alternative(&mut self, _ctx: &AlternativeContext) {} - fn exit_alternative(&mut self, _ctx: &AlternativeContext) {} - fn enter_element(&mut self, _ctx: &ElementContext) {} - fn exit_element(&mut self, _ctx: &ElementContext) {} - fn enter_predicate_options(&mut self, _ctx: &PredicateOptionsContext) {} - fn exit_predicate_options(&mut self, _ctx: &PredicateOptionsContext) {} - fn enter_predicate_option(&mut self, _ctx: &PredicateOptionContext) {} - fn exit_predicate_option(&mut self, _ctx: &PredicateOptionContext) {} - fn enter_labeled_element(&mut self, _ctx: &LabeledElementContext) {} - fn exit_labeled_element(&mut self, _ctx: &LabeledElementContext) {} - fn enter_ebnf(&mut self, _ctx: &EbnfContext) {} - fn exit_ebnf(&mut self, _ctx: &EbnfContext) {} - fn enter_block_suffix(&mut self, _ctx: &BlockSuffixContext) {} - fn exit_block_suffix(&mut self, _ctx: &BlockSuffixContext) {} - fn enter_ebnf_suffix(&mut self, _ctx: &EbnfSuffixContext) {} - fn exit_ebnf_suffix(&mut self, _ctx: &EbnfSuffixContext) {} - fn enter_lexer_atom(&mut self, _ctx: &LexerAtomContext) {} - fn exit_lexer_atom(&mut self, _ctx: &LexerAtomContext) {} - fn enter_atom(&mut self, _ctx: &AtomContext) {} - fn exit_atom(&mut self, _ctx: &AtomContext) {} - fn enter_wildcard(&mut self, _ctx: &WildcardContext) {} - fn exit_wildcard(&mut self, _ctx: &WildcardContext) {} - fn enter_not_set(&mut self, _ctx: &NotSetContext) {} - fn exit_not_set(&mut self, _ctx: &NotSetContext) {} - fn enter_block_set(&mut self, _ctx: &BlockSetContext) {} - fn exit_block_set(&mut self, _ctx: &BlockSetContext) {} - fn enter_set_element(&mut self, _ctx: &SetElementContext) {} - fn exit_set_element(&mut self, _ctx: &SetElementContext) {} - fn enter_block(&mut self, _ctx: &BlockContext) {} - fn exit_block(&mut self, _ctx: &BlockContext) {} - fn enter_ruleref(&mut self, _ctx: &RulerefContext) {} - fn exit_ruleref(&mut self, _ctx: &RulerefContext) {} - fn enter_character_range(&mut self, _ctx: &CharacterRangeContext) {} - fn exit_character_range(&mut self, _ctx: &CharacterRangeContext) {} - fn enter_terminal_def(&mut self, _ctx: &TerminalDefContext) {} - fn exit_terminal_def(&mut self, _ctx: &TerminalDefContext) {} - fn enter_element_options(&mut self, _ctx: &ElementOptionsContext) {} - fn exit_element_options(&mut self, _ctx: &ElementOptionsContext) {} - fn enter_element_option(&mut self, _ctx: &ElementOptionContext) {} - fn exit_element_option(&mut self, _ctx: &ElementOptionContext) {} - fn enter_identifier(&mut self, _ctx: &IdentifierContext) {} - fn exit_identifier(&mut self, _ctx: &IdentifierContext) {} - fn enter_qualified_identifier(&mut self, _ctx: &QualifiedIdentifierContext) {} - fn exit_qualified_identifier(&mut self, _ctx: &QualifiedIdentifierContext) {} - fn visit_terminal(&mut self, _node: &TerminalNode) {} - fn visit_error_node(&mut self, _node: &ErrorNode) {} +pub trait ANTLRv4Listener { + fn walk(&mut self, tree: antlr4_runtime::Node<'_>) -> Result<(), E> + where + Self: Sized, + { + ANTLRv4TreeWalker::walk(self, tree) + } + + fn enter_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), E> { Ok(()) } + fn exit_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), E> { Ok(()) } + + fn enter_grammar_spec(&mut self, _ctx: &GrammarSpecContext) -> Result<(), E> { Ok(()) } + fn exit_grammar_spec(&mut self, _ctx: &GrammarSpecContext) -> Result<(), E> { Ok(()) } + fn enter_grammar_decl(&mut self, _ctx: &GrammarDeclContext) -> Result<(), E> { Ok(()) } + fn exit_grammar_decl(&mut self, _ctx: &GrammarDeclContext) -> Result<(), E> { Ok(()) } + fn enter_grammar_type(&mut self, _ctx: &GrammarTypeContext) -> Result<(), E> { Ok(()) } + fn exit_grammar_type(&mut self, _ctx: &GrammarTypeContext) -> Result<(), E> { Ok(()) } + fn enter_prequel_construct(&mut self, _ctx: &PrequelConstructContext) -> Result<(), E> { Ok(()) } + fn exit_prequel_construct(&mut self, _ctx: &PrequelConstructContext) -> Result<(), E> { Ok(()) } + fn enter_options_spec(&mut self, _ctx: &OptionsSpecContext) -> Result<(), E> { Ok(()) } + fn exit_options_spec(&mut self, _ctx: &OptionsSpecContext) -> Result<(), E> { Ok(()) } + fn enter_option(&mut self, _ctx: &OptionContext) -> Result<(), E> { Ok(()) } + fn exit_option(&mut self, _ctx: &OptionContext) -> Result<(), E> { Ok(()) } + fn enter_option_value(&mut self, _ctx: &OptionValueContext) -> Result<(), E> { Ok(()) } + fn exit_option_value(&mut self, _ctx: &OptionValueContext) -> Result<(), E> { Ok(()) } + fn enter_delegate_grammars(&mut self, _ctx: &DelegateGrammarsContext) -> Result<(), E> { Ok(()) } + fn exit_delegate_grammars(&mut self, _ctx: &DelegateGrammarsContext) -> Result<(), E> { Ok(()) } + fn enter_delegate_grammar(&mut self, _ctx: &DelegateGrammarContext) -> Result<(), E> { Ok(()) } + fn exit_delegate_grammar(&mut self, _ctx: &DelegateGrammarContext) -> Result<(), E> { Ok(()) } + fn enter_tokens_spec(&mut self, _ctx: &TokensSpecContext) -> Result<(), E> { Ok(()) } + fn exit_tokens_spec(&mut self, _ctx: &TokensSpecContext) -> Result<(), E> { Ok(()) } + fn enter_channels_spec(&mut self, _ctx: &ChannelsSpecContext) -> Result<(), E> { Ok(()) } + fn exit_channels_spec(&mut self, _ctx: &ChannelsSpecContext) -> Result<(), E> { Ok(()) } + fn enter_id_list(&mut self, _ctx: &IdListContext) -> Result<(), E> { Ok(()) } + fn exit_id_list(&mut self, _ctx: &IdListContext) -> Result<(), E> { Ok(()) } + fn enter_action(&mut self, _ctx: &ActionContext) -> Result<(), E> { Ok(()) } + fn exit_action(&mut self, _ctx: &ActionContext) -> Result<(), E> { Ok(()) } + fn enter_action_scope_name(&mut self, _ctx: &ActionScopeNameContext) -> Result<(), E> { Ok(()) } + fn exit_action_scope_name(&mut self, _ctx: &ActionScopeNameContext) -> Result<(), E> { Ok(()) } + fn enter_action_block(&mut self, _ctx: &ActionBlockContext) -> Result<(), E> { Ok(()) } + fn exit_action_block(&mut self, _ctx: &ActionBlockContext) -> Result<(), E> { Ok(()) } + fn enter_arg_action_block(&mut self, _ctx: &ArgActionBlockContext) -> Result<(), E> { Ok(()) } + fn exit_arg_action_block(&mut self, _ctx: &ArgActionBlockContext) -> Result<(), E> { Ok(()) } + fn enter_mode_spec(&mut self, _ctx: &ModeSpecContext) -> Result<(), E> { Ok(()) } + fn exit_mode_spec(&mut self, _ctx: &ModeSpecContext) -> Result<(), E> { Ok(()) } + fn enter_rules(&mut self, _ctx: &RulesContext) -> Result<(), E> { Ok(()) } + fn exit_rules(&mut self, _ctx: &RulesContext) -> Result<(), E> { Ok(()) } + fn enter_rule_spec(&mut self, _ctx: &RuleSpecContext) -> Result<(), E> { Ok(()) } + fn exit_rule_spec(&mut self, _ctx: &RuleSpecContext) -> Result<(), E> { Ok(()) } + fn enter_parser_rule_spec(&mut self, _ctx: &ParserRuleSpecContext) -> Result<(), E> { Ok(()) } + fn exit_parser_rule_spec(&mut self, _ctx: &ParserRuleSpecContext) -> Result<(), E> { Ok(()) } + fn enter_exception_group(&mut self, _ctx: &ExceptionGroupContext) -> Result<(), E> { Ok(()) } + fn exit_exception_group(&mut self, _ctx: &ExceptionGroupContext) -> Result<(), E> { Ok(()) } + fn enter_exception_handler(&mut self, _ctx: &ExceptionHandlerContext) -> Result<(), E> { Ok(()) } + fn exit_exception_handler(&mut self, _ctx: &ExceptionHandlerContext) -> Result<(), E> { Ok(()) } + fn enter_finally_clause(&mut self, _ctx: &FinallyClauseContext) -> Result<(), E> { Ok(()) } + fn exit_finally_clause(&mut self, _ctx: &FinallyClauseContext) -> Result<(), E> { Ok(()) } + fn enter_rule_prequel(&mut self, _ctx: &RulePrequelContext) -> Result<(), E> { Ok(()) } + fn exit_rule_prequel(&mut self, _ctx: &RulePrequelContext) -> Result<(), E> { Ok(()) } + fn enter_rule_returns(&mut self, _ctx: &RuleReturnsContext) -> Result<(), E> { Ok(()) } + fn exit_rule_returns(&mut self, _ctx: &RuleReturnsContext) -> Result<(), E> { Ok(()) } + fn enter_throws_spec(&mut self, _ctx: &ThrowsSpecContext) -> Result<(), E> { Ok(()) } + fn exit_throws_spec(&mut self, _ctx: &ThrowsSpecContext) -> Result<(), E> { Ok(()) } + fn enter_locals_spec(&mut self, _ctx: &LocalsSpecContext) -> Result<(), E> { Ok(()) } + fn exit_locals_spec(&mut self, _ctx: &LocalsSpecContext) -> Result<(), E> { Ok(()) } + fn enter_rule_action(&mut self, _ctx: &RuleActionContext) -> Result<(), E> { Ok(()) } + fn exit_rule_action(&mut self, _ctx: &RuleActionContext) -> Result<(), E> { Ok(()) } + fn enter_rule_modifiers(&mut self, _ctx: &RuleModifiersContext) -> Result<(), E> { Ok(()) } + fn exit_rule_modifiers(&mut self, _ctx: &RuleModifiersContext) -> Result<(), E> { Ok(()) } + fn enter_rule_modifier(&mut self, _ctx: &RuleModifierContext) -> Result<(), E> { Ok(()) } + fn exit_rule_modifier(&mut self, _ctx: &RuleModifierContext) -> Result<(), E> { Ok(()) } + fn enter_rule_block(&mut self, _ctx: &RuleBlockContext) -> Result<(), E> { Ok(()) } + fn exit_rule_block(&mut self, _ctx: &RuleBlockContext) -> Result<(), E> { Ok(()) } + fn enter_rule_alt_list(&mut self, _ctx: &RuleAltListContext) -> Result<(), E> { Ok(()) } + fn exit_rule_alt_list(&mut self, _ctx: &RuleAltListContext) -> Result<(), E> { Ok(()) } + fn enter_labeled_alt(&mut self, _ctx: &LabeledAltContext) -> Result<(), E> { Ok(()) } + fn exit_labeled_alt(&mut self, _ctx: &LabeledAltContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_rule_spec(&mut self, _ctx: &LexerRuleSpecContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_rule_spec(&mut self, _ctx: &LexerRuleSpecContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_rule_block(&mut self, _ctx: &LexerRuleBlockContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_rule_block(&mut self, _ctx: &LexerRuleBlockContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_alt_list(&mut self, _ctx: &LexerAltListContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_alt_list(&mut self, _ctx: &LexerAltListContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_alt(&mut self, _ctx: &LexerAltContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_alt(&mut self, _ctx: &LexerAltContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_elements(&mut self, _ctx: &LexerElementsContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_elements(&mut self, _ctx: &LexerElementsContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_element(&mut self, _ctx: &LexerElementContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_element(&mut self, _ctx: &LexerElementContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_block(&mut self, _ctx: &LexerBlockContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_block(&mut self, _ctx: &LexerBlockContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_commands(&mut self, _ctx: &LexerCommandsContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_commands(&mut self, _ctx: &LexerCommandsContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_command(&mut self, _ctx: &LexerCommandContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_command(&mut self, _ctx: &LexerCommandContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_command_name(&mut self, _ctx: &LexerCommandNameContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_command_name(&mut self, _ctx: &LexerCommandNameContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_command_expr(&mut self, _ctx: &LexerCommandExprContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_command_expr(&mut self, _ctx: &LexerCommandExprContext) -> Result<(), E> { Ok(()) } + fn enter_alt_list(&mut self, _ctx: &AltListContext) -> Result<(), E> { Ok(()) } + fn exit_alt_list(&mut self, _ctx: &AltListContext) -> Result<(), E> { Ok(()) } + fn enter_alternative(&mut self, _ctx: &AlternativeContext) -> Result<(), E> { Ok(()) } + fn exit_alternative(&mut self, _ctx: &AlternativeContext) -> Result<(), E> { Ok(()) } + fn enter_element(&mut self, _ctx: &ElementContext) -> Result<(), E> { Ok(()) } + fn exit_element(&mut self, _ctx: &ElementContext) -> Result<(), E> { Ok(()) } + fn enter_predicate_options(&mut self, _ctx: &PredicateOptionsContext) -> Result<(), E> { Ok(()) } + fn exit_predicate_options(&mut self, _ctx: &PredicateOptionsContext) -> Result<(), E> { Ok(()) } + fn enter_predicate_option(&mut self, _ctx: &PredicateOptionContext) -> Result<(), E> { Ok(()) } + fn exit_predicate_option(&mut self, _ctx: &PredicateOptionContext) -> Result<(), E> { Ok(()) } + fn enter_labeled_element(&mut self, _ctx: &LabeledElementContext) -> Result<(), E> { Ok(()) } + fn exit_labeled_element(&mut self, _ctx: &LabeledElementContext) -> Result<(), E> { Ok(()) } + fn enter_ebnf(&mut self, _ctx: &EbnfContext) -> Result<(), E> { Ok(()) } + fn exit_ebnf(&mut self, _ctx: &EbnfContext) -> Result<(), E> { Ok(()) } + fn enter_block_suffix(&mut self, _ctx: &BlockSuffixContext) -> Result<(), E> { Ok(()) } + fn exit_block_suffix(&mut self, _ctx: &BlockSuffixContext) -> Result<(), E> { Ok(()) } + fn enter_ebnf_suffix(&mut self, _ctx: &EbnfSuffixContext) -> Result<(), E> { Ok(()) } + fn exit_ebnf_suffix(&mut self, _ctx: &EbnfSuffixContext) -> Result<(), E> { Ok(()) } + fn enter_lexer_atom(&mut self, _ctx: &LexerAtomContext) -> Result<(), E> { Ok(()) } + fn exit_lexer_atom(&mut self, _ctx: &LexerAtomContext) -> Result<(), E> { Ok(()) } + fn enter_atom(&mut self, _ctx: &AtomContext) -> Result<(), E> { Ok(()) } + fn exit_atom(&mut self, _ctx: &AtomContext) -> Result<(), E> { Ok(()) } + fn enter_wildcard(&mut self, _ctx: &WildcardContext) -> Result<(), E> { Ok(()) } + fn exit_wildcard(&mut self, _ctx: &WildcardContext) -> Result<(), E> { Ok(()) } + fn enter_not_set(&mut self, _ctx: &NotSetContext) -> Result<(), E> { Ok(()) } + fn exit_not_set(&mut self, _ctx: &NotSetContext) -> Result<(), E> { Ok(()) } + fn enter_block_set(&mut self, _ctx: &BlockSetContext) -> Result<(), E> { Ok(()) } + fn exit_block_set(&mut self, _ctx: &BlockSetContext) -> Result<(), E> { Ok(()) } + fn enter_set_element(&mut self, _ctx: &SetElementContext) -> Result<(), E> { Ok(()) } + fn exit_set_element(&mut self, _ctx: &SetElementContext) -> Result<(), E> { Ok(()) } + fn enter_block(&mut self, _ctx: &BlockContext) -> Result<(), E> { Ok(()) } + fn exit_block(&mut self, _ctx: &BlockContext) -> Result<(), E> { Ok(()) } + fn enter_ruleref(&mut self, _ctx: &RulerefContext) -> Result<(), E> { Ok(()) } + fn exit_ruleref(&mut self, _ctx: &RulerefContext) -> Result<(), E> { Ok(()) } + fn enter_character_range(&mut self, _ctx: &CharacterRangeContext) -> Result<(), E> { Ok(()) } + fn exit_character_range(&mut self, _ctx: &CharacterRangeContext) -> Result<(), E> { Ok(()) } + fn enter_terminal_def(&mut self, _ctx: &TerminalDefContext) -> Result<(), E> { Ok(()) } + fn exit_terminal_def(&mut self, _ctx: &TerminalDefContext) -> Result<(), E> { Ok(()) } + fn enter_element_options(&mut self, _ctx: &ElementOptionsContext) -> Result<(), E> { Ok(()) } + fn exit_element_options(&mut self, _ctx: &ElementOptionsContext) -> Result<(), E> { Ok(()) } + fn enter_element_option(&mut self, _ctx: &ElementOptionContext) -> Result<(), E> { Ok(()) } + fn exit_element_option(&mut self, _ctx: &ElementOptionContext) -> Result<(), E> { Ok(()) } + fn enter_identifier(&mut self, _ctx: &IdentifierContext) -> Result<(), E> { Ok(()) } + fn exit_identifier(&mut self, _ctx: &IdentifierContext) -> Result<(), E> { Ok(()) } + fn enter_qualified_identifier(&mut self, _ctx: &QualifiedIdentifierContext) -> Result<(), E> { Ok(()) } + fn exit_qualified_identifier(&mut self, _ctx: &QualifiedIdentifierContext) -> Result<(), E> { Ok(()) } + fn visit_terminal(&mut self, _node: &TerminalNode) -> Result<(), E> { Ok(()) } + fn visit_error_node(&mut self, _node: &ErrorNode) -> Result<(), E> { Ok(()) } fn output(&mut self) -> std::io::Stdout { std::io::stdout() } } #[allow(dead_code)] -struct __ListenerBridge<'a, T: ANTLRv4Listener>(&'a mut T, Option>); +pub struct ANTLRv4TreeWalker; -impl antlr4_runtime::ParseTreeListener for __ListenerBridge<'_, T> { - fn enter_every_rule(&mut self, context: RuleNodeView<'_>) -> Result<(), antlr4_runtime::AntlrError> { - if let Some(invocation_states) = &mut self.1 { - invocation_states.insert(0, context.invoking_state()); - } - match context.rule_index() { - 0 => { - self.0.enter_grammar_spec(&GrammarSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 1 => { - self.0.enter_grammar_decl(&GrammarDeclContext::__from_listener_node(context, self.1.as_deref())); - } - 2 => { - self.0.enter_grammar_type(&GrammarTypeContext::__from_listener_node(context, self.1.as_deref())); - } - 3 => { - self.0.enter_prequel_construct(&PrequelConstructContext::__from_listener_node(context, self.1.as_deref())); - } - 4 => { - self.0.enter_options_spec(&OptionsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 5 => { - self.0.enter_option(&OptionContext::__from_listener_node(context, self.1.as_deref())); - } - 6 => { - self.0.enter_option_value(&OptionValueContext::__from_listener_node(context, self.1.as_deref())); - } - 7 => { - self.0.enter_delegate_grammars(&DelegateGrammarsContext::__from_listener_node(context, self.1.as_deref())); - } - 8 => { - self.0.enter_delegate_grammar(&DelegateGrammarContext::__from_listener_node(context, self.1.as_deref())); - } - 9 => { - self.0.enter_tokens_spec(&TokensSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 10 => { - self.0.enter_channels_spec(&ChannelsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 11 => { - self.0.enter_id_list(&IdListContext::__from_listener_node(context, self.1.as_deref())); - } - 12 => { - self.0.enter_action(&ActionContext::__from_listener_node(context, self.1.as_deref())); - } - 13 => { - self.0.enter_action_scope_name(&ActionScopeNameContext::__from_listener_node(context, self.1.as_deref())); - } - 14 => { - self.0.enter_action_block(&ActionBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 15 => { - self.0.enter_arg_action_block(&ArgActionBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 16 => { - self.0.enter_mode_spec(&ModeSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 17 => { - self.0.enter_rules(&RulesContext::__from_listener_node(context, self.1.as_deref())); - } - 18 => { - self.0.enter_rule_spec(&RuleSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 19 => { - self.0.enter_parser_rule_spec(&ParserRuleSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 20 => { - self.0.enter_exception_group(&ExceptionGroupContext::__from_listener_node(context, self.1.as_deref())); - } - 21 => { - self.0.enter_exception_handler(&ExceptionHandlerContext::__from_listener_node(context, self.1.as_deref())); - } - 22 => { - self.0.enter_finally_clause(&FinallyClauseContext::__from_listener_node(context, self.1.as_deref())); - } - 23 => { - self.0.enter_rule_prequel(&RulePrequelContext::__from_listener_node(context, self.1.as_deref())); - } - 24 => { - self.0.enter_rule_returns(&RuleReturnsContext::__from_listener_node(context, self.1.as_deref())); - } - 25 => { - self.0.enter_throws_spec(&ThrowsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 26 => { - self.0.enter_locals_spec(&LocalsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 27 => { - self.0.enter_rule_action(&RuleActionContext::__from_listener_node(context, self.1.as_deref())); - } - 28 => { - self.0.enter_rule_modifiers(&RuleModifiersContext::__from_listener_node(context, self.1.as_deref())); - } - 29 => { - self.0.enter_rule_modifier(&RuleModifierContext::__from_listener_node(context, self.1.as_deref())); - } - 30 => { - self.0.enter_rule_block(&RuleBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 31 => { - self.0.enter_rule_alt_list(&RuleAltListContext::__from_listener_node(context, self.1.as_deref())); - } - 32 => { - self.0.enter_labeled_alt(&LabeledAltContext::__from_listener_node(context, self.1.as_deref())); - } - 33 => { - self.0.enter_lexer_rule_spec(&LexerRuleSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 34 => { - self.0.enter_lexer_rule_block(&LexerRuleBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 35 => { - self.0.enter_lexer_alt_list(&LexerAltListContext::__from_listener_node(context, self.1.as_deref())); - } - 36 => { - self.0.enter_lexer_alt(&LexerAltContext::__from_listener_node(context, self.1.as_deref())); - } - 37 => { - self.0.enter_lexer_elements(&LexerElementsContext::__from_listener_node(context, self.1.as_deref())); - } - 38 => { - self.0.enter_lexer_element(&LexerElementContext::__from_listener_node(context, self.1.as_deref())); - } - 39 => { - self.0.enter_lexer_block(&LexerBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 40 => { - self.0.enter_lexer_commands(&LexerCommandsContext::__from_listener_node(context, self.1.as_deref())); - } - 41 => { - self.0.enter_lexer_command(&LexerCommandContext::__from_listener_node(context, self.1.as_deref())); - } - 42 => { - self.0.enter_lexer_command_name(&LexerCommandNameContext::__from_listener_node(context, self.1.as_deref())); - } - 43 => { - self.0.enter_lexer_command_expr(&LexerCommandExprContext::__from_listener_node(context, self.1.as_deref())); - } - 44 => { - self.0.enter_alt_list(&AltListContext::__from_listener_node(context, self.1.as_deref())); - } - 45 => { - self.0.enter_alternative(&AlternativeContext::__from_listener_node(context, self.1.as_deref())); - } - 46 => { - self.0.enter_element(&ElementContext::__from_listener_node(context, self.1.as_deref())); - } - 47 => { - self.0.enter_predicate_options(&PredicateOptionsContext::__from_listener_node(context, self.1.as_deref())); - } - 48 => { - self.0.enter_predicate_option(&PredicateOptionContext::__from_listener_node(context, self.1.as_deref())); - } - 49 => { - self.0.enter_labeled_element(&LabeledElementContext::__from_listener_node(context, self.1.as_deref())); - } - 50 => { - self.0.enter_ebnf(&EbnfContext::__from_listener_node(context, self.1.as_deref())); - } - 51 => { - self.0.enter_block_suffix(&BlockSuffixContext::__from_listener_node(context, self.1.as_deref())); - } - 52 => { - self.0.enter_ebnf_suffix(&EbnfSuffixContext::__from_listener_node(context, self.1.as_deref())); - } - 53 => { - self.0.enter_lexer_atom(&LexerAtomContext::__from_listener_node(context, self.1.as_deref())); - } - 54 => { - self.0.enter_atom(&AtomContext::__from_listener_node(context, self.1.as_deref())); - } - 55 => { - self.0.enter_wildcard(&WildcardContext::__from_listener_node(context, self.1.as_deref())); - } - 56 => { - self.0.enter_not_set(&NotSetContext::__from_listener_node(context, self.1.as_deref())); - } - 57 => { - self.0.enter_block_set(&BlockSetContext::__from_listener_node(context, self.1.as_deref())); - } - 58 => { - self.0.enter_set_element(&SetElementContext::__from_listener_node(context, self.1.as_deref())); - } - 59 => { - self.0.enter_block(&BlockContext::__from_listener_node(context, self.1.as_deref())); - } - 60 => { - self.0.enter_ruleref(&RulerefContext::__from_listener_node(context, self.1.as_deref())); - } - 61 => { - self.0.enter_character_range(&CharacterRangeContext::__from_listener_node(context, self.1.as_deref())); - } - 62 => { - self.0.enter_terminal_def(&TerminalDefContext::__from_listener_node(context, self.1.as_deref())); - } - 63 => { - self.0.enter_element_options(&ElementOptionsContext::__from_listener_node(context, self.1.as_deref())); - } - 64 => { - self.0.enter_element_option(&ElementOptionContext::__from_listener_node(context, self.1.as_deref())); - } - 65 => { - self.0.enter_identifier(&IdentifierContext::__from_listener_node(context, self.1.as_deref())); - } - 66 => { - self.0.enter_qualified_identifier(&QualifiedIdentifierContext::__from_listener_node(context, self.1.as_deref())); - } - _ => {} - } - Ok(()) +#[allow(dead_code)] +impl ANTLRv4TreeWalker { + pub fn walk>( + listener: &mut T, + tree: antlr4_runtime::Node<'_>, + ) -> Result<(), E> { + Self::__walk(listener, tree, None) } - fn exit_every_rule(&mut self, context: RuleNodeView<'_>) -> Result<(), antlr4_runtime::AntlrError> { - match context.rule_index() { - 0 => { - self.0.exit_grammar_spec(&GrammarSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 1 => { - self.0.exit_grammar_decl(&GrammarDeclContext::__from_listener_node(context, self.1.as_deref())); - } - 2 => { - self.0.exit_grammar_type(&GrammarTypeContext::__from_listener_node(context, self.1.as_deref())); - } - 3 => { - self.0.exit_prequel_construct(&PrequelConstructContext::__from_listener_node(context, self.1.as_deref())); - } - 4 => { - self.0.exit_options_spec(&OptionsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 5 => { - self.0.exit_option(&OptionContext::__from_listener_node(context, self.1.as_deref())); - } - 6 => { - self.0.exit_option_value(&OptionValueContext::__from_listener_node(context, self.1.as_deref())); - } - 7 => { - self.0.exit_delegate_grammars(&DelegateGrammarsContext::__from_listener_node(context, self.1.as_deref())); - } - 8 => { - self.0.exit_delegate_grammar(&DelegateGrammarContext::__from_listener_node(context, self.1.as_deref())); - } - 9 => { - self.0.exit_tokens_spec(&TokensSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 10 => { - self.0.exit_channels_spec(&ChannelsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 11 => { - self.0.exit_id_list(&IdListContext::__from_listener_node(context, self.1.as_deref())); - } - 12 => { - self.0.exit_action(&ActionContext::__from_listener_node(context, self.1.as_deref())); - } - 13 => { - self.0.exit_action_scope_name(&ActionScopeNameContext::__from_listener_node(context, self.1.as_deref())); - } - 14 => { - self.0.exit_action_block(&ActionBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 15 => { - self.0.exit_arg_action_block(&ArgActionBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 16 => { - self.0.exit_mode_spec(&ModeSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 17 => { - self.0.exit_rules(&RulesContext::__from_listener_node(context, self.1.as_deref())); - } - 18 => { - self.0.exit_rule_spec(&RuleSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 19 => { - self.0.exit_parser_rule_spec(&ParserRuleSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 20 => { - self.0.exit_exception_group(&ExceptionGroupContext::__from_listener_node(context, self.1.as_deref())); - } - 21 => { - self.0.exit_exception_handler(&ExceptionHandlerContext::__from_listener_node(context, self.1.as_deref())); - } - 22 => { - self.0.exit_finally_clause(&FinallyClauseContext::__from_listener_node(context, self.1.as_deref())); - } - 23 => { - self.0.exit_rule_prequel(&RulePrequelContext::__from_listener_node(context, self.1.as_deref())); - } - 24 => { - self.0.exit_rule_returns(&RuleReturnsContext::__from_listener_node(context, self.1.as_deref())); - } - 25 => { - self.0.exit_throws_spec(&ThrowsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 26 => { - self.0.exit_locals_spec(&LocalsSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 27 => { - self.0.exit_rule_action(&RuleActionContext::__from_listener_node(context, self.1.as_deref())); - } - 28 => { - self.0.exit_rule_modifiers(&RuleModifiersContext::__from_listener_node(context, self.1.as_deref())); - } - 29 => { - self.0.exit_rule_modifier(&RuleModifierContext::__from_listener_node(context, self.1.as_deref())); - } - 30 => { - self.0.exit_rule_block(&RuleBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 31 => { - self.0.exit_rule_alt_list(&RuleAltListContext::__from_listener_node(context, self.1.as_deref())); - } - 32 => { - self.0.exit_labeled_alt(&LabeledAltContext::__from_listener_node(context, self.1.as_deref())); - } - 33 => { - self.0.exit_lexer_rule_spec(&LexerRuleSpecContext::__from_listener_node(context, self.1.as_deref())); - } - 34 => { - self.0.exit_lexer_rule_block(&LexerRuleBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 35 => { - self.0.exit_lexer_alt_list(&LexerAltListContext::__from_listener_node(context, self.1.as_deref())); - } - 36 => { - self.0.exit_lexer_alt(&LexerAltContext::__from_listener_node(context, self.1.as_deref())); - } - 37 => { - self.0.exit_lexer_elements(&LexerElementsContext::__from_listener_node(context, self.1.as_deref())); - } - 38 => { - self.0.exit_lexer_element(&LexerElementContext::__from_listener_node(context, self.1.as_deref())); - } - 39 => { - self.0.exit_lexer_block(&LexerBlockContext::__from_listener_node(context, self.1.as_deref())); - } - 40 => { - self.0.exit_lexer_commands(&LexerCommandsContext::__from_listener_node(context, self.1.as_deref())); - } - 41 => { - self.0.exit_lexer_command(&LexerCommandContext::__from_listener_node(context, self.1.as_deref())); - } - 42 => { - self.0.exit_lexer_command_name(&LexerCommandNameContext::__from_listener_node(context, self.1.as_deref())); - } - 43 => { - self.0.exit_lexer_command_expr(&LexerCommandExprContext::__from_listener_node(context, self.1.as_deref())); - } - 44 => { - self.0.exit_alt_list(&AltListContext::__from_listener_node(context, self.1.as_deref())); - } - 45 => { - self.0.exit_alternative(&AlternativeContext::__from_listener_node(context, self.1.as_deref())); - } - 46 => { - self.0.exit_element(&ElementContext::__from_listener_node(context, self.1.as_deref())); - } - 47 => { - self.0.exit_predicate_options(&PredicateOptionsContext::__from_listener_node(context, self.1.as_deref())); - } - 48 => { - self.0.exit_predicate_option(&PredicateOptionContext::__from_listener_node(context, self.1.as_deref())); - } - 49 => { - self.0.exit_labeled_element(&LabeledElementContext::__from_listener_node(context, self.1.as_deref())); - } - 50 => { - self.0.exit_ebnf(&EbnfContext::__from_listener_node(context, self.1.as_deref())); - } - 51 => { - self.0.exit_block_suffix(&BlockSuffixContext::__from_listener_node(context, self.1.as_deref())); - } - 52 => { - self.0.exit_ebnf_suffix(&EbnfSuffixContext::__from_listener_node(context, self.1.as_deref())); - } - 53 => { - self.0.exit_lexer_atom(&LexerAtomContext::__from_listener_node(context, self.1.as_deref())); - } - 54 => { - self.0.exit_atom(&AtomContext::__from_listener_node(context, self.1.as_deref())); - } - 55 => { - self.0.exit_wildcard(&WildcardContext::__from_listener_node(context, self.1.as_deref())); - } - 56 => { - self.0.exit_not_set(&NotSetContext::__from_listener_node(context, self.1.as_deref())); - } - 57 => { - self.0.exit_block_set(&BlockSetContext::__from_listener_node(context, self.1.as_deref())); - } - 58 => { - self.0.exit_set_element(&SetElementContext::__from_listener_node(context, self.1.as_deref())); - } - 59 => { - self.0.exit_block(&BlockContext::__from_listener_node(context, self.1.as_deref())); - } - 60 => { - self.0.exit_ruleref(&RulerefContext::__from_listener_node(context, self.1.as_deref())); - } - 61 => { - self.0.exit_character_range(&CharacterRangeContext::__from_listener_node(context, self.1.as_deref())); - } - 62 => { - self.0.exit_terminal_def(&TerminalDefContext::__from_listener_node(context, self.1.as_deref())); - } - 63 => { - self.0.exit_element_options(&ElementOptionsContext::__from_listener_node(context, self.1.as_deref())); - } - 64 => { - self.0.exit_element_option(&ElementOptionContext::__from_listener_node(context, self.1.as_deref())); - } - 65 => { - self.0.exit_identifier(&IdentifierContext::__from_listener_node(context, self.1.as_deref())); - } - 66 => { - self.0.exit_qualified_identifier(&QualifiedIdentifierContext::__from_listener_node(context, self.1.as_deref())); - } - _ => {} - } - if let Some(invocation_states) = &mut self.1 { - invocation_states.remove(0); - } - Ok(()) + pub fn walk_with_invocation_states>( + listener: &mut T, + tree: antlr4_runtime::Node<'_>, + parent_invocation_states: Vec, + ) -> Result<(), E> { + Self::__walk(listener, tree, Some(parent_invocation_states)) } - fn visit_terminal(&mut self, node: RuntimeTerminalNode<'_>) -> Result<(), antlr4_runtime::AntlrError> { - self.0.visit_terminal(&TerminalNode::new(node)); - Ok(()) - } + fn __walk>( + listener: &mut T, + tree: antlr4_runtime::Node<'_>, + mut invocation_states: Option>, + ) -> Result<(), E> { + enum Event<'tree> { + Enter(antlr4_runtime::Node<'tree>), + Exit(RuleNodeView<'tree>), + } - fn visit_error_node(&mut self, node: RuntimeErrorNode<'_>) -> Result<(), antlr4_runtime::AntlrError> { - self.0.visit_error_node(&ErrorNode::new(node)); + let mut stack = vec![Event::Enter(tree)]; + while let Some(event) = stack.pop() { + match event { + Event::Enter(node) => match node.kind() { + antlr4_runtime::NodeKind::Rule => { + let context = node.as_rule().expect("rule node kind checked"); + if let Some(states) = &mut invocation_states { + states.insert(0, context.invoking_state()); + } + listener.enter_every_rule(context)?; + match __context_kind(context) { + 0 => listener.enter_grammar_spec(&GrammarSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 1 => listener.enter_grammar_decl(&GrammarDeclContext::__from_listener_node(context, invocation_states.as_deref()))?, + 2 => listener.enter_grammar_type(&GrammarTypeContext::__from_listener_node(context, invocation_states.as_deref()))?, + 3 => listener.enter_prequel_construct(&PrequelConstructContext::__from_listener_node(context, invocation_states.as_deref()))?, + 4 => listener.enter_options_spec(&OptionsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 5 => listener.enter_option(&OptionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 6 => listener.enter_option_value(&OptionValueContext::__from_listener_node(context, invocation_states.as_deref()))?, + 7 => listener.enter_delegate_grammars(&DelegateGrammarsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 8 => listener.enter_delegate_grammar(&DelegateGrammarContext::__from_listener_node(context, invocation_states.as_deref()))?, + 9 => listener.enter_tokens_spec(&TokensSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 10 => listener.enter_channels_spec(&ChannelsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 11 => listener.enter_id_list(&IdListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 12 => listener.enter_action(&ActionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 13 => listener.enter_action_scope_name(&ActionScopeNameContext::__from_listener_node(context, invocation_states.as_deref()))?, + 14 => listener.enter_action_block(&ActionBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 15 => listener.enter_arg_action_block(&ArgActionBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 16 => listener.enter_mode_spec(&ModeSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 17 => listener.enter_rules(&RulesContext::__from_listener_node(context, invocation_states.as_deref()))?, + 18 => listener.enter_rule_spec(&RuleSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 19 => listener.enter_parser_rule_spec(&ParserRuleSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 20 => listener.enter_exception_group(&ExceptionGroupContext::__from_listener_node(context, invocation_states.as_deref()))?, + 21 => listener.enter_exception_handler(&ExceptionHandlerContext::__from_listener_node(context, invocation_states.as_deref()))?, + 22 => listener.enter_finally_clause(&FinallyClauseContext::__from_listener_node(context, invocation_states.as_deref()))?, + 23 => listener.enter_rule_prequel(&RulePrequelContext::__from_listener_node(context, invocation_states.as_deref()))?, + 24 => listener.enter_rule_returns(&RuleReturnsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 25 => listener.enter_throws_spec(&ThrowsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 26 => listener.enter_locals_spec(&LocalsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 27 => listener.enter_rule_action(&RuleActionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 28 => listener.enter_rule_modifiers(&RuleModifiersContext::__from_listener_node(context, invocation_states.as_deref()))?, + 29 => listener.enter_rule_modifier(&RuleModifierContext::__from_listener_node(context, invocation_states.as_deref()))?, + 30 => listener.enter_rule_block(&RuleBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 31 => listener.enter_rule_alt_list(&RuleAltListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 32 => listener.enter_labeled_alt(&LabeledAltContext::__from_listener_node(context, invocation_states.as_deref()))?, + 33 => listener.enter_lexer_rule_spec(&LexerRuleSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 34 => listener.enter_lexer_rule_block(&LexerRuleBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 35 => listener.enter_lexer_alt_list(&LexerAltListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 36 => listener.enter_lexer_alt(&LexerAltContext::__from_listener_node(context, invocation_states.as_deref()))?, + 37 => listener.enter_lexer_elements(&LexerElementsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 38 => listener.enter_lexer_element(&LexerElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 39 => listener.enter_lexer_block(&LexerBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 40 => listener.enter_lexer_commands(&LexerCommandsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 41 => listener.enter_lexer_command(&LexerCommandContext::__from_listener_node(context, invocation_states.as_deref()))?, + 42 => listener.enter_lexer_command_name(&LexerCommandNameContext::__from_listener_node(context, invocation_states.as_deref()))?, + 43 => listener.enter_lexer_command_expr(&LexerCommandExprContext::__from_listener_node(context, invocation_states.as_deref()))?, + 44 => listener.enter_alt_list(&AltListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 45 => listener.enter_alternative(&AlternativeContext::__from_listener_node(context, invocation_states.as_deref()))?, + 46 => listener.enter_element(&ElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 47 => listener.enter_predicate_options(&PredicateOptionsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 48 => listener.enter_predicate_option(&PredicateOptionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 49 => listener.enter_labeled_element(&LabeledElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 50 => listener.enter_ebnf(&EbnfContext::__from_listener_node(context, invocation_states.as_deref()))?, + 51 => listener.enter_block_suffix(&BlockSuffixContext::__from_listener_node(context, invocation_states.as_deref()))?, + 52 => listener.enter_ebnf_suffix(&EbnfSuffixContext::__from_listener_node(context, invocation_states.as_deref()))?, + 53 => listener.enter_lexer_atom(&LexerAtomContext::__from_listener_node(context, invocation_states.as_deref()))?, + 54 => listener.enter_atom(&AtomContext::__from_listener_node(context, invocation_states.as_deref()))?, + 55 => listener.enter_wildcard(&WildcardContext::__from_listener_node(context, invocation_states.as_deref()))?, + 56 => listener.enter_not_set(&NotSetContext::__from_listener_node(context, invocation_states.as_deref()))?, + 57 => listener.enter_block_set(&BlockSetContext::__from_listener_node(context, invocation_states.as_deref()))?, + 58 => listener.enter_set_element(&SetElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 59 => listener.enter_block(&BlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 60 => listener.enter_ruleref(&RulerefContext::__from_listener_node(context, invocation_states.as_deref()))?, + 61 => listener.enter_character_range(&CharacterRangeContext::__from_listener_node(context, invocation_states.as_deref()))?, + 62 => listener.enter_terminal_def(&TerminalDefContext::__from_listener_node(context, invocation_states.as_deref()))?, + 63 => listener.enter_element_options(&ElementOptionsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 64 => listener.enter_element_option(&ElementOptionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 65 => listener.enter_identifier(&IdentifierContext::__from_listener_node(context, invocation_states.as_deref()))?, + 66 => listener.enter_qualified_identifier(&QualifiedIdentifierContext::__from_listener_node(context, invocation_states.as_deref()))?, + _ => {} + } + stack.push(Event::Exit(context)); + stack.extend(context.children().rev().map(Event::Enter)); + } + antlr4_runtime::NodeKind::Terminal => { + listener.visit_terminal(&TerminalNode::new( + node.as_terminal().expect("terminal node kind checked"), + ))?; + } + antlr4_runtime::NodeKind::Error => { + listener.visit_error_node(&ErrorNode::new( + node.as_error().expect("error node kind checked"), + ))?; + } + }, + Event::Exit(context) => { + match __context_kind(context) { + 0 => listener.exit_grammar_spec(&GrammarSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 1 => listener.exit_grammar_decl(&GrammarDeclContext::__from_listener_node(context, invocation_states.as_deref()))?, + 2 => listener.exit_grammar_type(&GrammarTypeContext::__from_listener_node(context, invocation_states.as_deref()))?, + 3 => listener.exit_prequel_construct(&PrequelConstructContext::__from_listener_node(context, invocation_states.as_deref()))?, + 4 => listener.exit_options_spec(&OptionsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 5 => listener.exit_option(&OptionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 6 => listener.exit_option_value(&OptionValueContext::__from_listener_node(context, invocation_states.as_deref()))?, + 7 => listener.exit_delegate_grammars(&DelegateGrammarsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 8 => listener.exit_delegate_grammar(&DelegateGrammarContext::__from_listener_node(context, invocation_states.as_deref()))?, + 9 => listener.exit_tokens_spec(&TokensSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 10 => listener.exit_channels_spec(&ChannelsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 11 => listener.exit_id_list(&IdListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 12 => listener.exit_action(&ActionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 13 => listener.exit_action_scope_name(&ActionScopeNameContext::__from_listener_node(context, invocation_states.as_deref()))?, + 14 => listener.exit_action_block(&ActionBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 15 => listener.exit_arg_action_block(&ArgActionBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 16 => listener.exit_mode_spec(&ModeSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 17 => listener.exit_rules(&RulesContext::__from_listener_node(context, invocation_states.as_deref()))?, + 18 => listener.exit_rule_spec(&RuleSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 19 => listener.exit_parser_rule_spec(&ParserRuleSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 20 => listener.exit_exception_group(&ExceptionGroupContext::__from_listener_node(context, invocation_states.as_deref()))?, + 21 => listener.exit_exception_handler(&ExceptionHandlerContext::__from_listener_node(context, invocation_states.as_deref()))?, + 22 => listener.exit_finally_clause(&FinallyClauseContext::__from_listener_node(context, invocation_states.as_deref()))?, + 23 => listener.exit_rule_prequel(&RulePrequelContext::__from_listener_node(context, invocation_states.as_deref()))?, + 24 => listener.exit_rule_returns(&RuleReturnsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 25 => listener.exit_throws_spec(&ThrowsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 26 => listener.exit_locals_spec(&LocalsSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 27 => listener.exit_rule_action(&RuleActionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 28 => listener.exit_rule_modifiers(&RuleModifiersContext::__from_listener_node(context, invocation_states.as_deref()))?, + 29 => listener.exit_rule_modifier(&RuleModifierContext::__from_listener_node(context, invocation_states.as_deref()))?, + 30 => listener.exit_rule_block(&RuleBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 31 => listener.exit_rule_alt_list(&RuleAltListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 32 => listener.exit_labeled_alt(&LabeledAltContext::__from_listener_node(context, invocation_states.as_deref()))?, + 33 => listener.exit_lexer_rule_spec(&LexerRuleSpecContext::__from_listener_node(context, invocation_states.as_deref()))?, + 34 => listener.exit_lexer_rule_block(&LexerRuleBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 35 => listener.exit_lexer_alt_list(&LexerAltListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 36 => listener.exit_lexer_alt(&LexerAltContext::__from_listener_node(context, invocation_states.as_deref()))?, + 37 => listener.exit_lexer_elements(&LexerElementsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 38 => listener.exit_lexer_element(&LexerElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 39 => listener.exit_lexer_block(&LexerBlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 40 => listener.exit_lexer_commands(&LexerCommandsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 41 => listener.exit_lexer_command(&LexerCommandContext::__from_listener_node(context, invocation_states.as_deref()))?, + 42 => listener.exit_lexer_command_name(&LexerCommandNameContext::__from_listener_node(context, invocation_states.as_deref()))?, + 43 => listener.exit_lexer_command_expr(&LexerCommandExprContext::__from_listener_node(context, invocation_states.as_deref()))?, + 44 => listener.exit_alt_list(&AltListContext::__from_listener_node(context, invocation_states.as_deref()))?, + 45 => listener.exit_alternative(&AlternativeContext::__from_listener_node(context, invocation_states.as_deref()))?, + 46 => listener.exit_element(&ElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 47 => listener.exit_predicate_options(&PredicateOptionsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 48 => listener.exit_predicate_option(&PredicateOptionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 49 => listener.exit_labeled_element(&LabeledElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 50 => listener.exit_ebnf(&EbnfContext::__from_listener_node(context, invocation_states.as_deref()))?, + 51 => listener.exit_block_suffix(&BlockSuffixContext::__from_listener_node(context, invocation_states.as_deref()))?, + 52 => listener.exit_ebnf_suffix(&EbnfSuffixContext::__from_listener_node(context, invocation_states.as_deref()))?, + 53 => listener.exit_lexer_atom(&LexerAtomContext::__from_listener_node(context, invocation_states.as_deref()))?, + 54 => listener.exit_atom(&AtomContext::__from_listener_node(context, invocation_states.as_deref()))?, + 55 => listener.exit_wildcard(&WildcardContext::__from_listener_node(context, invocation_states.as_deref()))?, + 56 => listener.exit_not_set(&NotSetContext::__from_listener_node(context, invocation_states.as_deref()))?, + 57 => listener.exit_block_set(&BlockSetContext::__from_listener_node(context, invocation_states.as_deref()))?, + 58 => listener.exit_set_element(&SetElementContext::__from_listener_node(context, invocation_states.as_deref()))?, + 59 => listener.exit_block(&BlockContext::__from_listener_node(context, invocation_states.as_deref()))?, + 60 => listener.exit_ruleref(&RulerefContext::__from_listener_node(context, invocation_states.as_deref()))?, + 61 => listener.exit_character_range(&CharacterRangeContext::__from_listener_node(context, invocation_states.as_deref()))?, + 62 => listener.exit_terminal_def(&TerminalDefContext::__from_listener_node(context, invocation_states.as_deref()))?, + 63 => listener.exit_element_options(&ElementOptionsContext::__from_listener_node(context, invocation_states.as_deref()))?, + 64 => listener.exit_element_option(&ElementOptionContext::__from_listener_node(context, invocation_states.as_deref()))?, + 65 => listener.exit_identifier(&IdentifierContext::__from_listener_node(context, invocation_states.as_deref()))?, + 66 => listener.exit_qualified_identifier(&QualifiedIdentifierContext::__from_listener_node(context, invocation_states.as_deref()))?, + _ => {} + } + listener.exit_every_rule(context)?; + if let Some(states) = &mut invocation_states { + states.remove(0); + } + } + } + } Ok(()) } } -#[allow(dead_code)] -pub struct ParseTreeWalker; - -#[allow(dead_code)] -impl ParseTreeWalker { - pub fn walk(listener: &mut T, tree: antlr4_runtime::Node<'_>) { - let mut bridge = __ListenerBridge(listener, None); - let _ = antlr4_runtime::ParseTreeWalker::walk(&mut bridge, tree); - } - - pub fn walk_with_invocation_states( - listener: &mut T, - tree: antlr4_runtime::Node<'_>, - parent_invocation_states: Vec, - ) { - let mut bridge = __ListenerBridge(listener, Some(parent_invocation_states)); - let _ = antlr4_runtime::ParseTreeWalker::walk(&mut bridge, tree); - } -} +pub type ParseTreeWalker = ANTLRv4TreeWalker; @@ -10280,7 +9515,7 @@ where self.base .parse_atn_rule_adaptive_or_fallback(atn(), simulator, rule_index) } else { - let (tree, actions) = self.base.parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence, antlr4_runtime::ParserRuntimeOptions { track_alt_numbers: false, predicates: &[], semantics: Some(parser_semantics()), rule_args: &[], member_actions: &[], return_actions: &[], unknown_predicate_policy: antlr4_runtime::UnknownSemanticPolicy::Error , ..antlr4_runtime::ParserRuntimeOptions::default() })?; + let (tree, actions) = self.base.parse_atn_rule_with_runtime_options_and_precedence(atn(), rule_index, precedence, antlr4_runtime::ParserRuntimeOptions { track_alt_numbers: false, track_context_alt_numbers: false, predicates: &[], semantics: Some(parser_semantics()), rule_args: &[], member_actions: &[], return_actions: &[], unknown_predicate_policy: antlr4_runtime::UnknownSemanticPolicy::Error , ..antlr4_runtime::ParserRuntimeOptions::default() })?; let _ = actions; Ok(tree) } diff --git a/src/lib.rs b/src/lib.rs index edafd41d..3d9f110f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,9 +44,10 @@ pub use token::{ }; pub use token_stream::CommonTokenStream; pub use tree::{ - ErrorNodeView, FromRuleNode, GeneratedAttrs, Node, NodeChildren, NodeId, NodeKind, ParseTree, - ParseTreeDescendants, ParseTreeListener, ParseTreeStats, ParseTreeStorage, ParseTreeWalker, - ParsedFile, ParserRuleContext, RuleNodeView, TerminalNodeView, + AsRuleNode, ErrorNodeView, FromRuleNode, GeneratedAttrs, MissingChildError, Node, NodeChildren, + NodeId, NodeKind, ParseTree, ParseTreeDescendants, ParseTreeListener, ParseTreeStats, + ParseTreeStorage, ParseTreeVisitor, ParseTreeWalker, ParsedFile, ParserRuleContext, + RuleNodeView, TerminalNodeView, }; pub use vocabulary::Vocabulary; diff --git a/src/parser.rs b/src/parser.rs index 7569700c..e9a22193 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1067,6 +1067,12 @@ pub struct ParserRuntimeOptions<'a> { pub init_action_rules: &'a [usize], /// Whether generated parse-tree contexts should retain alternative numbers. pub track_alt_numbers: bool, + /// Whether generated typed contexts should retain private dispatch alternatives. + /// + /// Unlike `track_alt_numbers`, this metadata does not affect the public + /// alternative number or parse-tree rendering. + #[doc(hidden)] + pub track_context_alt_numbers: bool, /// Semantic predicate table keyed by serialized `(rule_index, pred_index)`. pub predicates: &'a [(usize, usize, ParserPredicate)], /// `SemIR` predicate/action table emitted by newer generated parsers. @@ -1490,6 +1496,7 @@ enum ArenaRecognizedNode { /// public rule entry hands the tree to the caller. LeftRecursiveBoundary { rule_index: u32, + alt_number: u32, }, } @@ -1901,9 +1908,15 @@ impl RecognitionArena { }) .then_with(|| self.compare_sequences(left_children, right_children)), ( - ArenaRecognizedNode::LeftRecursiveBoundary { rule_index: left }, - ArenaRecognizedNode::LeftRecursiveBoundary { rule_index: right }, - ) => left.cmp(&right), + ArenaRecognizedNode::LeftRecursiveBoundary { + rule_index: left_rule, + alt_number: left_alt, + }, + ArenaRecognizedNode::LeftRecursiveBoundary { + rule_index: right_rule, + alt_number: right_alt, + }, + ) => (left_rule, left_alt).cmp(&(right_rule, right_alt)), (left, right) => recognition_node_kind(&left).cmp(&recognition_node_kind(&right)), } } @@ -1924,7 +1937,10 @@ impl RecognitionArena { let mut reversed = NodeSeqId::EMPTY; while let Some(link) = self.link(sequence) { match self.node(link.head) { - ArenaRecognizedNode::LeftRecursiveBoundary { rule_index } => { + ArenaRecognizedNode::LeftRecursiveBoundary { + rule_index, + alt_number, + } => { if !reversed.is_empty() { let children = self.reverse_sequence(reversed); let start_index = self.sequence_start_index(children).unwrap_or_default(); @@ -1932,7 +1948,7 @@ impl RecognitionArena { let rule = self.push_node(ArenaRecognizedNode::Rule { rule_index, invoking_state: -1, - alt_number: 0, + alt_number, start_index: u32::try_from(start_index) .expect("left-recursive start index fits in u32"), stop_index: stop_index.map(|index| { @@ -3946,6 +3962,7 @@ fn atn_has_predicate_transitions(atn: &Atn) -> bool { fn can_use_fast_predicate_recognizer(atn: &Atn, options: &ParserRuntimeOptions<'_>) -> bool { options.init_action_rules.is_empty() && !options.track_alt_numbers + && !options.track_context_alt_numbers && options .predicates .iter() @@ -6745,7 +6762,7 @@ where { let mut cursor = live_root; while let Some(link) = self.recognition_arena.link(cursor) { - let child = self.arena_recognized_node_tree(link.head, false)?; + let child = self.arena_recognized_node_tree(link.head, false, false)?; self.tree.add_child(&mut context, child); cursor = link.tail; } @@ -6867,6 +6884,7 @@ where &mut self, node_id: RecognizedNodeId, track_alt_numbers: bool, + track_context_alt_numbers: bool, ) -> Result { let node = self.recognition_arena.node(node_id); match node { @@ -6906,6 +6924,9 @@ where if track_alt_numbers { context.set_alt_number(alt_number as usize); } + if track_context_alt_numbers { + context.set_context_alt_number(alt_number as usize); + } if let Some(extra) = return_values { let RecognitionExtra::ReturnValues(values) = self.recognition_arena.extra(extra) @@ -6926,13 +6947,17 @@ where .recognition_arena .fold_left_recursive_boundaries(children); while let Some(link) = self.recognition_arena.link(cursor) { - let child = self.arena_recognized_node_tree(link.head, track_alt_numbers)?; + let child = self.arena_recognized_node_tree( + link.head, + track_alt_numbers, + track_context_alt_numbers, + )?; self.tree.add_child(&mut context, child); cursor = link.tail; } Ok(self.rule_node(context)) } - ArenaRecognizedNode::LeftRecursiveBoundary { rule_index } => { + ArenaRecognizedNode::LeftRecursiveBoundary { rule_index, .. } => { Err(AntlrError::Unsupported(format!( "unfolded left-recursive boundary for rule {rule_index}" ))) @@ -6976,7 +7001,7 @@ where )?; Ok(self.rule_node(context)) } - _ => self.arena_recognized_node_tree(node_id, false), + _ => self.arena_recognized_node_tree(node_id, false, false), } } @@ -7136,6 +7161,7 @@ where let ParserRuntimeOptions { init_action_rules, track_alt_numbers, + track_context_alt_numbers, predicates, semantics, rule_args, @@ -7143,8 +7169,9 @@ where return_actions, unknown_predicate_policy, } = options; + let capture_alt_numbers = track_alt_numbers || track_context_alt_numbers; if init_action_rules.is_empty() - && !track_alt_numbers + && !capture_alt_numbers && predicates.is_empty() && semantics.is_none() && rule_args.is_empty() @@ -7234,7 +7261,7 @@ where member_values, return_values, rule_alt_number: 0, - track_alt_numbers, + track_alt_numbers: capture_alt_numbers, consumed_eof: false, committed_decision: false, precedence, @@ -7286,6 +7313,9 @@ where if track_alt_numbers { context.set_alt_number(outcome.alt_number); } + if track_context_alt_numbers { + context.set_context_alt_number(outcome.alt_number); + } for (name, value) in outcome.return_values { context.set_int_return(name, value); } @@ -7304,7 +7334,11 @@ where if self.build_parse_trees { let mut nodes = live_root; while let Some(link) = self.recognition_arena.link(nodes) { - let child = self.arena_recognized_node_tree(link.head, track_alt_numbers)?; + let child = self.arena_recognized_node_tree( + link.head, + track_alt_numbers, + track_context_alt_numbers, + )?; self.tree.add_child(&mut context, child); nodes = link.tail; } @@ -8582,7 +8616,7 @@ where .into_iter() .map(|mut outcome| { if let Some(rule_index) = boundary { - let boundary = self.arena_boundary_node(rule_index); + let boundary = self.arena_boundary_node(rule_index, 0); self.defer_fast_outcome_node(&mut outcome, boundary); } outcome @@ -8619,7 +8653,7 @@ where .into_iter() .map(|mut outcome| { if let Some(rule_index) = boundary { - let boundary = self.arena_boundary_node(rule_index); + let boundary = self.arena_boundary_node(rule_index, 0); self.defer_fast_outcome_node(&mut outcome, boundary); } outcome @@ -8658,7 +8692,7 @@ where .into_iter() .map(|mut outcome| { if let Some(rule_index) = boundary { - let boundary = self.arena_boundary_node(rule_index); + let boundary = self.arena_boundary_node(rule_index, 0); self.defer_fast_outcome_node(&mut outcome, boundary); } outcome @@ -9583,7 +9617,8 @@ where .map(|mut outcome| { prepend_decision(&mut outcome, decision); if let Some(rule_index) = left_recursive_boundary { - let boundary = self.arena_boundary_node(rule_index); + let boundary = + self.arena_boundary_node(rule_index, next_alt_number); self.arena_prepend(&mut outcome.nodes, boundary); } outcome @@ -10043,7 +10078,7 @@ where .map(|mut outcome| { prepend_decision(&mut outcome, step.decision); if let Some(rule_index) = step.left_recursive_boundary { - let boundary = self.arena_boundary_node(rule_index); + let boundary = self.arena_boundary_node(rule_index, step.alt_number); self.arena_prepend(&mut outcome.nodes, boundary); } if let Some(action) = action { @@ -10439,10 +10474,11 @@ where }) } - fn arena_boundary_node(&mut self, rule_index: usize) -> RecognizedNodeId { + fn arena_boundary_node(&mut self, rule_index: usize, alt_number: usize) -> RecognizedNodeId { self.recognition_arena .push_node(ArenaRecognizedNode::LeftRecursiveBoundary { rule_index: u32::try_from(rule_index).expect("rule index fits in u32"), + alt_number: u32::try_from(alt_number).expect("alternative number fits in u32"), }) } @@ -17550,8 +17586,10 @@ mod tests { let first = arena.push_node(ArenaRecognizedNode::Token { token: TokenId::try_from(0).expect("test token ID"), }); - let boundary = - arena.push_node(ArenaRecognizedNode::LeftRecursiveBoundary { rule_index: 1 }); + let boundary = arena.push_node(ArenaRecognizedNode::LeftRecursiveBoundary { + rule_index: 1, + alt_number: 3, + }); let second = arena.push_node(ArenaRecognizedNode::Token { token: TokenId::try_from(1).expect("test token ID"), }); @@ -17567,6 +17605,7 @@ mod tests { let ArenaRecognizedNode::Rule { rule_index, invoking_state, + alt_number, start_index, stop_index, children, @@ -17577,6 +17616,7 @@ mod tests { }; assert_eq!(rule_index, 1); assert_eq!(invoking_state, -1); + assert_eq!(alt_number, 3); assert_eq!(start_index, 0); assert_eq!(stop_index, Some(0)); assert_eq!(arena.iter(children).collect::>(), [first]); diff --git a/src/tree.rs b/src/tree.rs index b09ef76c..80a88dc3 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -10,6 +10,8 @@ const NONE: u32 = u32::MAX; const FLAG_MATCHED_CHILD: u8 = 1 << 0; const FLAG_START_PRESENT: u8 = 1 << 1; const FLAG_STOP_PRESENT: u8 = 1 << 2; +const VISITOR_STACK_RED_ZONE: usize = 1024 * 1024; +const VISITOR_STACK_SIZE: usize = 4 * 1024 * 1024; #[repr(transparent)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -70,6 +72,7 @@ pub struct ParseTreeStorage { starts: Vec, stops: Vec, alt_numbers: Vec, + context_alt_numbers: Vec, extra_ids: Vec, parents: Vec, flags: Vec, @@ -107,6 +110,7 @@ impl ParseTreeStorage { starts: Vec::new(), stops: Vec::new(), alt_numbers: Vec::new(), + context_alt_numbers: Vec::new(), extra_ids: Vec::new(), parents: Vec::new(), flags: Vec::new(), @@ -146,6 +150,7 @@ impl ParseTreeStorage { + self.starts.capacity() * size_of::() + self.stops.capacity() * size_of::() + self.alt_numbers.capacity() * size_of::() + + self.context_alt_numbers.capacity() * size_of::() + self.extra_ids.capacity() * size_of::() + self.parents.capacity() * size_of::() + self.flags.capacity() * size_of::() @@ -164,6 +169,7 @@ impl ParseTreeStorage { self.starts.clear(); self.stops.clear(); self.alt_numbers.clear(); + self.context_alt_numbers.clear(); self.extra_ids.clear(); self.parents.clear(); self.flags.clear(); @@ -198,6 +204,7 @@ impl ParseTreeStorage { self.starts.truncate(checkpoint.nodes); self.stops.truncate(checkpoint.nodes); self.alt_numbers.truncate(checkpoint.nodes); + self.context_alt_numbers.truncate(checkpoint.nodes); self.extra_ids.truncate(checkpoint.nodes); self.parents.truncate(checkpoint.nodes); self.flags.truncate(checkpoint.nodes); @@ -278,6 +285,8 @@ impl ParseTreeStorage { start: context.start.map_or(NONE, |token| token.index() as u32), stop: context.stop.map_or(NONE, |token| token.index() as u32), alt_number: u32::try_from(context.alt_number).expect("alternative number exceeds u32"), + context_alt_number: u32::try_from(context.context_alt_number) + .expect("context alternative number exceeds u32"), extra_id, flags: (u8::from(context.matched_child) * FLAG_MATCHED_CHILD) | (u8::from(context.start.is_some()) * FLAG_START_PRESENT) @@ -295,6 +304,16 @@ impl ParseTreeStorage { self.starts.push(record.start); self.stops.push(record.stop); self.alt_numbers.push(record.alt_number); + if record.context_alt_number == 0 { + if !self.context_alt_numbers.is_empty() { + self.context_alt_numbers.push(0); + } + } else { + if self.context_alt_numbers.is_empty() { + self.context_alt_numbers.resize(id.index(), 0); + } + self.context_alt_numbers.push(record.context_alt_number); + } self.extra_ids.push(record.extra_id); self.parents.push(NONE); self.flags.push(record.flags); @@ -362,6 +381,7 @@ struct NodeRecord { start: u32, stop: u32, alt_number: u32, + context_alt_number: u32, extra_id: u32, flags: u8, } @@ -377,6 +397,7 @@ impl Default for NodeRecord { start: NONE, stop: NONE, alt_number: 0, + context_alt_number: 0, extra_id: NONE, flags: 0, } @@ -671,6 +692,17 @@ impl<'tree> RuleNodeView<'tree> { self.node.storage.alt_numbers[self.node.id.index()] as usize } + #[doc(hidden)] + #[must_use] + pub fn context_alt_number(self) -> usize { + self.node + .storage + .context_alt_numbers + .get(self.node.id.index()) + .copied() + .unwrap_or_default() as usize + } + #[must_use] pub fn start(self) -> Option> { self.start_id().and_then(|id| self.node.tokens.view(id)) @@ -935,6 +967,7 @@ pub struct ParserRuleContext { rule_index: usize, invoking_state: isize, alt_number: usize, + context_alt_number: usize, start: Option, stop: Option, int_returns: BTreeMap, @@ -953,6 +986,7 @@ impl ParserRuleContext { rule_index, invoking_state, alt_number: 0, + context_alt_number: 0, start: None, stop: None, int_returns: BTreeMap::new(), @@ -992,6 +1026,17 @@ impl ParserRuleContext { self.alt_number = alt_number; } + #[doc(hidden)] + #[must_use] + pub const fn context_alt_number(&self) -> usize { + self.context_alt_number + } + + #[doc(hidden)] + pub const fn set_context_alt_number(&mut self, alt_number: usize) { + self.context_alt_number = alt_number; + } + pub fn start<'a>(&self, tokens: &'a TokenStore) -> Option> { self.start.and_then(|id| tokens.view(id)) } @@ -1190,6 +1235,53 @@ pub trait FromRuleNode<'tree>: Sized { fn from_rule_node(node: RuleNodeView<'tree>) -> Option; } +/// Exposes the stored rule node behind a completed generated context. +pub trait AsRuleNode<'tree> { + fn as_rule_node(&self) -> RuleNodeView<'tree>; +} + +impl<'tree> AsRuleNode<'tree> for RuleNodeView<'tree> { + fn as_rule_node(&self) -> Self { + *self + } +} + +/// A required grammar child was absent from a recovered parse tree. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct MissingChildError { + context: &'static str, + child: &'static str, +} + +impl MissingChildError { + #[must_use] + pub const fn new(context: &'static str, child: &'static str) -> Self { + Self { context, child } + } + + #[must_use] + pub const fn context(self) -> &'static str { + self.context + } + + #[must_use] + pub const fn child(self) -> &'static str { + self.child + } +} + +impl fmt::Display for MissingChildError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "required child {} is missing from {}", + self.child, self.context + ) + } +} + +impl std::error::Error for MissingChildError {} + pub trait ParseTreeListener { fn enter_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), AntlrError> { Ok(()) @@ -1208,6 +1300,71 @@ pub trait ParseTreeListener { } } +/// Value-returning, caller-directed traversal over a completed parse tree. +/// +/// Generated grammar visitors adapt typed rule and alternative callbacks to +/// this runtime contract. The default traversal returns the latest child's +/// result, matching ANTLR's base visitor behavior. +pub trait ParseTreeVisitor { + type Result; + + fn default_result(&mut self) -> Self::Result; + + fn visit(&mut self, tree: Node<'_>) -> Self::Result { + match tree.kind() { + NodeKind::Rule => self.visit_rule(tree.as_rule().expect("rule node kind checked")), + NodeKind::Terminal => { + self.visit_terminal(tree.as_terminal().expect("terminal node kind checked")) + } + NodeKind::Error => { + self.visit_error_node(tree.as_error().expect("error node kind checked")) + } + } + } + + fn visit_rule(&mut self, node: RuleNodeView<'_>) -> Self::Result { + self.visit_children(node) + } + + fn visit_children(&mut self, node: RuleNodeView<'_>) -> Self::Result { + stacker::maybe_grow(VISITOR_STACK_RED_ZONE, VISITOR_STACK_SIZE, || { + let mut result = self.default_result(); + for child in node.children() { + if !self.should_visit_next_child(node, &result) { + break; + } + let child_result = self.visit(child); + result = self.aggregate_result(result, child_result); + } + result + }) + } + + fn visit_terminal(&mut self, _node: TerminalNodeView<'_>) -> Self::Result { + self.default_result() + } + + fn visit_error_node(&mut self, _node: ErrorNodeView<'_>) -> Self::Result { + self.default_result() + } + + fn aggregate_result( + &mut self, + _aggregate: Self::Result, + next_result: Self::Result, + ) -> Self::Result { + next_result + } + + fn should_visit_next_child( + &mut self, + _node: RuleNodeView<'_>, + _current_result: &Self::Result, + ) -> bool { + true + } +} + #[derive(Debug, Default)] pub struct ParseTreeWalker; @@ -1363,6 +1520,28 @@ mod tests { ); } + #[test] + fn context_alt_number_does_not_change_public_tree_rendering() { + let tokens = TokenStore::new(None, ""); + let mut storage = ParseTreeStorage::new(); + let mut context = ParserRuleContext::new(0, -1); + context.set_context_alt_number(2); + + assert_eq!(context.alt_number(), 0); + assert_eq!(context.context_alt_number(), 2); + assert_eq!( + context.to_string_tree_with_names(&storage, &tokens, &["root"]), + "root" + ); + + let root = storage.finish_rule(context); + let parsed = ParsedFile::new(tokens, storage, root); + let rule = parsed.tree().as_rule().expect("root rule"); + assert_eq!(rule.alt_number(), 0); + assert_eq!(rule.context_alt_number(), 2); + assert_eq!(parsed.tree().to_string_tree_with_names(&["root"]), "root"); + } + #[test] fn descendants_and_walker_preserve_antlr_order() { let mut tokens = TokenStore::new(None, ""); @@ -1426,6 +1605,190 @@ mod tests { assert_eq!(listener.0, ["enter0", "a", "enter1", "b", "exit1", "exit0"]); } + fn visitor_test_tree() -> ParsedFile { + let mut tokens = TokenStore::new(None, ""); + let a = token(&mut tokens, 1, "a"); + let b = token(&mut tokens, 2, "b"); + let error = token(&mut tokens, 3, "!"); + let mut storage = ParseTreeStorage::new(); + let a = storage.terminal(a); + let b = storage.terminal(b); + let error = storage.error(error); + let mut child = ParserRuleContext::new(1, 7); + storage.add_child(&mut child, b); + let child = storage.finish_rule(child); + let mut root = ParserRuleContext::new(0, -1); + storage.add_child(&mut root, a); + storage.add_child(&mut root, child); + storage.add_child(&mut root, error); + let root = storage.finish_rule(root); + ParsedFile::new(tokens, storage, root) + } + + #[test] + fn visitor_dispatches_and_aggregates_all_node_kinds() { + #[derive(Default)] + struct Visitor(Vec); + + impl ParseTreeVisitor for Visitor { + type Result = Vec; + + fn default_result(&mut self) -> Self::Result { + Vec::new() + } + + fn visit_rule(&mut self, node: RuleNodeView<'_>) -> Self::Result { + self.0.push(format!("rule{}", node.rule_index())); + self.visit_children(node) + } + + fn visit_terminal(&mut self, node: TerminalNodeView<'_>) -> Self::Result { + vec![format!("terminal:{}", node.text())] + } + + fn visit_error_node(&mut self, node: ErrorNodeView<'_>) -> Self::Result { + vec![format!("error:{}", node.text())] + } + + fn aggregate_result( + &mut self, + mut aggregate: Self::Result, + next_result: Self::Result, + ) -> Self::Result { + aggregate.extend(next_result); + aggregate + } + } + + let parsed = visitor_test_tree(); + let mut visitor = Visitor::default(); + assert_eq!( + visitor.visit(parsed.tree()), + ["terminal:a", "terminal:b", "error:!"] + ); + assert_eq!(visitor.0, ["rule0", "rule1"]); + } + + #[test] + fn visitor_default_aggregation_returns_the_latest_child() { + struct Visitor; + + impl ParseTreeVisitor for Visitor { + type Result = String; + + fn default_result(&mut self) -> Self::Result { + String::new() + } + + fn visit_terminal(&mut self, node: TerminalNodeView<'_>) -> Self::Result { + node.text().to_owned() + } + + fn visit_error_node(&mut self, node: ErrorNodeView<'_>) -> Self::Result { + node.text().to_owned() + } + } + + let parsed = visitor_test_tree(); + assert_eq!(Visitor.visit(parsed.tree()), "!"); + } + + #[test] + fn visitor_can_short_circuit_before_any_or_later_children() { + struct Visitor { + limit: usize, + visited: usize, + } + + impl ParseTreeVisitor for Visitor { + type Result = usize; + + fn default_result(&mut self) -> Self::Result { + 0 + } + + fn visit_terminal(&mut self, _node: TerminalNodeView<'_>) -> Self::Result { + self.visited += 1; + 1 + } + + fn visit_error_node(&mut self, _node: ErrorNodeView<'_>) -> Self::Result { + self.visited += 1; + 1 + } + + fn aggregate_result( + &mut self, + aggregate: Self::Result, + next_result: Self::Result, + ) -> Self::Result { + aggregate + next_result + } + + fn should_visit_next_child( + &mut self, + _node: RuleNodeView<'_>, + current_result: &Self::Result, + ) -> bool { + *current_result < self.limit + } + } + + let parsed = visitor_test_tree(); + let mut none = Visitor { + limit: 0, + visited: 0, + }; + assert_eq!(none.visit(parsed.tree()), 0); + assert_eq!(none.visited, 0); + + let mut one = Visitor { + limit: 1, + visited: 0, + }; + assert_eq!(one.visit(parsed.tree()), 1); + assert_eq!(one.visited, 1); + } + + #[test] + fn visitor_grows_the_stack_for_deep_rule_trees() { + const DEPTH: usize = 20_000; + const STACK_SIZE: usize = 256 * 1024; + + std::thread::Builder::new() + .name("visitor-stack-growth".to_owned()) + .stack_size(STACK_SIZE) + .spawn(|| { + let tokens = TokenStore::new(None, ""); + let mut storage = ParseTreeStorage::new(); + let mut child = storage.finish_rule(ParserRuleContext::new(DEPTH, -1)); + for rule_index in (0..DEPTH).rev() { + let mut parent = ParserRuleContext::new(rule_index, -1); + storage.add_child(&mut parent, child); + child = storage.finish_rule(parent); + } + let parsed = ParsedFile::new(tokens, storage, child); + + struct Visitor; + impl ParseTreeVisitor for Visitor { + type Result = usize; + + fn default_result(&mut self) -> Self::Result { + 0 + } + + fn visit_rule(&mut self, node: RuleNodeView<'_>) -> Self::Result { + self.visit_children(node) + 1 + } + } + + assert_eq!(Visitor.visit(parsed.tree()), DEPTH + 1); + }) + .expect("small-stack thread should start") + .join() + .expect("visitor should not overflow its stack"); + } + #[test] fn invocation_states_exclude_a_nonnegative_root_frame() { let tokens = TokenStore::new(None, ""); diff --git a/tests/antlr4_rust_gen_cli.rs b/tests/antlr4_rust_gen_cli.rs index 896dbb04..70cd8bf8 100644 --- a/tests/antlr4_rust_gen_cli.rs +++ b/tests/antlr4_rust_gen_cli.rs @@ -12,6 +12,10 @@ fn run_antlr4_rust_gen(args: &[impl AsRef]) -> Output { } fn assert_generated_modules_compile(temp_dir: &Path, modules: &[&str]) { + assert_generated_project(temp_dir, modules, ""); +} + +fn assert_generated_project(temp_dir: &Path, modules: &[&str], test_source: &str) { let project = temp_dir.join("compile-generated"); let source = project.join("src"); fs::create_dir_all(&source).expect("generated-module check should be writable"); @@ -37,8 +41,11 @@ fn assert_generated_modules_compile(temp_dir: &Path, modules: &[&str]) { }) .collect::>() .join("\n"); - fs::write(source.join("lib.rs"), declarations) - .expect("generated-module crate root should be writable"); + fs::write( + source.join("lib.rs"), + format!("{declarations}\n{test_source}"), + ) + .expect("generated-module crate root should be writable"); for module in modules { fs::copy(temp_dir.join("generated").join(module), source.join(module)) .expect("generated module should be copied into the check crate"); @@ -46,7 +53,11 @@ fn assert_generated_modules_compile(temp_dir: &Path, modules: &[&str]) { let output = Command::new(env!("CARGO")) .args([ - "check", + if test_source.is_empty() { + "check" + } else { + "test" + }, "--quiet", "--offline", "--manifest-path", @@ -60,7 +71,7 @@ fn assert_generated_modules_compile(temp_dir: &Path, modules: &[&str]) { .expect("cargo check should run"); assert!( output.status.success(), - "generated modules did not compile\nstdout: {}\nstderr: {}", + "generated project failed\nstdout: {}\nstderr: {}", utf8(&output.stdout), utf8(&output.stderr) ); @@ -116,6 +127,10 @@ fn long_help_describes_source_only_cli() { ); assert!(stdout.contains(" -I, --lib DIR"), "{stdout}"); assert!(stdout.contains(" --option-hook KEY=VALUE"), "{stdout}"); + assert!(stdout.contains(" -listener, --listener"), "{stdout}"); + assert!(stdout.contains(" -no-listener, --no-listener"), "{stdout}"); + assert!(stdout.contains(" -visitor, --visitor"), "{stdout}"); + assert!(stdout.contains(" -no-visitor, --no-visitor"), "{stdout}"); assert!(!stdout.contains("--lexer "), "{stdout}"); assert!(!stdout.contains("--parser "), "{stdout}"); assert!(!stdout.contains("--grammar "), "{stdout}"); @@ -245,20 +260,461 @@ fn combined_root_suffixes_alternative_contexts_and_listener_methods() { let parser = fs::read_to_string(out.join("shapes_parser.rs")).expect("parser should be emitted"); for expected in [ - "pub struct StartContext<'a>", - "pub struct SingleLabelContext<'a>", - "pub struct ManyLabelContext<'a>", - "pub trait ShapesListener", + "pub struct StartContext<'a, State = StoredTreeContext>", + "pub struct SingleLabelContext<'a, State = StoredTreeContext>", + "pub struct ManyLabelContext<'a, State = StoredTreeContext>", + "pub trait ShapesListener", + "pub struct ShapesTreeWalker", + "pub type ParseTreeWalker = ShapesTreeWalker", + "fn enter_every_rule(&mut self", "fn enter_single_label(&mut self", "fn enter_many_label(&mut self", + "pub fn atom_children(&self) -> impl Iterator>", + "pub fn first(&self) -> Result, MissingChildError>", + "pub fn rest(&self) -> impl Iterator>", + "pub fn value(&self) -> Result, MissingChildError>", ] { assert!(parser.contains(expected), "missing {expected:?}\n{parser}"); } + assert!( + !parser.contains("_all(&self)"), + "generated contexts must not expose allocating Java-style list accessors\n{parser}" + ); assert!( !parser.contains("antlr4_runtime::{{"), "generated imports must not contain redundant nested braces\n{parser}" ); - assert_generated_modules_compile(temp.path(), &["shapes_lexer.rs", "shapes_parser.rs"]); + assert!( + !parser.contains("pub trait ShapesVisitor"), + "visitor generation must remain opt-in\n{parser}" + ); + assert_generated_project( + temp.path(), + &["shapes_lexer.rs", "shapes_parser.rs"], + r#" +#[cfg(test)] +mod typed_label_tests { + use super::shapes_lexer::ShapesLexer; + use super::shapes_parser::*; + use antlr4_runtime::{CommonTokenStream, InputStream, Parser as _}; + + #[test] + fn list_and_repeated_single_labels_keep_antlr_semantics() { + let lexer = ShapesLexer::new(InputStream::new("a,b,c")); + let tokens = CommonTokenStream::new(lexer); + let mut parser = ShapesParser::new(tokens); + let root = parser.start().expect("list input should parse"); + assert_eq!(parser.number_of_syntax_errors(), 0); + let parsed = parser.into_parsed_file(root); + let many = parsed + .tree() + .as_rule() + .expect("start rule") + .downcast_ref::() + .expect("comma-separated input uses the many alternative"); + assert_eq!( + many + .rest() + .map(|atom| atom.rule_node().node().text()) + .collect::>(), + ["a", "b", "c"] + ); + + let lexer = ShapesLexer::new(InputStream::new("a b c")); + let tokens = CommonTokenStream::new(lexer); + let mut parser = ShapesParser::new(tokens); + let root = parser.latest().expect("repeated input should parse"); + assert_eq!(parser.number_of_syntax_errors(), 0); + let parsed = parser.into_parsed_file(root); + let latest = parsed + .tree() + .as_rule() + .expect("latest rule") + .downcast_ref::() + .expect("latest context"); + assert_eq!(latest.atom_children().count(), 3); + assert_eq!( + latest + .value() + .expect("one or more atoms guarantees a value") + .rule_node() + .node() + .text(), + "c" + ); + } +} +"#, + ); +} + +#[test] +fn visitor_and_typed_walk_dispatch_labeled_left_recursion() { + let temp = temporary_directory("typed-tree-walkers"); + let grammar = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests/fixtures/antlr4-rust-gen/typed-tree-walkers/Calculator.g4"); + let out = temp.path().join("generated"); + + let output = run_antlr4_rust_gen(&[ + grammar.as_os_str(), + OsStr::new("--visitor"), + OsStr::new("--out-dir"), + out.as_os_str(), + ]); + assert!( + output.status.success(), + "stdout: {}\nstderr: {}", + utf8(&output.stdout), + utf8(&output.stderr) + ); + let parser = + fs::read_to_string(out.join("calculator_parser.rs")).expect("parser should be emitted"); + for expected in [ + "pub trait CalculatorVisitor", + "pub trait CalculatorVisitable", + "pub trait CalculatorListener", + "pub struct CalculatorTreeWalker", + "fn visit_multiply_label(&mut self", + "fn visit_add_label(&mut self", + "fn visit_number_label(&mut self", + "fn default_result(&mut self) -> Self::Result;", + "pub trait CalculatorListener", + "pub fn expression_children(&self) -> impl Iterator>", + "pub fn left(&self) -> Result, MissingChildError>", + "pub fn right(&self) -> Result, MissingChildError>", + "pub fn star_token(&self) -> Option>", + "pub fn int_token(&self) -> Result, MissingChildError>", + "pub fn eof_token(&self) -> Result, MissingChildError>", + "pub fn literal(&self) -> Result, MissingChildError>", + "pub fn choice(&self) -> Result, MissingChildError>", + "pub fn other(&self) -> Result, MissingChildError>", + "pub fn wildcard(&self) -> Result, MissingChildError>", + "pub fn plus_token(&self) -> Result, MissingChildError>", + "pub fn star_token(&self) -> Result, MissingChildError>", + "__token_children_matching(self.__node", + "track_context_alt_numbers: true", + ] { + assert!(parser.contains(expected), "missing {expected:?}\n{parser}"); + } + assert!( + !parser.contains("pub fn INT(") && !parser.contains("_all(&self)"), + "generated contexts must expose Rust-shaped token and collection accessors\n{parser}" + ); + + assert_generated_project( + temp.path(), + &["calculator_lexer.rs", "calculator_parser.rs"], + r#" +#[cfg(test)] +mod typed_tree_tests { + use super::calculator_lexer::CalculatorLexer; + use super::calculator_parser::*; + use antlr4_runtime::{ + CommonTokenStream, InputStream, MissingChildError, Parser as _, RuleNodeView, + }; + + struct Eval; + + impl CalculatorVisitor for Eval { + type Result = Result; + + fn default_result(&mut self) -> Self::Result { + Ok(0) + } + + fn visit_start(&mut self, ctx: &StartContext) -> Self::Result { + self.visit(ctx.expression()?) + } + + fn visit_number_label(&mut self, ctx: &NumberLabelContext) -> Self::Result { + Ok(ctx + .int_token()? + .to_string() + .parse() + .expect("integer token")) + } + + fn visit_multiply_label(&mut self, ctx: &MultiplyLabelContext) -> Self::Result { + let left = self.visit(ctx.left()?)?; + let right = self.visit(ctx.right()?)?; + if ctx.star_token().is_some() { + Ok(left * right) + } else { + Ok(left / right) + } + } + + fn visit_add_label(&mut self, ctx: &AddLabelContext) -> Self::Result { + let left = self.visit(ctx.left()?)?; + let right = self.visit(ctx.right()?)?; + if ctx.plus_token().is_some() { + Ok(left + right) + } else { + Ok(left - right) + } + } + } + + #[derive(Default)] + struct Trace { + events: Vec<&'static str>, + entered_rules: usize, + exited_rules: usize, + } + + #[derive(Debug, Eq, PartialEq)] + struct TraceError; + + impl CalculatorListener for Trace { + fn enter_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), TraceError> { + self.entered_rules += 1; + Ok(()) + } + + fn exit_every_rule(&mut self, _ctx: RuleNodeView<'_>) -> Result<(), TraceError> { + self.exited_rules += 1; + Ok(()) + } + + fn enter_multiply_label( + &mut self, + _ctx: &MultiplyLabelContext, + ) -> Result<(), TraceError> { + self.events.push("enter:multiply"); + Ok(()) + } + + fn exit_multiply_label( + &mut self, + _ctx: &MultiplyLabelContext, + ) -> Result<(), TraceError> { + self.events.push("exit:multiply"); + Ok(()) + } + + fn enter_add_label(&mut self, _ctx: &AddLabelContext) -> Result<(), TraceError> { + self.events.push("enter:add"); + Ok(()) + } + + fn exit_add_label(&mut self, _ctx: &AddLabelContext) -> Result<(), TraceError> { + self.events.push("exit:add"); + Ok(()) + } + + fn enter_number_label( + &mut self, + _ctx: &NumberLabelContext, + ) -> Result<(), TraceError> { + self.events.push("enter:number"); + Ok(()) + } + + fn exit_number_label( + &mut self, + _ctx: &NumberLabelContext, + ) -> Result<(), TraceError> { + self.events.push("exit:number"); + Ok(()) + } + } + + struct FailingTrace; + + impl CalculatorListener<&'static str> for FailingTrace { + fn enter_multiply_label( + &mut self, + _ctx: &MultiplyLabelContext, + ) -> Result<(), &'static str> { + Err("stop at multiply") + } + } + + #[test] + fn evaluates_and_walks_exact_typed_alternatives() { + let lexer = CalculatorLexer::new(InputStream::new("2 + 8 / 2")); + let tokens = CommonTokenStream::new(lexer); + let mut parser = CalculatorParser::new(tokens); + let root = parser.start().expect("calculator input should parse"); + assert_eq!(parser.number_of_syntax_errors(), 0); + let parsed = parser.into_parsed_file(root); + assert!( + parsed + .tree() + .descendants() + .filter_map(antlr4_runtime::Node::as_rule) + .all(|rule| rule.alt_number() == 0), + "typed dispatch metadata must not become display-visible alt numbers" + ); + let start = parsed + .tree() + .as_rule() + .expect("start rule") + .downcast_ref::() + .expect("typed start context"); + assert_eq!(start.eof_token().expect("required EOF").to_string(), ""); + + assert_eq!(Eval.visit(parsed.tree()).expect("evaluation succeeds"), 6); + + let mut trace = Trace::default(); + trace.walk(parsed.tree()).expect("typed listener walk"); + assert_eq!( + trace.events, + [ + "enter:add", + "enter:number", + "exit:number", + "enter:multiply", + "enter:number", + "exit:number", + "enter:number", + "exit:number", + "exit:multiply", + "exit:add", + ] + ); + assert_eq!(trace.entered_rules, 6); + assert_eq!(trace.exited_rules, 6); + + assert_eq!( + FailingTrace.walk(parsed.tree()), + Err("stop at multiply"), + "listener domain errors must stop and escape the generated walker" + ); + + let start = parsed.tree().as_rule().expect("start rule"); + let expression = start + .child_rule(RULE_EXPRESSION) + .expect("top-level expression"); + let add = expression + .downcast_ref::() + .expect("top-level expression is addition"); + assert_eq!(add.rule_node().node().id(), expression.node().id()); + assert_eq!(add.expression_children().count(), 2); + assert!(add.plus_token().is_some()); + assert!(add.minus_token().is_none()); + assert_eq!( + add.left().expect("left expression").rule_node().node().id(), + expression + .child_rules(RULE_EXPRESSION) + .next() + .expect("left expression") + .node() + .id() + ); + assert!(expression.downcast_ref::().is_none()); + + let right = expression + .child_rules(RULE_EXPRESSION) + .nth(1) + .expect("right expression"); + assert!(right.downcast_ref::().is_some()); + assert!(right.downcast_ref::().is_none()); + + let lexer = CalculatorLexer::new(InputStream::new("+*1-")); + let tokens = CommonTokenStream::new(lexer); + let mut parser = CalculatorParser::new(tokens); + let root = parser + .labeled_tokens() + .expect("labeled token input should parse"); + let parsed = parser.into_parsed_file(root); + let labeled = parsed + .tree() + .as_rule() + .expect("labeledTokens rule") + .downcast_ref::() + .expect("typed labeledTokens context"); + assert_eq!(labeled.literal().expect("literal label").to_string(), "+"); + assert_eq!(labeled.choice().expect("set label").to_string(), "*"); + assert_eq!(labeled.other().expect("not-set label").to_string(), "1"); + assert_eq!(labeled.wildcard().expect("wildcard label").to_string(), "-"); + + let lexer = CalculatorLexer::new(InputStream::new("+*")); + let tokens = CommonTokenStream::new(lexer); + let mut parser = CalculatorParser::new(tokens); + let root = parser + .literal_tokens() + .expect("literal token input should parse"); + let parsed = parser.into_parsed_file(root); + let literal_tokens = parsed + .tree() + .as_rule() + .expect("literalTokens rule") + .downcast_ref::() + .expect("typed literalTokens context"); + assert_eq!( + literal_tokens + .plus_token() + .expect("required literal PLUS") + .to_string(), + "+" + ); + assert_eq!( + literal_tokens + .star_token() + .expect("required literal STAR") + .to_string(), + "*" + ); + assert_eq!( + literal_tokens + .eof_token() + .expect("required literal EOF") + .to_string(), + "" + ); + } +} +"#, + ); +} + +#[test] +fn listener_and_visitor_generation_can_be_disabled_independently() { + let temp = temporary_directory("tree-walker-flags"); + let grammar = Path::new(env!("CARGO_MANIFEST_DIR")) + .join("tests/fixtures/antlr4-rust-gen/combined-contexts/Shapes.g4"); + let visitor_only = temp.path().join("visitor-only"); + + let output = run_antlr4_rust_gen(&[ + grammar.as_os_str(), + OsStr::new("-no-listener"), + OsStr::new("-visitor"), + OsStr::new("--out-dir"), + visitor_only.as_os_str(), + ]); + assert!( + output.status.success(), + "stdout: {}\nstderr: {}", + utf8(&output.stdout), + utf8(&output.stderr) + ); + let parser = fs::read_to_string(visitor_only.join("shapes_parser.rs")) + .expect("parser should be emitted"); + assert!(parser.contains("pub trait ShapesVisitor"), "{parser}"); + assert!(!parser.contains("pub trait ShapesListener"), "{parser}"); + assert!(!parser.contains("pub struct ShapesTreeWalker"), "{parser}"); + assert!(!parser.contains("pub type ParseTreeWalker"), "{parser}"); + + let neither = temp.path().join("neither"); + let output = run_antlr4_rust_gen(&[ + grammar.as_os_str(), + OsStr::new("--no-listener"), + OsStr::new("--visitor"), + OsStr::new("--no-visitor"), + OsStr::new("--out-dir"), + neither.as_os_str(), + ]); + assert!( + output.status.success(), + "stdout: {}\nstderr: {}", + utf8(&output.stdout), + utf8(&output.stderr) + ); + let parser = + fs::read_to_string(neither.join("shapes_parser.rs")).expect("parser should be emitted"); + assert!(!parser.contains("pub trait ShapesVisitor"), "{parser}"); + assert!(!parser.contains("pub trait ShapesListener"), "{parser}"); } #[test] @@ -281,9 +737,9 @@ fn colliding_rule_and_alternative_label_context_names_compile() { ); let parser = fs::read_to_string(out.join("t.rs")).expect("parser should be emitted"); for expected in [ - "pub struct ObjectCreationExpressionContext<'a>", - "pub struct ObjectCreationExpressionLabelContext<'a>", - "pub struct ParenthesizedLabelContext<'a>", + "pub struct ObjectCreationExpressionContext<'a, State = StoredTreeContext>", + "pub struct ObjectCreationExpressionLabelContext<'a, State = StoredTreeContext>", + "pub struct ParenthesizedLabelContext<'a, State = StoredTreeContext>", "fn enter_object_creation_expression(&mut self", "fn enter_object_creation_expression_label(&mut self", "fn enter_parenthesized_label(&mut self", diff --git a/tests/fixtures/antlr4-rust-gen/combined-contexts/Shapes.g4 b/tests/fixtures/antlr4-rust-gen/combined-contexts/Shapes.g4 index 288bbf4d..1069f8c5 100644 --- a/tests/fixtures/antlr4-rust-gen/combined-contexts/Shapes.g4 +++ b/tests/fixtures/antlr4-rust-gen/combined-contexts/Shapes.g4 @@ -2,13 +2,21 @@ grammar Shapes; start : first = atom # Single - | rest += atom+ # Many + | rest += atom (COMMA rest += atom)* # Many + ; + +latest + : value = atom+ ; atom : ID ; +COMMA + : ',' + ; + ID : [a-z]+ ; diff --git a/tests/fixtures/antlr4-rust-gen/context-name-collision/T.g4 b/tests/fixtures/antlr4-rust-gen/context-name-collision/T.g4 index 3047621e..805ef0ae 100644 --- a/tests/fixtures/antlr4-rust-gen/context-name-collision/T.g4 +++ b/tests/fixtures/antlr4-rust-gen/context-name-collision/T.g4 @@ -14,3 +14,11 @@ primary_expression_start object_creation_expression : OPEN_PARENS CLOSE_PARENS ; + +everyRule + : NEW + ; + +storedTree + : NEW + ; diff --git a/tests/fixtures/antlr4-rust-gen/typed-tree-walkers/Calculator.g4 b/tests/fixtures/antlr4-rust-gen/typed-tree-walkers/Calculator.g4 new file mode 100644 index 00000000..8d4d36b1 --- /dev/null +++ b/tests/fixtures/antlr4-rust-gen/typed-tree-walkers/Calculator.g4 @@ -0,0 +1,45 @@ +grammar Calculator; + +start + : expression EOF + ; + +labeledTokens + : literal='+' choice=('*' | '/') other=~';' wildcard=. + ; + +literalTokens + : '+' '*' EOF + ; + +expression + : left = expression STAR right = expression # Multiply + | left = expression SLASH right = expression # Multiply + | left = expression PLUS right = expression # Add + | left = expression MINUS right = expression # Add + | INT # Number + ; + +STAR + : '*' + ; + +SLASH + : '/' + ; + +PLUS + : '+' + ; + +MINUS + : '-' + ; + +INT + : [0-9]+ + ; + +WS + : [ \t\r\n]+ -> skip + ; diff --git a/third_party/antlr-v4-grammar/self-hosted.sha256 b/third_party/antlr-v4-grammar/self-hosted.sha256 index b83c1a0a..f5a68417 100644 --- a/third_party/antlr-v4-grammar/self-hosted.sha256 +++ b/third_party/antlr-v4-grammar/self-hosted.sha256 @@ -3,4 +3,4 @@ c7114545a75ab294215819962e92e570383dc830fd5768463dab04e6733bcb80 third_party/antlr-v4-grammar/predefined.tokens 5803594bd2c8dd2d5180f1ca08fc70dfc80308479d18a7c4a1b743fa523b55ec third_party/antlr-v4-grammar/antlr-v4.toml 03fbfdcfb9020ece809ac8121a666cbb29382a1838834950a93abb864fbd338e src/bin_support/grammar/generated/antlr_v4_lexer.rs -78992e0a5a10d596b0e8f9d35e7727e574b0dc0fb590c3500b9beebaed8e16c7 src/bin_support/grammar/generated/antlr_v4_parser.rs +fb414bf09139c3fe0e6b5fbf48c1fb454b6330a95c08c821b6a8eea6a0fdd424 src/bin_support/grammar/generated/antlr_v4_parser.rs