Skip to content

Commit

Permalink
Support AssignOr and AssignAnd
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed Jul 11, 2021
1 parent 85c084f commit 1b0ccf0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl ModulePath {
}
}

impl <'a> IntoIterator for &'a ModulePath {
impl<'a> IntoIterator for &'a ModulePath {
type Item = &'a Ident;

type IntoIter = std::slice::Iter<'a, Ident>;
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ peg::parser! {
x:@ _ pos:pos() "-=" _ y:(@) { Expr::BinOp(Box::new(x), Box::new(y), BinOp::AssignSubtract, pos) }
x:@ _ pos:pos() "*=" _ y:(@) { Expr::BinOp(Box::new(x), Box::new(y), BinOp::AssignMultiply, pos) }
x:@ _ pos:pos() "/=" _ y:(@) { Expr::BinOp(Box::new(x), Box::new(y), BinOp::AssignDivide, pos) }
x:@ _ pos:pos() "|=" _ y:(@) { Expr::BinOp(Box::new(x), Box::new(y), BinOp::AssignOr, pos) }
x:@ _ pos:pos() "&=" _ y:(@) { Expr::BinOp(Box::new(x), Box::new(y), BinOp::AssignAnd, pos) }
--
x:(@) _ pos:pos() "||" _ y:@ { Expr::BinOp(Box::new(x), Box::new(y), BinOp::LogicOr, pos) }
x:(@) _ pos:pos() "&&" _ y:@ { Expr::BinOp(Box::new(x), Box::new(y), BinOp::LogicAnd, pos) }
Expand Down
8 changes: 8 additions & 0 deletions core/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ pub enum BinOp {
AssignMultiply,
#[strum(serialize = "OperatorAssignDivide")]
AssignDivide,
#[strum(serialize = "OperatorAssignOr")]
AssignOr,
#[strum(serialize = "OperatorAssignAnd")]
AssignAnd,
#[strum(serialize = "OperatorLogicOr")]
LogicOr,
#[strum(serialize = "OperatorLogicAnd")]
Expand Down Expand Up @@ -197,6 +201,8 @@ impl BinOp {
BinOp::AssignSubtract => 10,
BinOp::AssignMultiply => 10,
BinOp::AssignDivide => 10,
BinOp::AssignOr => 10,
BinOp::AssignAnd => 10,
BinOp::LogicOr => 9,
BinOp::LogicAnd => 8,
BinOp::Or => 7,
Expand All @@ -222,6 +228,8 @@ impl BinOp {
BinOp::AssignSubtract => false,
BinOp::AssignMultiply => false,
BinOp::AssignDivide => false,
BinOp::AssignOr => false,
BinOp::AssignAnd => false,
BinOp::LogicOr => true,
BinOp::LogicAnd => true,
BinOp::Or => true,
Expand Down
2 changes: 2 additions & 0 deletions decompiler/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ fn format_binop(op: BinOp) -> &'static str {
BinOp::AssignSubtract => "-=",
BinOp::AssignMultiply => "*=",
BinOp::AssignDivide => "/=",
BinOp::AssignOr => "|=",
BinOp::AssignAnd => "&=",
BinOp::LogicOr => "||",
BinOp::LogicAnd => "&&",
BinOp::Or => "|",
Expand Down

1 comment on commit 1b0ccf0

@flibdev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.