mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
chore: fmt
This commit is contained in:
parent
0ee981aed6
commit
df45b9f034
@ -7,11 +7,11 @@ pub mod functions;
|
|||||||
pub mod identifiers;
|
pub mod identifiers;
|
||||||
pub mod interfaces;
|
pub mod interfaces;
|
||||||
pub mod modifiers;
|
pub mod modifiers;
|
||||||
|
pub mod operators;
|
||||||
pub mod properties;
|
pub mod properties;
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
pub mod try_block;
|
pub mod try_block;
|
||||||
pub mod variables;
|
pub mod variables;
|
||||||
pub mod operators;
|
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
@ -588,9 +588,7 @@ pub struct ListItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum InfixOp {
|
pub enum InfixOp {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TokenKind> for InfixOp {
|
impl From<TokenKind> for InfixOp {
|
||||||
fn from(k: TokenKind) -> Self {
|
fn from(k: TokenKind) -> Self {
|
||||||
|
@ -131,7 +131,7 @@ pub enum AssignmentOperation {
|
|||||||
left: Box<Expression>,
|
left: Box<Expression>,
|
||||||
span: Span,
|
span: Span,
|
||||||
right: Box<Expression>,
|
right: Box<Expression>,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@ -164,7 +164,7 @@ pub enum BitwiseOperation {
|
|||||||
Not {
|
Not {
|
||||||
span: Span,
|
span: Span,
|
||||||
right: Box<Expression>,
|
right: Box<Expression>,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@ -218,7 +218,7 @@ pub enum ComparisonOperation {
|
|||||||
left: Box<Expression>,
|
left: Box<Expression>,
|
||||||
span: Span,
|
span: Span,
|
||||||
right: Box<Expression>,
|
right: Box<Expression>,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@ -252,4 +252,4 @@ pub enum LogicalOperation {
|
|||||||
span: Span,
|
span: Span,
|
||||||
right: Box<Expression>,
|
right: Box<Expression>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -110,116 +110,252 @@ fn for_precedence(state: &mut State, precedence: Precedence) -> ParseResult<Expr
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// FIXME: Hacky, should probably be refactored.
|
// FIXME: Hacky, should probably be refactored.
|
||||||
left = match kind {
|
left =
|
||||||
TokenKind::Equals if state.current.kind == TokenKind::Ampersand => {
|
match kind {
|
||||||
let amper_span = state.current.span;
|
TokenKind::Equals if state.current.kind == TokenKind::Ampersand => {
|
||||||
state.next();
|
let amper_span = state.current.span;
|
||||||
|
state.next();
|
||||||
|
|
||||||
// FIXME: You should only be allowed to assign a referencable variable,
|
// FIXME: You should only be allowed to assign a referencable variable,
|
||||||
// here, not any old expression.
|
// here, not any old expression.
|
||||||
let right = Box::new(for_precedence(state, rpred)?);
|
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 }) })
|
Expression::AssignmentOperation(AssignmentOperation::Assign {
|
||||||
}
|
left: Box::new(left),
|
||||||
TokenKind::Instanceof if state.current.kind == TokenKind::Self_ => {
|
span,
|
||||||
if !state.has_class_scope {
|
right: Box::new(Expression::Reference {
|
||||||
return Err(ParseError::CannotFindTypeInCurrentScope(
|
span: amper_span,
|
||||||
state.current.kind.to_string(),
|
right,
|
||||||
state.current.span,
|
}),
|
||||||
));
|
})
|
||||||
}
|
}
|
||||||
|
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 {
|
Expression::Instanceof {
|
||||||
left: Box::new(left),
|
left: Box::new(left),
|
||||||
span,
|
span,
|
||||||
right: Box::new(Expression::Self_),
|
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,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
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 {
|
Expression::Instanceof {
|
||||||
left: Box::new(left),
|
left: Box::new(left),
|
||||||
span,
|
span,
|
||||||
right: Box::new(Expression::Self_),
|
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,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
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 {
|
Expression::Instanceof {
|
||||||
left: Box::new(left),
|
left: Box::new(left),
|
||||||
span,
|
span,
|
||||||
right: Box::new(Expression::Self_),
|
right: Box::new(Expression::Self_),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
_ => {
|
||||||
_ => {
|
let left = Box::new(left);
|
||||||
let left = Box::new(left);
|
let right = Box::new(for_precedence(state, rpred)?);
|
||||||
let right = Box::new(for_precedence(state, rpred)?);
|
|
||||||
|
|
||||||
match kind {
|
match kind {
|
||||||
TokenKind::Plus => Expression::ArithmeticOperation(ArithmeticOperation::Addition { left, span, right }),
|
TokenKind::Plus => Expression::ArithmeticOperation(
|
||||||
TokenKind::Minus => Expression::ArithmeticOperation(ArithmeticOperation::Subtraction { left, span, right }),
|
ArithmeticOperation::Addition { left, span, right },
|
||||||
TokenKind::Asterisk => Expression::ArithmeticOperation(ArithmeticOperation::Multiplication { left, span, right }),
|
),
|
||||||
TokenKind::Slash => Expression::ArithmeticOperation(ArithmeticOperation::Division { left, span, right }),
|
TokenKind::Minus => Expression::ArithmeticOperation(
|
||||||
TokenKind::Percent => Expression::ArithmeticOperation(ArithmeticOperation::Modulo { left, span, right }),
|
ArithmeticOperation::Subtraction { left, span, right },
|
||||||
TokenKind::Pow => Expression::ArithmeticOperation(ArithmeticOperation::Exponentiation { left, span, right }),
|
),
|
||||||
TokenKind::Equals => Expression::AssignmentOperation(AssignmentOperation::Assign { left, span, right }),
|
TokenKind::Asterisk => Expression::ArithmeticOperation(
|
||||||
TokenKind::PlusEquals => Expression::AssignmentOperation(AssignmentOperation::Addition { left, span, right }),
|
ArithmeticOperation::Multiplication { left, span, right },
|
||||||
TokenKind::MinusEquals => Expression::AssignmentOperation(AssignmentOperation::Subtraction { left, span, right }),
|
),
|
||||||
TokenKind::AsteriskEqual => Expression::AssignmentOperation(AssignmentOperation::Multiplication { left, span, right }),
|
TokenKind::Slash => Expression::ArithmeticOperation(
|
||||||
TokenKind::SlashEquals => Expression::AssignmentOperation(AssignmentOperation::Division { left, span, right }),
|
ArithmeticOperation::Division { left, span, right },
|
||||||
TokenKind::PercentEquals => Expression::AssignmentOperation(AssignmentOperation::Modulo { left, span, right }),
|
),
|
||||||
TokenKind::PowEquals => Expression::AssignmentOperation(AssignmentOperation::Exponentiation { left, span, right }),
|
TokenKind::Percent => Expression::ArithmeticOperation(
|
||||||
TokenKind::AmpersandEquals => Expression::AssignmentOperation(AssignmentOperation::BitwiseAnd { left, span, right }),
|
ArithmeticOperation::Modulo { left, span, right },
|
||||||
TokenKind::PipeEquals => Expression::AssignmentOperation(AssignmentOperation::BitwiseOr { left, span, right }),
|
),
|
||||||
TokenKind::CaretEquals => Expression::AssignmentOperation(AssignmentOperation::BitwiseXor { left, span, right }),
|
TokenKind::Pow => Expression::ArithmeticOperation(
|
||||||
TokenKind::LeftShiftEquals => Expression::AssignmentOperation(AssignmentOperation::LeftShift { left, span, right }),
|
ArithmeticOperation::Exponentiation { left, span, right },
|
||||||
TokenKind::RightShiftEquals => Expression::AssignmentOperation(AssignmentOperation::RightShift { left, span, right }),
|
),
|
||||||
TokenKind::CoalesceEqual => Expression::AssignmentOperation(AssignmentOperation::Coalesce { left, span, right }),
|
TokenKind::Equals => Expression::AssignmentOperation(
|
||||||
TokenKind::DotEquals => Expression::AssignmentOperation(AssignmentOperation::Concat { left, span, right }),
|
AssignmentOperation::Assign { left, span, right },
|
||||||
TokenKind::Ampersand => Expression::BitwiseOperation(BitwiseOperation::And { left, span, right }),
|
),
|
||||||
TokenKind::Pipe => Expression::BitwiseOperation(BitwiseOperation::Or { left, span, right }),
|
TokenKind::PlusEquals => Expression::AssignmentOperation(
|
||||||
TokenKind::Caret => Expression::BitwiseOperation(BitwiseOperation::Xor { left, span, right }),
|
AssignmentOperation::Addition { left, span, right },
|
||||||
TokenKind::LeftShift => Expression::BitwiseOperation(BitwiseOperation::LeftShift { left, span, right }),
|
),
|
||||||
TokenKind::RightShift => Expression::BitwiseOperation(BitwiseOperation::RightShift { left, span, right }),
|
TokenKind::MinusEquals => Expression::AssignmentOperation(
|
||||||
TokenKind::DoubleEquals => Expression::ComparisonOperation(ComparisonOperation::Equal { left, span, right }),
|
AssignmentOperation::Subtraction { left, span, right },
|
||||||
TokenKind::TripleEquals => Expression::ComparisonOperation(ComparisonOperation::Identical { left, span, right }),
|
),
|
||||||
TokenKind::BangEquals => Expression::ComparisonOperation(ComparisonOperation::NotEqual { left, span, right }),
|
TokenKind::AsteriskEqual => Expression::AssignmentOperation(
|
||||||
TokenKind::AngledLeftRight => Expression::ComparisonOperation(ComparisonOperation::AngledNotEqual { left, span, right }),
|
AssignmentOperation::Multiplication { left, span, right },
|
||||||
TokenKind::BangDoubleEquals => Expression::ComparisonOperation(ComparisonOperation::NotIdentical { left, span, right }),
|
),
|
||||||
TokenKind::LessThan => Expression::ComparisonOperation(ComparisonOperation::LessThan { left, span, right }),
|
TokenKind::SlashEquals => Expression::AssignmentOperation(
|
||||||
TokenKind::GreaterThan => Expression::ComparisonOperation(ComparisonOperation::GreaterThan { left, span, right }),
|
AssignmentOperation::Division { left, span, right },
|
||||||
TokenKind::LessThanEquals => Expression::ComparisonOperation(ComparisonOperation::LessThanOrEqual { left, span, right }),
|
),
|
||||||
TokenKind::GreaterThanEquals => Expression::ComparisonOperation(ComparisonOperation::GreaterThanOrEqual { left, span, right }),
|
TokenKind::PercentEquals => Expression::AssignmentOperation(
|
||||||
TokenKind::Spaceship => Expression::ComparisonOperation(ComparisonOperation::Spaceship { left, span, right }),
|
AssignmentOperation::Modulo { left, span, right },
|
||||||
TokenKind::BooleanAnd => Expression::LogicalOperation(LogicalOperation::And { left, span, right }),
|
),
|
||||||
TokenKind::BooleanOr => Expression::LogicalOperation(LogicalOperation::Or { left, span, right }),
|
TokenKind::PowEquals => Expression::AssignmentOperation(
|
||||||
TokenKind::LogicalAnd => Expression::LogicalOperation(LogicalOperation::LogicalAnd { left, span, right }),
|
AssignmentOperation::Exponentiation { left, span, right },
|
||||||
TokenKind::LogicalOr => Expression::LogicalOperation(LogicalOperation::LogicalOr { left, span, right }),
|
),
|
||||||
TokenKind::LogicalXor => Expression::LogicalOperation(LogicalOperation::LogicalXor { left, span, right }),
|
TokenKind::AmpersandEquals => Expression::AssignmentOperation(
|
||||||
TokenKind::Dot => Expression::Concat { left, span, right },
|
AssignmentOperation::BitwiseAnd { left, span, right },
|
||||||
TokenKind::Instanceof => Expression::Instanceof { left, span, right },
|
),
|
||||||
_ => todo!(),
|
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;
|
let span = state.current.span;
|
||||||
state.next();
|
state.next();
|
||||||
|
|
||||||
Expression::ArithmeticOperation(ArithmeticOperation::PostIncrement { left: Box::new(lhs), span })
|
Expression::ArithmeticOperation(ArithmeticOperation::PostIncrement {
|
||||||
|
left: Box::new(lhs),
|
||||||
|
span,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
TokenKind::Decrement => {
|
TokenKind::Decrement => {
|
||||||
let span = state.current.span;
|
let span = state.current.span;
|
||||||
state.next();
|
state.next();
|
||||||
|
|
||||||
Expression::ArithmeticOperation(ArithmeticOperation::PostDecrement { left: Box::new(lhs), span })
|
Expression::ArithmeticOperation(ArithmeticOperation::PostDecrement {
|
||||||
|
left: Box::new(lhs),
|
||||||
|
span,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
_ => todo!("postfix: {:?}", op),
|
_ => todo!("postfix: {:?}", op),
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user