aboutsummaryrefslogtreecommitdiff
path: root/src/parser_impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser_impl')
-rw-r--r--src/parser_impl/input.rs17
-rw-r--r--src/parser_impl/mod.rs19
2 files changed, 30 insertions, 6 deletions
diff --git a/src/parser_impl/input.rs b/src/parser_impl/input.rs
index db76364b2..c0fe4d488 100644
--- a/src/parser_impl/input.rs
+++ b/src/parser_impl/input.rs
@@ -36,7 +36,22 @@ impl<'t> ParserInput<'t> {
36 self.tokens[idx].kind 36 self.tokens[idx].kind
37 } 37 }
38 38
39 #[allow(unused)] 39 pub fn len(&self, pos: InputPosition) -> TextUnit {
40 let idx = pos.0 as usize;
41 if !(idx < self.tokens.len()) {
42 return 0.into();
43 }
44 self.tokens[idx].len
45 }
46
47 pub fn start(&self, pos: InputPosition) -> TextUnit {
48 let idx = pos.0 as usize;
49 if !(idx < self.tokens.len()) {
50 return 0.into();
51 }
52 self.start_offsets[idx]
53 }
54
40 pub fn text(&self, pos: InputPosition) -> &'t str { 55 pub fn text(&self, pos: InputPosition) -> &'t str {
41 let idx = pos.0 as usize; 56 let idx = pos.0 as usize;
42 if !(idx < self.tokens.len()) { 57 if !(idx < self.tokens.len()) {
diff --git a/src/parser_impl/mod.rs b/src/parser_impl/mod.rs
index 2791c8da5..d640a7784 100644
--- a/src/parser_impl/mod.rs
+++ b/src/parser_impl/mod.rs
@@ -65,6 +65,11 @@ impl<'t> ParserImpl<'t> {
65 self.events 65 self.events
66 } 66 }
67 67
68 pub(super) fn at_compound2(&self, c1: SyntaxKind, c2: SyntaxKind) -> bool {
69 self.inp.kind(self.pos) == c1 && self.inp.kind(self.pos + 1) == c2
70 && self.inp.start(self.pos + 1) == self.inp.start(self.pos) + self.inp.len(self.pos)
71 }
72
68 pub(super) fn nth(&self, n: u32) -> SyntaxKind { 73 pub(super) fn nth(&self, n: u32) -> SyntaxKind {
69 self.inp.kind(self.pos + n) 74 self.inp.kind(self.pos + n)
70 } 75 }
@@ -87,7 +92,7 @@ impl<'t> ParserImpl<'t> {
87 if kind == EOF { 92 if kind == EOF {
88 return; 93 return;
89 } 94 }
90 self.do_bump(kind); 95 self.do_bump(kind, 1);
91 } 96 }
92 97
93 pub(super) fn bump_remap(&mut self, kind: SyntaxKind) { 98 pub(super) fn bump_remap(&mut self, kind: SyntaxKind) {
@@ -95,14 +100,18 @@ impl<'t> ParserImpl<'t> {
95 // TODO: panic!? 100 // TODO: panic!?
96 return; 101 return;
97 } 102 }
98 self.do_bump(kind); 103 self.do_bump(kind, 1);
104 }
105
106 pub(super) fn bump_compound(&mut self, kind: SyntaxKind, n: u8) {
107 self.do_bump(kind, n);
99 } 108 }
100 109
101 fn do_bump(&mut self, kind: SyntaxKind) { 110 fn do_bump(&mut self, kind: SyntaxKind, n_raw_tokens: u8) {
102 self.pos += 1; 111 self.pos += u32::from(n_raw_tokens);
103 self.event(Event::Token { 112 self.event(Event::Token {
104 kind, 113 kind,
105 n_raw_tokens: 1, 114 n_raw_tokens,
106 }); 115 });
107 } 116 }
108 117