leo_ast/passes/
consumer.rsuse crate::*;
pub trait ExpressionConsumer {
type Output;
fn consume_expression(&mut self, input: Expression) -> Self::Output {
match input {
Expression::Access(access) => self.consume_access(access),
Expression::Array(array) => self.consume_array(array),
Expression::Binary(binary) => self.consume_binary(binary),
Expression::Call(call) => self.consume_call(call),
Expression::Cast(cast) => self.consume_cast(cast),
Expression::Struct(struct_) => self.consume_struct_init(struct_),
Expression::Err(err) => self.consume_err(err),
Expression::Identifier(identifier) => self.consume_identifier(identifier),
Expression::Literal(value) => self.consume_literal(value),
Expression::Locator(locator) => self.consume_locator(locator),
Expression::Ternary(ternary) => self.consume_ternary(ternary),
Expression::Tuple(tuple) => self.consume_tuple(tuple),
Expression::Unary(unary) => self.consume_unary(unary),
Expression::Unit(unit) => self.consume_unit(unit),
}
}
fn consume_access(&mut self, _input: AccessExpression) -> Self::Output;
fn consume_array(&mut self, _input: ArrayExpression) -> Self::Output;
fn consume_binary(&mut self, _input: BinaryExpression) -> Self::Output;
fn consume_call(&mut self, _input: CallExpression) -> Self::Output;
fn consume_cast(&mut self, _input: CastExpression) -> Self::Output;
fn consume_struct_init(&mut self, _input: StructExpression) -> Self::Output;
fn consume_err(&mut self, _input: ErrExpression) -> Self::Output {
unreachable!("`ErrExpression`s should not be in the AST at this phase of compilation.")
}
fn consume_identifier(&mut self, _input: Identifier) -> Self::Output;
fn consume_literal(&mut self, _input: Literal) -> Self::Output;
fn consume_locator(&mut self, _input: LocatorExpression) -> Self::Output;
fn consume_ternary(&mut self, _input: TernaryExpression) -> Self::Output;
fn consume_tuple(&mut self, _input: TupleExpression) -> Self::Output;
fn consume_unary(&mut self, _input: UnaryExpression) -> Self::Output;
fn consume_unit(&mut self, _input: UnitExpression) -> Self::Output;
}
pub trait StatementConsumer {
type Output;
fn consume_statement(&mut self, input: Statement) -> Self::Output {
match input {
Statement::Assert(assert) => self.consume_assert(assert),
Statement::Assign(stmt) => self.consume_assign(*stmt),
Statement::Block(stmt) => self.consume_block(stmt),
Statement::Conditional(stmt) => self.consume_conditional(stmt),
Statement::Console(stmt) => self.consume_console(stmt),
Statement::Const(stmt) => self.consume_const(stmt),
Statement::Definition(stmt) => self.consume_definition(stmt),
Statement::Expression(stmt) => self.consume_expression_statement(stmt),
Statement::Iteration(stmt) => self.consume_iteration(*stmt),
Statement::Return(stmt) => self.consume_return(stmt),
}
}
fn consume_assert(&mut self, input: AssertStatement) -> Self::Output;
fn consume_assign(&mut self, input: AssignStatement) -> Self::Output;
fn consume_block(&mut self, input: Block) -> Self::Output;
fn consume_conditional(&mut self, input: ConditionalStatement) -> Self::Output;
fn consume_console(&mut self, input: ConsoleStatement) -> Self::Output;
fn consume_const(&mut self, input: ConstDeclaration) -> Self::Output;
fn consume_definition(&mut self, input: DefinitionStatement) -> Self::Output;
fn consume_expression_statement(&mut self, input: ExpressionStatement) -> Self::Output;
fn consume_iteration(&mut self, input: IterationStatement) -> Self::Output;
fn consume_return(&mut self, input: ReturnStatement) -> Self::Output;
}
pub trait FunctionConsumer {
type Output;
fn consume_function(&mut self, input: Function) -> Self::Output;
}
pub trait StructConsumer {
type Output;
fn consume_struct(&mut self, input: Composite) -> Self::Output;
}
pub trait ImportConsumer {
type Output;
fn consume_import(&mut self, input: Program) -> Self::Output;
}
pub trait MappingConsumer {
type Output;
fn consume_mapping(&mut self, input: Mapping) -> Self::Output;
}
pub trait ProgramScopeConsumer {
type Output;
fn consume_program_scope(&mut self, input: ProgramScope) -> Self::Output;
}
pub trait ProgramConsumer {
type Output;
fn consume_program(&mut self, input: Program) -> Self::Output;
}