Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ Using the same package release for `antlr4-rust-gen` and
`antlr-rust-runtime` remains the recommended workflow, but matching the
generated-code API is the compile-time requirement.

The bundled generator currently emits revision 3, which exposes parameterized
rule arguments to committed parser-action hooks. The runtime also accepts
revisions 1 and 2 because their older generated recognizers use API surfaces
that remain available.
The bundled generator currently emits revision 4, which moves typed parser
context mechanics behind a runtime support macro. The runtime also accepts
revisions 1, 2, and 3 because their older generated recognizers use API
surfaces that remain available.

Generated modules created before this check was introduced cannot be detected
retroactively. When first upgrading to a release that includes the check,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
source: crates/antlr-rust-codegen/src/generator.rs
assertion_line: 17489
source: crates/antlr-rust-codegen/src/generator/tests.rs
expression: "generated_module_header.replace(env!(\"CARGO_PKG_VERSION\"),\n\"<generator-version>\")"
---
// @generated by antlr-rust-codegen v<generator-version> - do not edit
// project: https://github.com/ophi-dev/antlr-rust-runtime
antlr4_runtime::__antlr4_rust_require_codegen_api!(3, "<generator-version>");
antlr4_runtime::__antlr4_rust_require_codegen_api!(4, "<generator-version>");
#[allow(warnings, missing_docs, clippy::all, clippy::pedantic, clippy::nursery)]
#[rustfmt::skip]
mod __antlr4_rust_generated {
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
---
source: crates/antlr-rust-codegen/src/generator.rs
source: crates/antlr-rust-codegen/src/generator/tests.rs
expression: "rendered_context_impl(&rendered, name)"
---

pub fn child_count(&self) -> usize {
match &self.__node {
__GeneratedRuleContext::Stored(node) => node.child_count(),
__GeneratedRuleContext::Active { context, .. } => context.child_count(),
}
}

/// Iterates terminals owned directly by this context without descending
/// into nested rule contexts.
///
/// Recovered trees expose inserted and deleted recovery tokens as error
/// nodes through the same `TerminalNode` surface. Use
/// `TerminalNode::is_error()` to identify recovery nodes and
/// `TerminalNode::is_missing()` to identify inserted synthetic tokens.
pub fn direct_terminals(
&self,
) -> impl Iterator<Item = TerminalNode<'a>> + 'a + use<'a, State> {
__terminal_children(self.__node).map(TerminalNode::new)
}

pub fn start(&self) -> __GeneratedTokenView {
let token = match &self.__node {
__GeneratedRuleContext::Stored(node) => node.start(),
__GeneratedRuleContext::Active { context, tokens, .. } => context.start(tokens),
};
__GeneratedTokenView { text: token.map(|token| token.text_or_empty().to_owned()).unwrap_or_default() }
}

pub fn text(&self) -> String {
match &self.__node {
__GeneratedRuleContext::Stored(node) => node.text(),
__GeneratedRuleContext::Active { context, storage, tokens } => context.text(storage, tokens),
}
}
}

