Implement type inference for boolean operators
This commit is contained in:
@@ -488,6 +488,45 @@ impl<'a> PrefixExpr<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum BinOp {
|
||||
/// The `||` operator for boolean OR
|
||||
BooleanOr,
|
||||
/// The `&&` operator for boolean AND
|
||||
BooleanAnd,
|
||||
/// The `==` operator for equality testing
|
||||
EqualityTest,
|
||||
/// The `<=` operator for lesser-equal testing
|
||||
LesserEqualTest,
|
||||
/// The `>=` operator for greater-equal testing
|
||||
GreaterEqualTest,
|
||||
/// The `<` operator for comparison
|
||||
LesserTest,
|
||||
/// The `>` operator for comparison
|
||||
GreaterTest,
|
||||
// TODO: lots of others
|
||||
}
|
||||
|
||||
impl<'a> BinExpr<'a> {
|
||||
pub fn op(&self) -> Option<BinOp> {
|
||||
self.syntax()
|
||||
.children()
|
||||
.filter_map(|c| {
|
||||
match c.kind() {
|
||||
PIPEPIPE => Some(BinOp::BooleanOr),
|
||||
AMPAMP => Some(BinOp::BooleanAnd),
|
||||
EQEQ => Some(BinOp::EqualityTest),
|
||||
LTEQ => Some(BinOp::LesserEqualTest),
|
||||
GTEQ => Some(BinOp::GreaterEqualTest),
|
||||
L_ANGLE => Some(BinOp::LesserTest),
|
||||
R_ANGLE => Some(BinOp::GreaterTest),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum SelfParamFlavor {
|
||||
/// self
|
||||
|
||||
@@ -217,7 +217,15 @@ impl<R: TreeRoot<RaTypes>> BinExprNode<R> {
|
||||
}
|
||||
|
||||
|
||||
impl<'a> BinExpr<'a> {}
|
||||
impl<'a> BinExpr<'a> {
|
||||
pub fn lhs(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn rhs(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
||||
// BindPat
|
||||
#[derive(Debug, Clone, Copy,)]
|
||||
|
||||
@@ -422,7 +422,12 @@ Grammar(
|
||||
"RefExpr": (options: ["Expr"]),
|
||||
"PrefixExpr": (options: ["Expr"]),
|
||||
"RangeExpr": (),
|
||||
"BinExpr": (),
|
||||
"BinExpr": (
|
||||
options: [
|
||||
["lhs", "Expr"],
|
||||
["rhs", "Expr"]
|
||||
]
|
||||
),
|
||||
"String": (),
|
||||
"Byte": (),
|
||||
"ByteString": (),
|
||||
|
||||
Reference in New Issue
Block a user