chore: fmt

This commit is contained in:
Ryan Chandler 2022-12-09 22:35:00 +00:00
parent 0ee981aed6
commit df45b9f034
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA
3 changed files with 246 additions and 106 deletions

View File

@ -7,11 +7,11 @@ pub mod functions;
pub mod identifiers;
pub mod interfaces;
pub mod modifiers;
pub mod operators;
pub mod properties;
pub mod traits;
pub mod try_block;
pub mod variables;
pub mod operators;
use std::fmt::Display;
@ -588,9 +588,7 @@ pub struct ListItem {
}
#[derive(Debug, Eq, PartialEq, Clone)]
pub enum InfixOp {
}
pub enum InfixOp {}
impl From<TokenKind> for InfixOp {
fn from(k: TokenKind) -> Self {

View File

@ -131,7 +131,7 @@ pub enum AssignmentOperation {
left: Box<Expression>,
span: Span,
right: Box<Expression>,
}
},
}
#[derive(Debug, Clone, PartialEq)]
@ -164,7 +164,7 @@ pub enum BitwiseOperation {
Not {
span: Span,
right: Box<Expression>,
}
},
}
#[derive(Debug, Clone, PartialEq)]
@ -218,7 +218,7 @@ pub enum ComparisonOperation {
left: Box<Expression>,
span: Span,
right: Box<Expression>,
}
},
}
#[derive(Debug, Clone, PartialEq)]
@ -252,4 +252,4 @@ pub enum LogicalOperation {
span: Span,
right: Box<Expression>,
},
}
}

View File

