SeraphScript/src/parsing/parser/parsed_statement.rs

179 lines
4.8 KiB
Rust

use super::parsed_type_modifier::ParsedTypeModifier;
use crate::defines::{LiteralFloat, LiteralInt};
use crate::modifiers::{FieldModifier, TypeModifier};
use crate::parsing::parser::parsed_type_modifier::ReferenceModifier;
use crate::parsing::parser::parser_operators::{
BinaryOperator, PostOperator, PreOperator, TernaryOperator,
};
use crate::prim_type::PrimitiveType;
use enumflags2::BitFlags;
#[derive(PartialEq, Debug)]
pub enum ParsedStatement {
Invalid,
Script {
statements: Vec<ParsedStatement>,
},
Namespace {
identifier: String,
script: Box<ParsedStatement>,
},
Interface {
type_mod: BitFlags<TypeModifier>,
identifier: String,
inherits: Vec<String>,
statements: Vec<ParsedStatement>,
},
Scope {
is_global: bool,
scope: Vec<String>,
generic_types: Option<Vec<ParsedStatement>>,
},
VirtProp {
field_mod: BitFlags<FieldModifier>,
property_type: Box<ParsedStatement>,
identifier: String,
is_handle: bool,
has_get: bool,
is_get_const: bool,
get_statement: Option<Box<ParsedStatement>>,
has_set: bool,
is_set_const: bool,
set_statement: Option<Box<ParsedStatement>>,
},
DataTypeIdentifier {
identifier: String,
},
DataTypeAuto {},
DataTypePrimType {
prim_type: PrimitiveType,
},
Type {
is_const: bool,
scope: Option<Box<ParsedStatement>>,
datatype: Box<ParsedStatement>,
modifiers: Vec<ParsedTypeModifier>,
},
Var {
modifier: BitFlags<FieldModifier>,
var_type: Box<ParsedStatement>,
identifier: String,
assignment: Option<Box<ParsedStatement>>,
},
ExprTermInitList {
statement_type: Option<Box<ParsedStatement>>,
initlist: Box<ParsedStatement>,
},
ExprPreOp {
operator: PreOperator,
operand: Box<ParsedStatement>,
},
ExprPostOp {
operator: PostOperator,
operand: Box<ParsedStatement>,
},
ExprVoidValue {},
ConstructCall {
statement_type: Option<Box<ParsedStatement>>,
arglist: Box<ParsedStatement>,
},
FuncCall {
scope: Option<Box<ParsedStatement>>,
identifier: String,
arglist: Box<ParsedStatement>,
},
VarAccess {
scope: Option<Box<ParsedStatement>>,
identifier: String,
},
Cast {
cast_type: Box<ParsedStatement>,
assign: Box<ParsedStatement>,
},
IntegerLiteral(LiteralInt),
FloatLiteral(LiteralFloat),
BoolLiteral(bool),
StringLiteral(String),
BinaryExpr {
left: Box<ParsedStatement>,
operator: BinaryOperator,
right: Box<ParsedStatement>,
},
TernaryExpr {
left: Box<ParsedStatement>,
operator: TernaryOperator,
middle: Box<ParsedStatement>,
right: Box<ParsedStatement>,
},
MemberAccess {
operand: Box<ParsedStatement>,
identifier: String,
},
MemberFuncCall {
operand: Box<ParsedStatement>,
func_call: Box<ParsedStatement>,
},
IndexingOperator {
operand: Box<ParsedStatement>,
index: Vec<(Option<String>, Box<ParsedStatement>)>,
},
AnonymousCall {
operand: Box<ParsedStatement>,
arg_list: Box<ParsedStatement>,
},
Assignment {
left: Box<ParsedStatement>,
operator: BinaryOperator,
right: Box<ParsedStatement>,
},
Switch {
expression: Box<ParsedStatement>,
cases: Vec<Box<ParsedStatement>>,
},
Case {
// None for default
expression: Option<Box<ParsedStatement>>,
statement: Box<ParsedStatement>,
},
TryStatement {
try_block: Box<ParsedStatement>,
catch_block: Box<ParsedStatement>,
},
StatBlock {
statements: Vec<Box<ParsedStatement>>,
},
DoWhileStatement {
statement: Box<ParsedStatement>,
condition: Box<ParsedStatement>,
},
WhileStatement {
condition: Box<ParsedStatement>,
statement: Box<ParsedStatement>,
},
ForStatement {
initializer: Box<ParsedStatement>,
bounds: Box<ParsedStatement>,
increment: Vec<Box<ParsedStatement>>,
},
IfStatement {
condition: Box<ParsedStatement>,
statement: Box<ParsedStatement>,
else_statement: Option<Box<ParsedStatement>>,
},
BreakStatement {},
ContinueStatement {},
ReturnStatement {
expression: Option<Box<ParsedStatement>>,
},
ParamList {
parameters: Vec<(
Box<ParsedStatement>, // type
Option<BitFlags<ReferenceModifier>>, // typemod
Option<String>, // identifier
Option<Box<ParsedStatement>>, // default expression
)>,
},
}