-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve parser for expressions, removing a previous limitation
- Loading branch information
Showing
7 changed files
with
236 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,112 @@ | ||
use crate::{operations::Operation, statements::Statement}; | ||
use crate::{common::Ident, statements::Statement, types::TypeSpec}; | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum Expression { | ||
Simple(SimpleExpr), | ||
FnCall(FnCallOp), | ||
Match(MatchExpr), | ||
If(IfExpr), | ||
Operation(Operation), | ||
UnaryOp(UnaryOp, Box<Self>), | ||
BinaryOp(Box<Self>, BinaryOp, Box<Self>), | ||
} | ||
|
||
// needed for match variants and array accesses | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum SimpleExpr { | ||
ConstBool(bool), | ||
ConstChar(char), | ||
ConstInt(u64), | ||
ConstFloat(f64), | ||
ConstStr(String), | ||
Path(PathOp), | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Copy)] | ||
pub enum UnaryOp { | ||
ArithNeg, | ||
LogicalNot, | ||
BitwiseNot, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Copy)] | ||
pub enum BinaryOp { | ||
Arith(ArithOp), | ||
Logic(LogicOp), | ||
Compare(CmpOp), | ||
Bitwise(BitwiseOp), | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Copy)] | ||
pub enum ArithOp { | ||
Add, | ||
Sub, | ||
Mul, | ||
Div, | ||
Mod, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Copy)] | ||
pub enum LogicOp { | ||
And, | ||
Or, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Copy)] | ||
pub enum CmpOp { | ||
Eq, | ||
NotEq, | ||
Lt, | ||
LtEq, | ||
Gt, | ||
GtEq, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Copy)] | ||
pub enum BitwiseOp { | ||
And, | ||
Or, | ||
Xor, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct MatchExpr { | ||
pub value: Operation, | ||
pub value: Box<Expression>, | ||
pub variants: Vec<MatchVariant>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct IfExpr { | ||
pub value: Operation, | ||
pub value: Box<Expression>, | ||
pub contents: Vec<Statement>, | ||
pub r#else: Option<Vec<Statement>>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct MatchVariant { | ||
pub case: Operation, | ||
pub case: SimpleExpr, | ||
pub block: Vec<Statement>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum PathSegment { | ||
FieldAccess(Ident), | ||
ArrayIndex(SimpleExpr), | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct PathOp { | ||
pub first: Ident, | ||
pub extra: Vec<PathSegment>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct CastOp { | ||
pub value: Expression, | ||
pub r#type: TypeSpec, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct FnCallOp { | ||
pub target: Ident, | ||
pub args: Vec<Expression>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.