a ton of stuff idk more ir work
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use super::{Symbol, Token};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum BinaryOperator {
|
||||
pub enum BinaryOp {
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
@@ -12,7 +12,7 @@ pub enum BinaryOperator {
|
||||
Assign,
|
||||
}
|
||||
|
||||
impl BinaryOperator {
|
||||
impl BinaryOp {
|
||||
pub fn presedence(&self) -> u32 {
|
||||
match self {
|
||||
Self::Assign => 0,
|
||||
@@ -37,6 +37,39 @@ impl BinaryOperator {
|
||||
Self::Assign => "=",
|
||||
}
|
||||
}
|
||||
pub fn pad(&self) -> bool {
|
||||
match self {
|
||||
Self::Add => true,
|
||||
Self::Sub => true,
|
||||
Self::Mul => true,
|
||||
Self::Div => true,
|
||||
Self::LessThan => true,
|
||||
Self::GreaterThan => true,
|
||||
Self::Access => false,
|
||||
Self::Assign => true,
|
||||
}
|
||||
}
|
||||
pub fn traitt(&self) -> &str {
|
||||
match self {
|
||||
Self::Add => "Add",
|
||||
Self::Sub => "Sub",
|
||||
Self::Mul => "Mul",
|
||||
Self::Div => "Div",
|
||||
Self::LessThan => "LessThan",
|
||||
Self::GreaterThan => "GreaterThan",
|
||||
Self::Access => "Access",
|
||||
Self::Assign => "Assign",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum UnaryOp {
|
||||
Not,
|
||||
Ref,
|
||||
Deref,
|
||||
}
|
||||
|
||||
impl BinaryOp {
|
||||
pub fn from_token(token: &Token) -> Option<Self> {
|
||||
let Token::Symbol(symbol) = token else {
|
||||
return None;
|
||||
@@ -55,30 +88,14 @@ impl BinaryOperator {
|
||||
}
|
||||
})
|
||||
}
|
||||
pub fn pad(&self) -> bool {
|
||||
match self {
|
||||
Self::Add => true,
|
||||
Self::Sub => true,
|
||||
Self::Mul => true,
|
||||
Self::Div => true,
|
||||
Self::LessThan => true,
|
||||
Self::GreaterThan => true,
|
||||
Self::Access => false,
|
||||
Self::Assign => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum UnaryOperator {
|
||||
Not,
|
||||
Ref,
|
||||
}
|
||||
|
||||
impl UnaryOperator {
|
||||
impl UnaryOp {
|
||||
pub fn str(&self) -> &str {
|
||||
match self {
|
||||
Self::Not => "!",
|
||||
Self::Ref => "&",
|
||||
Self::Deref => "*",
|
||||
}
|
||||
}
|
||||
pub fn from_token(token: &Token) -> Option<Self> {
|
||||
@@ -88,6 +105,7 @@ impl UnaryOperator {
|
||||
Some(match symbol {
|
||||
Symbol::Ampersand => Self::Ref,
|
||||
Symbol::Bang => Self::Not,
|
||||
Symbol::Asterisk => Self::Deref,
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user