mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-07 14:13:47 +00:00
internal: prepare a dedicated module for all operators
This commit is contained in:
parent
beca92b245
commit
faa420fc32
@ -5,6 +5,7 @@ mod traits;
|
|||||||
mod token_ext;
|
mod token_ext;
|
||||||
mod node_ext;
|
mod node_ext;
|
||||||
mod expr_ext;
|
mod expr_ext;
|
||||||
|
mod operators;
|
||||||
pub mod edit;
|
pub mod edit;
|
||||||
pub mod edit_in_place;
|
pub mod edit_in_place;
|
||||||
pub mod make;
|
pub mod make;
|
||||||
@ -17,14 +18,21 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
|
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind},
|
||||||
generated::{nodes::*, tokens::*},
|
generated::{nodes::*, tokens::*},
|
||||||
node_ext::{
|
node_ext::{
|
||||||
AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind,
|
AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind,
|
||||||
SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
|
SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
|
||||||
},
|
},
|
||||||
token_ext::*,
|
operators::{PrefixOp, RangeOp},
|
||||||
traits::*,
|
token_ext::{
|
||||||
|
CommentKind, CommentPlacement, CommentShape, HasFormatSpecifier, IsString, QuoteOffsets,
|
||||||
|
Radix,
|
||||||
|
},
|
||||||
|
traits::{
|
||||||
|
ArgListOwner, AttrsOwner, CommentIter, DocCommentsOwner, GenericParamsOwner, LoopBodyOwner,
|
||||||
|
ModuleItemOwner, NameOwner, TypeBoundsOwner, VisibilityOwner,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
|
/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
use rowan::WalkEvent;
|
use rowan::WalkEvent;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{self, support, AstChildren, AstNode},
|
ast::{
|
||||||
|
self,
|
||||||
|
operators::{PrefixOp, RangeOp},
|
||||||
|
support, AstChildren, AstNode,
|
||||||
|
},
|
||||||
AstToken,
|
AstToken,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
SyntaxToken, T,
|
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 {
|
impl ast::PrefixExpr {
|
||||||
pub fn op_kind(&self) -> Option<PrefixOp> {
|
pub fn op_kind(&self) -> Option<PrefixOp> {
|
||||||
match self.op_token()?.kind() {
|
let res = match self.op_token()?.kind() {
|
||||||
T![*] => Some(PrefixOp::Deref),
|
T![*] => PrefixOp::Deref,
|
||||||
T![!] => Some(PrefixOp::Not),
|
T![!] => PrefixOp::Not,
|
||||||
T![-] => Some(PrefixOp::Neg),
|
T![-] => PrefixOp::Neg,
|
||||||
_ => None,
|
_ => return None,
|
||||||
}
|
};
|
||||||
|
Some(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn op_token(&self) -> Option<SyntaxToken> {
|
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 {
|
impl ast::RangeExpr {
|
||||||
fn op_details(&self) -> Option<(usize, SyntaxToken, RangeOp)> {
|
fn op_details(&self) -> Option<(usize, SyntaxToken, RangeOp)> {
|
||||||
self.syntax().children_with_tokens().enumerate().find_map(|(ix, child)| {
|
self.syntax().children_with_tokens().enumerate().find_map(|(ix, child)| {
|
||||||
|
17
crates/syntax/src/ast/operators.rs
Normal file
17
crates/syntax/src/ast/operators.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#[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,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub enum RangeOp {
|
||||||
|
/// `..`
|
||||||
|
Exclusive,
|
||||||
|
/// `..=`
|
||||||
|
Inclusive,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user