#![allow(nonstandard_style)]
#![allow(dead_code)]
// Generated from VisitorBasic.g4 by ANTLR 4.13.2
use dbt_antlr4::errors::ANTLRError;
use dbt_antlr4::tree::*;
use super::visitorbasicparser::*;

/// This interface defines a complete generic visitor for a parse tree produced
/// by {@link VisitorBasicParser}.
pub trait VisitorBasicVisitor<'input, 'arena>
where
    'input: 'arena,
{
    type Return: Default;

    /// Visit a parse tree produced by {@link VisitorBasicParser#s}.
    /// @param ctx the parse tree
    fn visit_s(&mut self, ctx: &SContext<'input, 'arena>) -> Result<Self::Return, ANTLRError> { self.visit_children(ctx) }


    /// Called on terminal(leaf) node
    fn visit_terminal(
        &mut self,
        _node: &TerminalNode<'input, 'arena>,
    ) -> Result<Self::Return, ANTLRError> { Ok(Self::Return::default()) }

    /// Called on error node
    fn visit_error_node(
        &mut self,
        _node: &ErrorNode<'input, 'arena>,
    ) -> Result<Self::Return, ANTLRError> { Ok(Self::Return::default()) }

    fn visit(&mut self, tree: &'arena dyn NodeInner<'input, 'arena, VisitorBasicParserContextNode<'input, 'arena>>) -> Result<Self::Return, ANTLRError> {
        let Some(node) = tree.try_as_node() else {
            return Err(ANTLRError::custom_error("Visitor can only visit non-leaf nodes".to_string()));
        };
        self.visit_node(node)
    }

    fn visit_node(&mut self, node: &VisitorBasicParserContextNode<'input, 'arena>) -> Result<Self::Return, ANTLRError> {
        node.accept(self)
    }

    fn visit_children(
        &mut self,
        node: &dyn NodeInner<'input, 'arena, VisitorBasicParserContextNode<'input, 'arena>>,
    ) -> Result<Self::Return, ANTLRError> {
        let mut result = Self::Return::default();
        for child in node.iter_child_nodes() {
            if !self.should_visit_next_child(child, &result) {
                break;
            }

            let child_result = self.visit_node(child)?;
            result = self.aggregate_results(result, child_result)?;
        }
        Ok(result)
    }

    fn aggregate_results(
        &self,
        _aggregate: Self::Return,
        next: Self::Return,
    ) -> Result<Self::Return, ANTLRError> { Ok(next) }

    fn should_visit_next_child(&self, _node: &VisitorBasicParserContextNode<'input, 'arena>, _current: &Self::Return) -> bool { true }
}