241 lines
6.6 KiB
Rust
241 lines
6.6 KiB
Rust
use super::parsed_type_modifier::ParsedTypeModifier;
|
|
use crate::defines::{LiteralFloat, LiteralInt};
|
|
use crate::modifiers::{FieldModifier, TypeModifier};
|
|
use crate::parsing::parser::parsed_funcattr::FuncAttr;
|
|
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;
|
|
|
|
#[cfg(test)]
|
|
use serde_derive::{Deserialize, Serialize};
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
#[cfg_attr(test, derive(Serialize, Deserialize))]
|
|
pub struct ParsedParameter {
|
|
pub parameter_type: Box<ParsedStatement>,
|
|
pub type_mod: Option<BitFlags<ReferenceModifier>>,
|
|
pub identifier: Option<String>,
|
|
pub default: Option<Box<ParsedStatement>>,
|
|
}
|
|
|
|
#[derive(PartialEq, Debug)]
|
|
#[cfg_attr(test, derive(Serialize, Deserialize))]
|
|
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: Option<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<ParsedParameter>,
|
|
},
|
|
InterfaceMethod {
|
|
return_type: Box<ParsedStatement>,
|
|
returns_reference: bool,
|
|
identifier: String,
|
|
param_list: Box<ParsedStatement>,
|
|
is_const: bool,
|
|
},
|
|
TypeDefStatement {
|
|
from: Box<ParsedStatement>,
|
|
to: Box<ParsedStatement>,
|
|
},
|
|
ImportStatement {
|
|
import_type: Box<ParsedStatement>,
|
|
is_reference: bool,
|
|
identifier: String,
|
|
param_list: Box<ParsedStatement>,
|
|
func_attr: BitFlags<FuncAttr>,
|
|
source: String,
|
|
},
|
|
ArgList {
|
|
args: Vec<(Option<String>, Box<ParsedStatement>)>,
|
|
},
|
|
EnumDeclaration {
|
|
modifiers: BitFlags<TypeModifier>,
|
|
identifier: String,
|
|
base_type: Option<Box<ParsedStatement>>,
|
|
values: Vec<(String, Option<Box<ParsedStatement>>)>,
|
|
},
|
|
FuncDeclaration {
|
|
modifiers: BitFlags<TypeModifier>,
|
|
field_mod: Option<FieldModifier>,
|
|
is_destructor: bool,
|
|
returns_reference: bool,
|
|
return_type: Option<Box<ParsedStatement>>,
|
|
name: String,
|
|
param_list: Box<ParsedStatement>,
|
|
is_const: bool,
|
|
func_attr: BitFlags<FuncAttr>,
|
|
block: Option<Box<ParsedStatement>>,
|
|
},
|
|
FuncDefDeclaration {
|
|
modifiers: BitFlags<TypeModifier>,
|
|
returns_reference: bool,
|
|
return_type: Option<Box<ParsedStatement>>,
|
|
name: String,
|
|
param_list: Box<ParsedStatement>,
|
|
},
|
|
ClassDeclaration {
|
|
modifiers: BitFlags<TypeModifier>,
|
|
name: String,
|
|
inherits: Vec<String>,
|
|
statements: Vec<Box<ParsedStatement>>,
|
|
},
|
|
}
|