@ -110,116 +110,252 @@ fn for_precedence(state: &mut State, precedence: Precedence) -> ParseResult<Expr
}
_ => {
// FIXME: Hacky, should probably be refactored.
left = match kind {
TokenKind::Equals if state.current.kind == TokenKind::Ampersand => {
let amper_span = state.current.span;
state.next();
left =
match kind {
TokenKind::Equals if state.current.kind == TokenKind::Ampersand => {
let amper_span = state.current.span;
state.next();
// FIXME: You should only be allowed to assign a referencable variable,
// here, not any old expression.
let right = Box::new(for_precedence(state, rpred)?);
// FIXME: You should only be allowed to assign a referencable variable,
// here, not any old expression.
let right = Box::new(for_precedence(state, rpred)?);
Expression::AssignmentOperation(AssignmentOperation::Assign { left: Box::new(left), span, right: Box::new(Expression::Reference { span: amper_span, right }) })
}
TokenKind::Instanceof if state.current.kind == TokenKind::Self_ => {
if !state.has_class_scope {
return Err(ParseError::CannotFindTypeInCurrentScope(
state.current.kind.to_string(),
state.current.span,
));
Expression::AssignmentOperation(AssignmentOperation::Assign {
left: Box::new(left),
span,
right: Box::new(Expression::Reference {
span: amper_span,
right,
}),
})
}
TokenKind::Instanceof if state.current.kind == TokenKind::Self_ => {
if !state.has_class_scope {
return Err(ParseError::CannotFindTypeInCurrentScope(
state.current.kind.to_string(),
state.current.span,
));
}
state.next();
state.next();
Expression::Instanceof {
left: Box::new(left),
span,
right: Box::new(Expression::Self_),
}
}
TokenKind::Instanceof if state.current.kind == TokenKind::Parent => {
if !state.has_class_scope {
return Err(ParseError::CannotFindTypeInCurrentScope(
state.current.kind.to_string(),
state.current.span,
));
Expression::Instanceof {
left: Box::new(left),
span,
right: Box::new(Expression::Self_),
}
}
TokenKind::Instanceof if state.current.kind == TokenKind::Parent => {
if !state.has_class_scope {
return Err(ParseError::CannotFindTypeInCurrentScope(
state.current.kind.to_string(),
state.current.span,
));
}
state.next();
state.next();
Expression::Instanceof {
left: Box::new(left),
span,
right: Box::new(Expression::Self_),
}
}
TokenKind::Instanceof if state.current.kind == TokenKind::Static => {
if !state.has_class_scope {
return Err(ParseError::CannotFindTypeInCurrentScope(
state.current.kind.to_string(),
state.current.span,
));
Expression::Instanceof {
left: Box::new(left),
span,
right: Box::new(Expression::Self_),
}
}
TokenKind::Instanceof if state.current.kind == TokenKind::Static => {
if !state.has_class_scope {
return Err(ParseError::CannotFindTypeInCurrentScope(
state.current.kind.to_string(),
state.current.span,
));
}
state.next();
state.next();
Expression::Instanceof {
left: Box::new(left),
span,
right: Box::new(Expression::Self_),
Expression::Instanceof {
left: Box::new(left),
span,
right: Box::new(Expression::Self_),
}
}
}
_ => {
let left = Box::new(left);
let right = Box::new(for_precedence(state, rpred)?);
_ => {
let left = Box::new(left);
let right = Box::new(for_precedence(state, rpred)?);
match kind {
TokenKind::Plus => Expression::ArithmeticOperation(ArithmeticOperation::Addition { left, span, right }),
TokenKind::Minus => Expression::ArithmeticOperation(ArithmeticOperation::Subtraction { left, span, right }),
TokenKind::Asterisk => Expression::ArithmeticOperation(ArithmeticOperation::Multiplication { left, span, right }),
TokenKind::Slash => Expression::ArithmeticOperation(ArithmeticOperation::Division { left, span, right }),
TokenKind::Percent => Expression::ArithmeticOperation(ArithmeticOperation::Modulo { left, span, right }),
TokenKind::Pow => Expression::ArithmeticOperation(ArithmeticOperation::Exponentiation { left, span, right }),
TokenKind::Equals => Expression::AssignmentOperation(AssignmentOperation::Assign { left, span, right }),
TokenKind::PlusEquals => Expression::AssignmentOperation(AssignmentOperation::Addition { left, span, right }),
TokenKind::MinusEquals => Expression::AssignmentOperation(AssignmentOperation::Subtraction { left, span, right }),
TokenKind::AsteriskEqual => Expression::AssignmentOperation(AssignmentOperation::Multiplication { left, span, right }),
TokenKind::SlashEquals => Expression::AssignmentOperation(AssignmentOperation::Division { left, span, right }),
TokenKind::PercentEquals => Expression::AssignmentOperation(AssignmentOperation::Modulo { left, span, right }),
TokenKind::PowEquals => Expression::AssignmentOperation(AssignmentOperation::Exponentiation { left, span, right }),
TokenKind::AmpersandEquals => Expression::AssignmentOperation(AssignmentOperation::BitwiseAnd { left, span, right }),
TokenKind::PipeEquals => Expression::AssignmentOperation(AssignmentOperation::BitwiseOr { left, span, right }),
TokenKind::CaretEquals => Expression::AssignmentOperation(AssignmentOperation::BitwiseXor { left, span, right }),
TokenKind::LeftShiftEquals => Expression::AssignmentOperation(AssignmentOperation::LeftShift { left, span, right }),
TokenKind::RightShiftEquals => Expression::AssignmentOperation(AssignmentOperation::RightShift { left, span, right }),
TokenKind::CoalesceEqual => Expression::AssignmentOperation(AssignmentOperation::Coalesce { left, span, right }),
TokenKind::DotEquals => Expression::AssignmentOperation(AssignmentOperation::Concat { left, span, right }),
TokenKind::Ampersand => Expression::BitwiseOperation(BitwiseOperation::And { left, span, right }),
TokenKind::Pipe => Expression::BitwiseOperation(BitwiseOperation::Or { left, span, right }),
TokenKind::Caret => Expression::BitwiseOperation(BitwiseOperation::Xor { left, span, right }),
TokenKind::LeftShift => Expression::BitwiseOperation(BitwiseOperation::LeftShift { left, span, right }),
TokenKind::RightShift => Expression::BitwiseOperation(BitwiseOperation::RightShift { left, span, right }),
TokenKind::DoubleEquals => Expression::ComparisonOperation(ComparisonOperation::Equal { left, span, right }),
TokenKind::TripleEquals => Expression::ComparisonOperation(ComparisonOperation::Identical { left, span, right }),
TokenKind::BangEquals => Expression::ComparisonOperation(ComparisonOperation::NotEqual { left, span, right }),
TokenKind::AngledLeftRight => Expression::ComparisonOperation(ComparisonOperation::AngledNotEqual { left, span, right }),
TokenKind::BangDoubleEquals => Expression::ComparisonOperation(ComparisonOperation::NotIdentical { left, span, right }),
TokenKind::LessThan => Expression::ComparisonOperation(ComparisonOperation::LessThan { left, span, right }),
TokenKind::GreaterThan => Expression::ComparisonOperation(ComparisonOperation::GreaterThan { left, span, right }),
TokenKind::LessThanEquals => Expression::ComparisonOperation(ComparisonOperation::LessThanOrEqual { left, span, right }),
TokenKind::GreaterThanEquals => Expression::ComparisonOperation(ComparisonOperation::GreaterThanOrEqual { left, span, right }),
TokenKind::Spaceship => Expression::ComparisonOperation(ComparisonOperation::Spaceship { left, span, right }),
TokenKind::BooleanAnd => Expression::LogicalOperation(LogicalOperation::And { left, span, right }),
TokenKind::BooleanOr => Expression::LogicalOperation(LogicalOperation::Or { left, span, right }),
TokenKind::LogicalAnd => Expression::LogicalOperation(LogicalOperation::LogicalAnd { left, span, right }),
TokenKind::LogicalOr => Expression::LogicalOperation(LogicalOperation::LogicalOr { left, span, right }),
TokenKind::LogicalXor => Expression::LogicalOperation(LogicalOperation::LogicalXor { left, span, right }),
TokenKind::Dot => Expression::Concat { left, span, right },
TokenKind::Instanceof => Expression::Instanceof { left, span, right },
_ => todo!(),
match kind {
TokenKind::Plus => Expression::ArithmeticOperation(
ArithmeticOperation::Addition { left, span, right },
),
TokenKind::Minus => Expression::ArithmeticOperation(
ArithmeticOperation::Subtraction { left, span, right },
),
TokenKind::Asterisk => Expression::ArithmeticOperation(
ArithmeticOperation::Multiplication { left, span, right },
),
TokenKind::Slash => Expression::ArithmeticOperation(
ArithmeticOperation::Division { left, span, right },
),
TokenKind::Percent => Expression::ArithmeticOperation(
ArithmeticOperation::Modulo { left, span, right },
),
TokenKind::Pow => Expression::ArithmeticOperation(
ArithmeticOperation::Exponentiation { left, span, right },
),
TokenKind::Equals => Expression::AssignmentOperation(
AssignmentOperation::Assign { left, span, right },
),
TokenKind::PlusEquals => Expression::AssignmentOperation(
AssignmentOperation::Addition { left, span, right },
),
TokenKind::MinusEquals => Expression::AssignmentOperation(
AssignmentOperation::Subtraction { left, span, right },
),
TokenKind::AsteriskEqual => Expression::AssignmentOperation(
AssignmentOperation::Multiplication { left, span, right },
),
TokenKind::SlashEquals => Expression::AssignmentOperation(
AssignmentOperation::Division { left, span, right },
),
TokenKind::PercentEquals => Expression::AssignmentOperation(
AssignmentOperation::Modulo { left, span, right },
),
TokenKind::PowEquals => Expression::AssignmentOperation(
AssignmentOperation::Exponentiation { left, span, right },
),
TokenKind::AmpersandEquals => Expression::AssignmentOperation(
AssignmentOperation::BitwiseAnd { left, span, right },
),
TokenKind::PipeEquals => Expression::AssignmentOperation(
AssignmentOperation::BitwiseOr { left, span, right },
),
TokenKind::CaretEquals => Expression::AssignmentOperation(
AssignmentOperation::BitwiseXor { left, span, right },
),
TokenKind::LeftShiftEquals => Expression::AssignmentOperation(
AssignmentOperation::LeftShift { left, span, right },
),
TokenKind::RightShiftEquals => Expression::AssignmentOperation(
AssignmentOperation::RightShift { left, span, right },
),
TokenKind::CoalesceEqual => Expression::AssignmentOperation(
AssignmentOperation::Coalesce { left, span, right },
),
TokenKind::DotEquals => Expression::AssignmentOperation(
AssignmentOperation::Concat { left, span, right },
),
TokenKind::Ampersand => {
Expression::BitwiseOperation(BitwiseOperation::And {
left,
span,
right,
})
}
TokenKind::Pipe => {
Expression::BitwiseOperation(BitwiseOperation::Or {
left,
span,
right,
})
}
TokenKind::Caret => {
Expression::BitwiseOperation(BitwiseOperation::Xor {
left,
span,
right,
})
}
TokenKind::LeftShift => {
Expression::BitwiseOperation(BitwiseOperation::LeftShift {
left,
span,
right,
})
}
TokenKind::RightShift => {
Expression::BitwiseOperation(BitwiseOperation::RightShift {
left,
span,
right,
})
}
TokenKind::DoubleEquals => Expression::ComparisonOperation(
ComparisonOperation::Equal { left, span, right },
),
TokenKind::TripleEquals => Expression::ComparisonOperation(
ComparisonOperation::Identical { left, span, right },
),
TokenKind::BangEquals => Expression::ComparisonOperation(
ComparisonOperation::NotEqual { left, span, right },
),
TokenKind::AngledLeftRight => Expression::ComparisonOperation(
ComparisonOperation::AngledNotEqual { left, span, right },
),
TokenKind::BangDoubleEquals => Expression::ComparisonOperation(
ComparisonOperation::NotIdentical { left, span, right },
),
TokenKind::LessThan => Expression::ComparisonOperation(
ComparisonOperation::LessThan { left, span, right },
),
TokenKind::GreaterThan => Expression::ComparisonOperation(
ComparisonOperation::GreaterThan { left, span, right },
),
TokenKind::LessThanEquals => Expression::ComparisonOperation(
ComparisonOperation::LessThanOrEqual { left, span, right },
),
TokenKind::GreaterThanEquals => {
Expression::ComparisonOperation(
ComparisonOperation::GreaterThanOrEqual {
left,
span,
right,
},
)
}
TokenKind::Spaceship => Expression::ComparisonOperation(
ComparisonOperation::Spaceship { left, span, right },
),
TokenKind::BooleanAnd => {
Expression::LogicalOperation(LogicalOperation::And {
left,
span,
right,
})
}
TokenKind::BooleanOr => {
Expression::LogicalOperation(LogicalOperation::Or {
left,
span,
right,
})
}
TokenKind::LogicalAnd => {
Expression::LogicalOperation(LogicalOperation::LogicalAnd {
left,
span,
right,
})
}
TokenKind::LogicalOr => {
Expression::LogicalOperation(LogicalOperation::LogicalOr {
left,
span,
right,
})
}
TokenKind::LogicalXor => {
Expression::LogicalOperation(LogicalOperation::LogicalXor {
left,
span,
right,
})
}
TokenKind::Dot => Expression::Concat { left, span, right },
TokenKind::Instanceof => {
Expression::Instanceof { left, span, right }
}
_ => todo!(),
}
}
},
};
};
}
}
@ -982,13 +1118,19 @@ fn postfix(state: &mut State, lhs: Expression, op: &TokenKind) -> Result<Express
let span = state.current.span;
state.next();
Expression::ArithmeticOperation(ArithmeticOperation::PostIncrement { left: Box::new(lhs), span })
Expression::ArithmeticOperation(ArithmeticOperation::PostIncrement {
left: Box::new(lhs),
span,
})
}
TokenKind::Decrement => {
let span = state.current.span;
state.next();
Expression::ArithmeticOperation(ArithmeticOperation::PostDecrement { left: Box::new(lhs), span })
Expression::ArithmeticOperation(ArithmeticOperation::PostDecrement {
left: Box::new(lhs),
span,
})
}
_ => todo!("postfix: {:?}", op),
})