internal: prepare a dedicated module for all operators

This commit is contained in:
Aleksey Kladov 2021-08-14 16:58:46 +03:00
parent beca92b245
commit faa420fc32
3 changed files with 40 additions and 28 deletions

View file

@ -3,7 +3,11 @@
use rowan::WalkEvent;
use crate::{
ast::{self, support, AstChildren, AstNode},
ast::{
self,
operators::{PrefixOp, RangeOp},
support, AstChildren, AstNode,
},
AstToken,
SyntaxKind::*,
SyntaxToken, T,
@ -193,24 +197,15 @@ impl ast::IfExpr {
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum PrefixOp {
/// The `*` operator for dereferencing
Deref,
/// The `!` operator for logical inversion
Not,
/// The `-` operator for negation
Neg,
}
impl ast::PrefixExpr {
pub fn op_kind(&self) -> Option<PrefixOp> {
match self.op_token()?.kind() {
T![*] => Some(PrefixOp::Deref),
T![!] => Some(PrefixOp::Not),
T![-] => Some(PrefixOp::Neg),
_ => None,
}
let res = match self.op_token()?.kind() {
T![*] => PrefixOp::Deref,
T![!] => PrefixOp::Not,
T![-] => PrefixOp::Neg,
_ => return None,
};
Some(res)
}
pub fn op_token(&self) -> Option<SyntaxToken> {
@ -398,14 +393,6 @@ impl std::fmt::Display for BinOp {
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum RangeOp {
/// `..`
Exclusive,
/// `..=`
Inclusive,
}
impl ast::RangeExpr {
fn op_details(&self) -> Option<(usize, SyntaxToken, RangeOp)> {
self.syntax().children_with_tokens().enumerate().find_map(|(ix, child)| {