@@ -18,11 +18,16 @@ pub struct Tokens {
18
18
contextual_kind : Vec < SyntaxKind > ,
19
19
}
20
20
21
+ /// `pub` impl used by callers to create `Tokens`.
21
22
impl Tokens {
22
23
#[ inline]
23
24
pub fn push ( & mut self , kind : SyntaxKind ) {
24
25
self . push_impl ( kind, SyntaxKind :: EOF )
25
26
}
27
+ #[ inline]
28
+ pub fn push_ident ( & mut self , contextual_kind : SyntaxKind ) {
29
+ self . push_impl ( SyntaxKind :: IDENT , contextual_kind)
30
+ }
26
31
/// Sets jointness for the last token we've pushed.
27
32
///
28
33
/// This is a separate API rather than an argument to the `push` to make it
@@ -41,11 +46,9 @@ impl Tokens {
41
46
/// ```
42
47
#[ inline]
43
48
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;
49
52
}
50
53
#[ inline]
51
54
fn push_impl ( & mut self , kind : SyntaxKind , contextual_kind : SyntaxKind ) {
@@ -56,22 +59,9 @@ impl Tokens {
56
59
self . kind . push ( kind) ;
57
60
self . contextual_kind . push ( contextual_kind) ;
58
61
}
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
- }
72
62
}
73
63
74
- /// pub(crate) impl used by the parser.
64
+ /// pub(crate) impl used by the parser to consume `Tokens` .
75
65
impl Tokens {
76
66
pub ( crate ) fn kind ( & self , idx : usize ) -> SyntaxKind {
77
67
self . kind . get ( idx) . copied ( ) . unwrap_or ( SyntaxKind :: EOF )
@@ -84,3 +74,14 @@ impl Tokens {
84
74
self . joint [ idx] & 1 << b_idx != 0
85
75
}
86
76
}
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