aboutsummaryrefslogtreecommitdiff
path: root/src/parser/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/parser.rs')
-rw-r--r--src/parser/parser.rs36
1 files changed, 9 insertions, 27 deletions
diff --git a/src/parser/parser.rs b/src/parser/parser.rs
index 3f4c8a07d..bb775c4a5 100644
--- a/src/parser/parser.rs
+++ b/src/parser/parser.rs
@@ -1,7 +1,6 @@
1use {SyntaxKind, TextUnit, Token};
2use super::Event; 1use super::Event;
3use super::is_insignificant; 2use super::input::{InputPosition, ParserInput};
4use SyntaxKind::{EOF, TOMBSTONE}; 3use SyntaxKind::{self, EOF, TOMBSTONE};
5 4
6pub(crate) struct Marker { 5pub(crate) struct Marker {
7 pos: u32, 6 pos: u32,
@@ -98,35 +97,18 @@ macro_rules! token_set {
98} 97}
99 98
100pub(crate) struct Parser<'t> { 99pub(crate) struct Parser<'t> {
101 #[allow(unused)] 100 inp: &'t ParserInput<'t>,
102 text: &'t str,
103 #[allow(unused)]
104 start_offsets: Vec<TextUnit>,
105 tokens: Vec<Token>, // non-whitespace tokens
106 101
107 pos: usize, 102 pos: InputPosition,
108 events: Vec<Event>, 103 events: Vec<Event>,
109} 104}
110 105
111impl<'t> Parser<'t> { 106impl<'t> Parser<'t> {
112 pub(crate) fn new(text: &'t str, raw_tokens: &'t [Token]) -> Parser<'t> { 107 pub(crate) fn new(inp: &'t ParserInput<'t>) -> Parser<'t> {
113 let mut tokens = Vec::new();
114 let mut start_offsets = Vec::new();
115 let mut len = TextUnit::new(0);
116 for &token in raw_tokens.iter() {
117 if !is_insignificant(token.kind) {
118 tokens.push(token);
119 start_offsets.push(len);
120 }
121 len += token.len;
122 }
123
124 Parser { 108 Parser {
125 text, 109 inp,
126 start_offsets,
127 tokens,
128 110
129 pos: 0, 111 pos: InputPosition::new(),
130 events: Vec::new(), 112 events: Vec::new(),
131 } 113 }
132 } 114 }
@@ -163,8 +145,8 @@ impl<'t> Parser<'t> {
163 }); 145 });
164 } 146 }
165 147
166 pub(crate) fn nth(&self, n: usize) -> SyntaxKind { 148 pub(crate) fn nth(&self, n: u32) -> SyntaxKind {
167 self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF) 149 self.inp.kind(self.pos + n)
168 } 150 }
169 151
170 pub(crate) fn current(&self) -> SyntaxKind { 152 pub(crate) fn current(&self) -> SyntaxKind {