Skip to content

Commit faa420f

Browse files
committed
internal: prepare a dedicated module for all operators
1 parent beca92b commit faa420f

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

crates/syntax/src/ast.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod traits;
55
mod token_ext;
66
mod node_ext;
77
mod expr_ext;
8+
mod operators;
89
pub mod edit;
910
pub mod edit_in_place;
1011
pub mod make;
@@ -17,14 +18,21 @@ use crate::{
1718
};
1819

1920
pub use self::{
20-
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
21+
expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind},
2122
generated::{nodes::*, tokens::*},
2223
node_ext::{
2324
AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind,
2425
SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind,
2526
},
26-
token_ext::*,
27-
traits::*,
27+
operators::{PrefixOp, RangeOp},
28+
token_ext::{
29+
CommentKind, CommentPlacement, CommentShape, HasFormatSpecifier, IsString, QuoteOffsets,
30+
Radix,
31+
},
32+
traits::{
33+
ArgListOwner, AttrsOwner, CommentIter, DocCommentsOwner, GenericParamsOwner, LoopBodyOwner,
34+
ModuleItemOwner, NameOwner, TypeBoundsOwner, VisibilityOwner,
35+
},
2836
};
2937

3038
/// The main trait to go from untyped `SyntaxNode` to a typed ast. The

crates/syntax/src/ast/expr_ext.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
use rowan::WalkEvent;
44

55
use crate::{
6-
ast::{self, support, AstChildren, AstNode},
6+
ast::{
7+
self,
8+
operators::{PrefixOp, RangeOp},
9+
support, AstChildren, AstNode,
10+
},
711
AstToken,
812
SyntaxKind::*,
913
SyntaxToken, T,
@@ -193,24 +197,15 @@ impl ast::IfExpr {
193197
}
194198
}
195199

196-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
197-
pub enum PrefixOp {
198-
/// The `*` operator for dereferencing
199-
Deref,
200-
/// The `!` operator for logical inversion
201-
Not,
202-
/// The `-` operator for negation
203-
Neg,
204-
}
205-
206200
impl ast::PrefixExpr {
207201
pub fn op_kind(&self) -> Option<PrefixOp> {
208-
match self.op_token()?.kind() {
209-
T![*] => Some(PrefixOp::Deref),
210-
T![!] => Some(PrefixOp::Not),
211-
T![-] => Some(PrefixOp::Neg),
212-
_ => None,
213-
}
202+
let res = match self.op_token()?.kind() {
203+
T![*] => PrefixOp::Deref,
204+
T![!] => PrefixOp::Not,
205+
T![-] => PrefixOp::Neg,
206+
_ => return None,
207+
};
208+
Some(res)
214209
}
215210

216211
pub fn op_token(&self) -> Option<SyntaxToken> {
@@ -398,14 +393,6 @@ impl std::fmt::Display for BinOp {
398393
}
399394
}
400395

401-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
402-
pub enum RangeOp {
403-
/// `..`
404-
Exclusive,
405-
/// `..=`
406-
Inclusive,
407-
}
408-
409396
impl ast::RangeExpr {
410397
fn op_details(&self) -> Option<(usize, SyntaxToken, RangeOp)> {
411398
self.syntax().children_with_tokens().enumerate().find_map(|(ix, child)| {

crates/syntax/src/ast/operators.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
2+
pub enum PrefixOp {
3+
/// The `*` operator for dereferencing
4+
Deref,
5+
/// The `!` operator for logical inversion
6+
Not,
7+
/// The `-` operator for negation
8+
Neg,
9+
}
10+
11+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
12+
pub enum RangeOp {
13+
/// `..`
14+
Exclusive,
15+
/// `..=`
16+
Inclusive,
17+
}

0 commit comments

Comments
 (0)