diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-04 12:40:24 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-04 12:40:24 +0000 |
commit | b86e87c8885895e5b3fcec021ee65003d64c4cbe (patch) | |
tree | 0495db2ec299fd7d617f84febffa5ea954f2d513 /src/parser/parser.rs | |
parent | aa36ad008eae28d1251a4bf276b1d13398fcf89f (diff) | |
parent | 852543212ba5c68b3428a80187087cc641de612c (diff) |
Merge #42
42: Extract parser input into a separate struct r=matklad a=matklad
bors r+
Diffstat (limited to 'src/parser/parser.rs')
-rw-r--r-- | src/parser/parser.rs | 36 |
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 @@ | |||
1 | use {SyntaxKind, TextUnit, Token}; | ||
2 | use super::Event; | 1 | use super::Event; |
3 | use super::is_insignificant; | 2 | use super::input::{InputPosition, ParserInput}; |
4 | use SyntaxKind::{EOF, TOMBSTONE}; | 3 | use SyntaxKind::{self, EOF, TOMBSTONE}; |
5 | 4 | ||
6 | pub(crate) struct Marker { | 5 | pub(crate) struct Marker { |
7 | pos: u32, | 6 | pos: u32, |
@@ -98,35 +97,18 @@ macro_rules! token_set { | |||
98 | } | 97 | } |
99 | 98 | ||
100 | pub(crate) struct Parser<'t> { | 99 | pub(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 | ||
111 | impl<'t> Parser<'t> { | 106 | impl<'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 { |