Replace ID based TokenMap with proper relative text-ranges / spans

This commit is contained in:
Lukas Wirth 2023-09-29 12:37:57 +02:00
parent f79439caed
commit 890eb17b4e
80 changed files with 1816 additions and 2046 deletions

View file

@ -7,6 +7,7 @@
use std::fmt;
use stdx::impl_from;
use text_size::{TextRange, TextSize};
pub use smol_str::SmolStr;
@ -31,36 +32,25 @@ impl TokenId {
Self::UNSPECIFIED
}
}
pub mod token_id {
pub use crate::{DelimiterKind, Spacing, TokenId};
pub type Span = crate::TokenId;
pub type Subtree = crate::Subtree<Span>;
pub type Punct = crate::Punct<Span>;
pub type Delimiter = crate::Delimiter<Span>;
pub type Leaf = crate::Leaf<Span>;
pub type Ident = crate::Ident<Span>;
pub type Literal = crate::Literal<Span>;
pub type TokenTree = crate::TokenTree<Span>;
pub mod buffer {
pub type TokenBuffer<'a> = crate::buffer::TokenBuffer<'a, super::Span>;
pub type Cursor<'a> = crate::buffer::Cursor<'a, super::Span>;
pub type TokenTreeRef<'a> = crate::buffer::TokenTreeRef<'a, super::Span>;
}
}
pub trait Span: std::fmt::Debug + Copy + Sized {
const DUMMY: Self;
fn is_dummy(&self) -> bool;
}
impl Span for TokenId {
const DUMMY: Self = TokenId(!0);
fn is_dummy(&self) -> bool {
*self == Self::DUMMY
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct SpanData<Anchor> {
/// The text range of this span, relative to the anchor.
pub range: TextRange,
pub anchor: Anchor,
}
impl<Anchor: Span> Span for SpanData<Anchor> {
const DUMMY: Self =
SpanData { range: TextRange::empty(TextSize::new(0)), anchor: Anchor::DUMMY };
}
pub trait Span: std::fmt::Debug + Copy + Sized + Eq {
const DUMMY: Self;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct SyntaxContext(pub u32);
@ -134,7 +124,6 @@ impl<S: Span> Delimiter<S> {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DelimiterKind {
Parenthesis,