156 lines
3.5 KiB
Rust
156 lines
3.5 KiB
Rust
use crate::ast::node::call_expression::CallExpression;
|
|
use crate::ast::node::closure::Closure;
|
|
use crate::ast::node::literal::Literal;
|
|
use crate::ast::node::names::FullyQualifiedName;
|
|
use crate::ast::node::object_access::ObjectAccess;
|
|
use crate::ast::node::operators::{BinaryOperator, PrefixUnaryOperator, SuffixUnaryOperator};
|
|
|
|
#[derive(Debug)]
|
|
pub enum Expression {
|
|
Ternary(Box<TernaryExpression>),
|
|
Binary(Box<BinaryExpression>),
|
|
UnaryPrefix(Box<PrefixExpression>),
|
|
UnarySuffix(Box<SuffixExpression>),
|
|
Call(Box<CallExpression>),
|
|
ObjectAccess(Box<ObjectAccess>),
|
|
Literal(Box<Literal>),
|
|
FullyQualifiedName(Box<FullyQualifiedName>),
|
|
Closure(Box<Closure>),
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct TernaryExpression {
|
|
condition: Box<Expression>,
|
|
true_expression: Box<Expression>,
|
|
false_expression: Box<Expression>,
|
|
}
|
|
|
|
impl TernaryExpression {
|
|
pub fn new(
|
|
condition: Box<Expression>,
|
|
true_expression: Box<Expression>,
|
|
false_expression: Box<Expression>,
|
|
) -> Self {
|
|
Self {
|
|
condition,
|
|
true_expression,
|
|
false_expression,
|
|
}
|
|
}
|
|
|
|
pub fn condition(&self) -> &Expression {
|
|
&self.condition
|
|
}
|
|
|
|
pub fn condition_mut(&mut self) -> &mut Expression {
|
|
&mut self.condition
|
|
}
|
|
|
|
pub fn true_expression(&self) -> &Expression {
|
|
&self.true_expression
|
|
}
|
|
|
|
pub fn true_expression_mut(&mut self) -> &mut Expression {
|
|
&mut self.true_expression
|
|
}
|
|
|
|
pub fn false_expression(&self) -> &Expression {
|
|
&self.false_expression
|
|
}
|
|
|
|
pub fn false_expression_mut(&mut self) -> &mut Expression {
|
|
&mut self.false_expression
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct BinaryExpression {
|
|
left: Box<Expression>,
|
|
operator: BinaryOperator,
|
|
right: Box<Expression>,
|
|
}
|
|
|
|
impl BinaryExpression {
|
|
pub fn new(left: Box<Expression>, operator: BinaryOperator, right: Box<Expression>) -> Self {
|
|
Self {
|
|
left,
|
|
operator,
|
|
right,
|
|
}
|
|
}
|
|
|
|
pub fn left(&self) -> &Expression {
|
|
&self.left
|
|
}
|
|
|
|
pub fn left_mut(&mut self) -> &mut Expression {
|
|
&mut self.left
|
|
}
|
|
|
|
pub fn operator(&self) -> &BinaryOperator {
|
|
&self.operator
|
|
}
|
|
|
|
pub fn right(&self) -> &Expression {
|
|
&self.right
|
|
}
|
|
|
|
pub fn right_mut(&mut self) -> &mut Expression {
|
|
&mut self.right
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct PrefixExpression {
|
|
operator: PrefixUnaryOperator,
|
|
expression: Box<Expression>,
|
|
}
|
|
|
|
impl PrefixExpression {
|
|
pub fn new(operator: PrefixUnaryOperator, expression: Box<Expression>) -> Self {
|
|
Self {
|
|
operator,
|
|
expression,
|
|
}
|
|
}
|
|
|
|
pub fn operator(&self) -> &PrefixUnaryOperator {
|
|
&self.operator
|
|
}
|
|
|
|
pub fn expression(&self) -> &Expression {
|
|
&self.expression
|
|
}
|
|
|
|
pub fn expression_mut(&mut self) -> &mut Expression {
|
|
&mut self.expression
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct SuffixExpression {
|
|
expression: Box<Expression>,
|
|
operator: SuffixUnaryOperator,
|
|
}
|
|
|
|
impl SuffixExpression {
|
|
pub fn new(expression: Box<Expression>, operator: SuffixUnaryOperator) -> Self {
|
|
Self {
|
|
expression,
|
|
operator,
|
|
}
|
|
}
|
|
|
|
pub fn expression(&self) -> &Expression {
|
|
&self.expression
|
|
}
|
|
|
|
pub fn expression_mut(&mut self) -> &mut Expression {
|
|
&mut self.expression
|
|
}
|
|
|
|
pub fn operator(&self) -> &SuffixUnaryOperator {
|
|
&self.operator
|
|
}
|
|
}
|