Skip to content

Commit 3b5b988

Browse files
committed
prettyfy
1 parent 980dd56 commit 3b5b988

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

crates/parser/src/tokens.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ pub struct Tokens {
1818
contextual_kind: Vec<SyntaxKind>,
1919
}
2020

21+
/// `pub` impl used by callers to create `Tokens`.
2122
impl Tokens {
2223
#[inline]
2324
pub fn push(&mut self, kind: SyntaxKind) {
2425
self.push_impl(kind, SyntaxKind::EOF)
2526
}
27+
#[inline]
28+
pub fn push_ident(&mut self, contextual_kind: SyntaxKind) {
29+
self.push_impl(SyntaxKind::IDENT, contextual_kind)
30+
}
2631
/// Sets jointness for the last token we've pushed.
2732
///
2833
/// This is a separate API rather than an argument to the `push` to make it
@@ -41,11 +46,9 @@ impl Tokens {
4146
/// ```
4247
#[inline]
4348
pub fn was_joint(&mut self) {
44-
self.set_joint(self.len() - 1);
45-
}
46-
#[inline]
47-
pub fn push_ident(&mut self, contextual_kind: SyntaxKind) {
48-
self.push_impl(SyntaxKind::IDENT, contextual_kind)
49+
let n = self.len() - 1;
50+
let (idx, b_idx) = self.bit_index(n);
51+
self.joint[idx] |= 1 << b_idx;
4952
}
5053
#[inline]
5154
fn push_impl(&mut self, kind: SyntaxKind, contextual_kind: SyntaxKind) {
@@ -56,22 +59,9 @@ impl Tokens {
5659
self.kind.push(kind);
5760
self.contextual_kind.push(contextual_kind);
5861
}
59-
fn set_joint(&mut self, n: usize) {
60-
let (idx, b_idx) = self.bit_index(n);
61-
self.joint[idx] |= 1 << b_idx;
62-
}
63-
fn bit_index(&self, n: usize) -> (usize, usize) {
64-
let idx = n / (bits::BITS as usize);
65-
let b_idx = n % (bits::BITS as usize);
66-
(idx, b_idx)
67-
}
68-
69-
fn len(&self) -> usize {
70-
self.kind.len()
71-
}
7262
}
7363

74-
/// pub(crate) impl used by the parser.
64+
/// pub(crate) impl used by the parser to consume `Tokens`.
7565
impl Tokens {
7666
pub(crate) fn kind(&self, idx: usize) -> SyntaxKind {
7767
self.kind.get(idx).copied().unwrap_or(SyntaxKind::EOF)
@@ -84,3 +74,14 @@ impl Tokens {
8474
self.joint[idx] & 1 << b_idx != 0
8575
}
8676
}
77+
78+
impl Tokens {
79+
fn bit_index(&self, n: usize) -> (usize, usize) {
80+
let idx = n / (bits::BITS as usize);
81+
let b_idx = n % (bits::BITS as usize);
82+
(idx, b_idx)
83+
}
84+
fn len(&self) -> usize {
85+
self.kind.len()
86+
}
87+
}

0 commit comments

Comments
 (0)