From 3238c06a5a122b7e7b9b6871484c700b7947fae1 Mon Sep 17 00:00:00 2001 From: Marcus Klaas de Vries Date: Mon, 7 Jan 2019 19:03:25 +0100 Subject: Add remaining binary operations to AST --- crates/ra_hir/src/ty.rs | 1 + crates/ra_syntax/src/ast.rs | 70 +++++++++++++++++++++++++- crates/ra_syntax/src/grammar.ron | 1 + crates/ra_syntax/src/syntax_kinds/generated.rs | 2 + 4 files changed, 73 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index bba8527b7..23ee76f4e 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -538,6 +538,7 @@ fn is_boolean_operator(op: BinaryOp) -> bool { | BinaryOp::GreaterEqualTest | BinaryOp::LesserTest | BinaryOp::GreaterTest => true, + _ => false, } } diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 9df8ec663..d8e187514 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -504,7 +504,52 @@ pub enum BinOp { LesserTest, /// The `>` operator for comparison GreaterTest, - // TODO: lots of others + /// The `+` operator for addition + Addition, + /// The `*` operator for multiplication + Multiplication, + /// The `-` operator for subtraction + Subtraction, + /// The `/` operator for division + Division, + /// The `%` operator for remainder after division + Remainder, + /// The `<<` operator for left shift + LeftShift, + /// The `>>` operator for right shift + RightShift, + /// The `^` operator for bitwise XOR + BitwiseXor, + /// The `|` operator for bitwise OR + BitwiseOr, + /// The `&` operator for bitwise AND + BitwiseAnd, + /// The `..` operator for right-open ranges + RangeRightOpen, + /// The `..=` operator for right-closed ranges + RangeRightClosed, + /// The `=` operator for assignment + Assignment, + /// The `+=` operator for assignment after additon + AddAssign, + /// The `/=` operator for assignment after division + DivAssign, + /// The `*=` operator for assignment after multiplication + MulAssign, + /// The `%=` operator for assignment after remainders + RemAssign, + /// The `>>=` operator for assignment after shifting right + ShrAssign, + /// The `<<=` operator for assignment after shifting left + ShlAssign, + /// The `-=` operator for assignment after subtraction + SubAssign, + /// The `|=` operator for assignment after bitwise OR + BitOrAssign, + /// The `&=` operator for assignment after bitwise AND + BitAndAssign, + /// The `^=` operator for assignment after bitwise XOR + BitXorAssin, } impl<'a> BinExpr<'a> { @@ -519,6 +564,29 @@ impl<'a> BinExpr<'a> { GTEQ => Some(BinOp::GreaterEqualTest), L_ANGLE => Some(BinOp::LesserTest), R_ANGLE => Some(BinOp::GreaterTest), + PLUS => Some(BinOp::Addition), + STAR => Some(BinOp::Multiplication), + MINUS => Some(BinOp::Subtraction), + SLASH => Some(BinOp::Division), + PERCENT => Some(BinOp::Remainder), + SHL => Some(BinOp::LeftShift), + SHR => Some(BinOp::RightShift), + CARET => Some(BinOp::BitwiseXor), + PIPE => Some(BinOp::BitwiseOr), + AMP => Some(BinOp::BitwiseAnd), + DOTDOT => Some(BinOp::RangeRightOpen), + DOTDOTEQ => Some(BinOp::RangeRightClosed), + EQ => Some(BinOp::Assignment), + PLUSEQ => Some(BinOp::AddAssign), + SLASHEQ => Some(BinOp::DivAssign), + STAREQ => Some(BinOp::MulAssign), + PERCENTEQ => Some(BinOp::RemAssign), + SHREQ => Some(BinOp::ShrAssign), + SHLEQ => Some(BinOp::ShlAssign), + MINUSEQ => Some(BinOp::SubAssign), + PIPEEQ => Some(BinOp::BitOrAssign), + AMPEQ => Some(BinOp::BitAndAssign), + CARETEQ => Some(BinOp::BitXorAssin), _ => None, }) .next() diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 3c640ed47..d7505ea06 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -49,6 +49,7 @@ Grammar( ["^=", "CARETEQ"], ["/=", "SLASHEQ"], ["*=", "STAREQ"], + ["%=", "PERCENTEQ"], ["&&", "AMPAMP"], ["||", "PIPEPIPE"], ["<<", "SHL"], diff --git a/crates/ra_syntax/src/syntax_kinds/generated.rs b/crates/ra_syntax/src/syntax_kinds/generated.rs index ef4588d93..830fac9f4 100644 --- a/crates/ra_syntax/src/syntax_kinds/generated.rs +++ b/crates/ra_syntax/src/syntax_kinds/generated.rs @@ -58,6 +58,7 @@ pub enum SyntaxKind { CARETEQ, SLASHEQ, STAREQ, + PERCENTEQ, AMPAMP, PIPEPIPE, SHL, @@ -319,6 +320,7 @@ impl SyntaxKind { CARETEQ => &SyntaxInfo { name: "CARETEQ" }, SLASHEQ => &SyntaxInfo { name: "SLASHEQ" }, STAREQ => &SyntaxInfo { name: "STAREQ" }, + PERCENTEQ => &SyntaxInfo { name: "PERCENTEQ" }, AMPAMP => &SyntaxInfo { name: "AMPAMP" }, PIPEPIPE => &SyntaxInfo { name: "PIPEPIPE" }, SHL => &SyntaxInfo { name: "SHL" }, -- cgit v1.2.3