#[allow(dead_code, private_bounds, clippy::all)]
impl<'a, State: __RecoveryContextState> BranchHazardContext<'a, State> {
pub fn unary(&self) -> Result<UnaryContext<'a>, MissingChildError> {
__rule_children(self.__node, 4)
.next()
Expand All @@ -62,51 +24,6 @@ impl<'a, State: __RecoveryContextState> BranchHazardContext<'a, State> {

#[allow(dead_code, clippy::all)]
impl<'a> BranchHazardContext<'a, ValidatedTreeContext> {
fn __from_validated_node(node: RuleNodeView<'a>) -> Self {
Self::__from_validated_node_with_invocation_states(node, None)
}

fn __from_validated_child_node(
node: RuleNodeView<'a>,
parent_invocation_states: Option<&[isize]>,
) -> Self {
let invocation_states = parent_invocation_states.map(|states| {
let mut invocation_states = Vec::with_capacity(states.len() + 1);
invocation_states.push(node.invoking_state());
invocation_states.extend_from_slice(states);
invocation_states
});
Self::__from_validated_node_with_invocation_states(node, invocation_states)
}

fn __from_validated_listener_node(
node: RuleNodeView<'a>,
invocation_states: Option<&[isize]>,
) -> Self {
Self::__from_validated_node_with_invocation_states(
node,
invocation_states.map(|states| states.to_vec()),
)
}

fn __from_validated_node_with_invocation_states(
node: RuleNodeView<'a>,
invocation_states: Option<Vec<isize>>,
) -> Self {
Self {
__node: __GeneratedRuleContext::Stored(node),
__invocation_states: invocation_states,
__state: std::marker::PhantomData,
}
}

pub fn rule_node(&self) -> RuleNodeView<'a> {
match self.__node {
__GeneratedRuleContext::Stored(node) => node,
__GeneratedRuleContext::Active { .. } => unreachable!("validated context contains an active parser context"),
}
}

pub fn unary(&self) -> UnaryContext<'a, ValidatedTreeContext> {
let Some(node) = __rule_children(self.__node, 4).next() else {
unreachable!("validated BranchHazardContext is missing required child unary")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
---
source: crates/antlr-rust-codegen/src/generator.rs
source: crates/antlr-rust-codegen/src/generator/tests.rs
expression: "rendered_context_impl(&rendered, name)"
---

pub fn child_count(&self) -> usize {
match &self.__node {
__GeneratedRuleContext::Stored(node) => node.child_count(),
__GeneratedRuleContext::Active { context, .. } => context.child_count(),
}
}

/// Iterates terminals owned directly by this context without descending
/// into nested rule contexts.
///
/// Recovered trees expose inserted and deleted recovery tokens as error
/// nodes through the same `TerminalNode` surface. Use
/// `TerminalNode::is_error()` to identify recovery nodes and
/// `TerminalNode::is_missing()` to identify inserted synthetic tokens.
pub fn direct_terminals(
&self,
) -> impl Iterator<Item = TerminalNode<'a>> + 'a + use<'a, State> {
__terminal_children(self.__node).map(TerminalNode::new)
}

pub fn start(&self) -> __GeneratedTokenView {
let token = match &self.__node {
__GeneratedRuleContext::Stored(node) => node.start(),
__GeneratedRuleContext::Active { context, tokens, .. } => context.start(tokens),
};
__GeneratedTokenView { text: token.map(|token| token.text_or_empty().to_owned()).unwrap_or_default() }
}

pub fn text(&self) -> String {
match &self.__node {
__GeneratedRuleContext::Stored(node) => node.text(),
__GeneratedRuleContext::Active { context, storage, tokens } => context.text(storage, tokens),
}
}
}

#[allow(dead_code, private_bounds, clippy::all)]
impl<'a, State: __RecoveryContextState> BranchRivalContext<'a, State> {
pub fn unary(&self) -> Result<UnaryContext<'a>, MissingChildError> {
__rule_children(self.__node, 4)
.next()
Expand All @@ -57,51 +19,6 @@ impl<'a, State: __RecoveryContextState> BranchRivalContext<'a, State> {

#[allow(dead_code, clippy::all)]
impl<'a> BranchRivalContext<'a, ValidatedTreeContext> {
fn __from_validated_node(node: RuleNodeView<'a>) -> Self {
Self::__from_validated_node_with_invocation_states(node, None)
}

fn __from_validated_child_node(
node: RuleNodeView<'a>,
parent_invocation_states: Option<&[isize]>,
) -> Self {
let invocation_states = parent_invocation_states.map(|states| {
let mut invocation_states = Vec::with_capacity(states.len() + 1);
invocation_states.push(node.invoking_state());
invocation_states.extend_from_slice(states);
invocation_states
});
Self::__from_validated_node_with_invocation_states(node, invocation_states)
}

fn __from_validated_listener_node(
node: RuleNodeView<'a>,
invocation_states: Option<&[isize]>,
) -> Self {
Self::__from_validated_node_with_invocation_states(
node,
invocation_states.map(|states| states.to_vec()),
)
}

fn __from_validated_node_with_invocation_states(
node: RuleNodeView<'a>,
invocation_states: Option<Vec<isize>>,
) -> Self {
Self {
__node: __GeneratedRuleContext::Stored(node),
__invocation_states: invocation_states,
__state: std::marker::PhantomData,
}
}

pub fn rule_node(&self) -> RuleNodeView<'a> {
match self.__node {
__GeneratedRuleContext::Stored(node) => node,
__GeneratedRuleContext::Active { .. } => unreachable!("validated context contains an active parser context"),
}
}

pub fn unary(&self) -> UnaryContext<'a, ValidatedTreeContext> {
let Some(node) = __rule_children(self.__node, 4).next() else {
unreachable!("validated BranchRivalContext is missing required child unary")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
---
source: crates/antlr-rust-codegen/src/generator.rs
assertion_line: 19412
source: crates/antlr-rust-codegen/src/generator/tests.rs
expression: calc_context
---

pub fn child_count(&self) -> usize {
match &self.__node {
__GeneratedRuleContext::Stored(node) => node.child_count(),
__GeneratedRuleContext::Active { context, .. } => context.child_count(),
}
}

/// Iterates terminals owned directly by this context without descending
/// into nested rule contexts.
///
/// Recovered trees expose inserted and deleted recovery tokens as error
/// nodes through the same `TerminalNode` surface. Use
/// `TerminalNode::is_error()` to identify recovery nodes and
/// `TerminalNode::is_missing()` to identify inserted synthetic tokens.
pub fn direct_terminals(
&self,
) -> impl Iterator<Item = TerminalNode<'a>> + 'a + use<'a, State> {
__terminal_children(self.__node).map(TerminalNode::new)
}

pub fn start(&self) -> __GeneratedTokenView {
let token = match &self.__node {
__GeneratedRuleContext::Stored(node) => node.start(),
__GeneratedRuleContext::Active { context, tokens, .. } => context.start(tokens),
};
__GeneratedTokenView { text: token.map(|token| token.text_or_empty().to_owned()).unwrap_or_default() }
}

pub fn text(&self) -> String {
match &self.__node {
__GeneratedRuleContext::Stored(node) => node.text(),
__GeneratedRuleContext::Active { context, storage, tokens } => context.text(storage, tokens),
}
}
}

#[allow(dead_code, private_bounds, clippy::all)]
impl<'a, State: __RecoveryContextState> CalcContext<'a, State> {
pub fn calc_children(&self) -> impl Iterator<Item = CalcContext<'a>> + '_ {
__rule_children(self.__node, 2)
.map(move |node| CalcContext::__from_child_node(node, self.__invocation_states.as_deref()))
Expand Down Expand Up @@ -85,51 +46,6 @@ impl<'a, State: __RecoveryContextState> CalcContext<'a, State> {

#[allow(dead_code, clippy::all)]
impl<'a> CalcContext<'a, ValidatedTreeContext> {
fn __from_validated_node(node: RuleNodeView<'a>) -> Self {
Self::__from_validated_node_with_invocation_states(node, None)
}

fn __from_validated_child_node(
node: RuleNodeView<'a>,
parent_invocation_states: Option<&[isize]>,
) -> Self {
let invocation_states = parent_invocation_states.map(|states| {
let mut invocation_states = Vec::with_capacity(states.len() + 1);
invocation_states.push(node.invoking_state());
invocation_states.extend_from_slice(states);
invocation_states
});
Self::__from_validated_node_with_invocation_states(node, invocation_states)
}

fn __from_validated_listener_node(
node: RuleNodeView<'a>,
invocation_states: Option<&[isize]>,
) -> Self {
Self::__from_validated_node_with_invocation_states(
node,
invocation_states.map(|states| states.to_vec()),
)
}

fn __from_validated_node_with_invocation_states(
node: RuleNodeView<'a>,
invocation_states: Option<Vec<isize>>,
) -> Self {
Self {
__node: __GeneratedRuleContext::Stored(node),
__invocation_states: invocation_states,
__state: std::marker::PhantomData,
}
}

pub fn rule_node(&self) -> RuleNodeView<'a> {
match self.__node {
__GeneratedRuleContext::Stored(node) => node,
__GeneratedRuleContext::Active { .. } => unreachable!("validated context contains an active parser context"),
}
}

pub fn calc_children(&self) -> impl Iterator<Item = CalcContext<'a, ValidatedTreeContext>> + '_ {
__rule_children(self.__node, 2)
.map(move |node| CalcContext::<ValidatedTreeContext>::__from_validated_child_node(node, self.__invocation_states.as_deref()))
Expand Down
Loading
Loading