mirror of
https://github.com/danog/parser.git
synced 2024-11-30 04:29:13 +01:00
parser: workaround for assignment by ref
This commit is contained in:
parent
e8b58ba52b
commit
d71600ee65
@ -833,6 +833,7 @@ pub enum InfixOp {
|
|||||||
And,
|
And,
|
||||||
Or,
|
Or,
|
||||||
Assign,
|
Assign,
|
||||||
|
AssignRef,
|
||||||
AddAssign,
|
AddAssign,
|
||||||
Pow,
|
Pow,
|
||||||
Instanceof,
|
Instanceof,
|
||||||
|
@ -1353,8 +1353,15 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
// FIXME: Hacky, should probably be refactored.
|
||||||
|
let by_ref = kind == TokenKind::Equals && state.current.kind == TokenKind::Ampersand;
|
||||||
|
if by_ref {
|
||||||
|
state.next();
|
||||||
|
}
|
||||||
|
|
||||||
let rhs = self.expression(state, rpred)?;
|
let rhs = self.expression(state, rpred)?;
|
||||||
left = infix(left, kind, rhs);
|
|
||||||
|
left = infix(left, kind, rhs, by_ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1853,10 +1860,13 @@ fn prefix(op: &TokenKind, rhs: Expression) -> Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infix(lhs: Expression, op: TokenKind, rhs: Expression) -> Expression {
|
fn infix(lhs: Expression, op: TokenKind, rhs: Expression, by_ref: bool) -> Expression {
|
||||||
Expression::Infix {
|
Expression::Infix {
|
||||||
lhs: Box::new(lhs),
|
lhs: Box::new(lhs),
|
||||||
op: op.into(),
|
op: match (&op, by_ref) {
|
||||||
|
(TokenKind::Equals, true) => ast::InfixOp::AssignRef,
|
||||||
|
_ => op.into()
|
||||||
|
},
|
||||||
rhs: Box::new(rhs),
|
rhs: Box::new(rhs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user