Merge commit 'af40101841' into sync-from-ra

This commit is contained in:
Laurențiu Nicola 2024-01-08 11:29:25 +02:00
parent 79fa976864
commit 3afeb24198
115 changed files with 3106 additions and 3623 deletions

View file

@ -14,6 +14,8 @@ use crate::{
ted, NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
};
use super::{RangeItem, RangeOp};
impl ast::Lifetime {
pub fn text(&self) -> TokenText<'_> {
text_of_first_token(self.syntax())
@ -875,8 +877,10 @@ impl ast::Module {
}
}
impl ast::RangePat {
pub fn start(&self) -> Option<ast::Pat> {
impl RangeItem for ast::RangePat {
type Bound = ast::Pat;
fn start(&self) -> Option<ast::Pat> {
self.syntax()
.children_with_tokens()
.take_while(|it| !(it.kind() == T![..] || it.kind() == T![..=]))
@ -884,13 +888,37 @@ impl ast::RangePat {
.find_map(ast::Pat::cast)
}
pub fn end(&self) -> Option<ast::Pat> {
fn end(&self) -> Option<ast::Pat> {
self.syntax()
.children_with_tokens()
.skip_while(|it| !(it.kind() == T![..] || it.kind() == T![..=]))
.filter_map(|it| it.into_node())
.find_map(ast::Pat::cast)
}
fn op_token(&self) -> Option<SyntaxToken> {
self.syntax().children_with_tokens().find_map(|it| {
let token = it.into_token()?;
match token.kind() {
T![..] => Some(token),
T![..=] => Some(token),
_ => None,
}
})
}
fn op_kind(&self) -> Option<RangeOp> {
self.syntax().children_with_tokens().find_map(|it| {
let token = it.into_token()?;
match token.kind() {
T![..] => Some(RangeOp::Exclusive),
T![..=] => Some(RangeOp::Inclusive),
_ => None,
}
})
}
}
impl ast::TokenTree {