diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-11 10:19:32 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-11 10:19:32 +0000 |
commit | 7a0ada860b57acd44b1d53e944ae621e438652da (patch) | |
tree | 206edfb15c0eec57c1872a2acc435d7f38df1c88 /src/parser/grammar/mod.rs | |
parent | 7176029803fe2e00f29ab7d20a384e3ee6f53ba3 (diff) | |
parent | 65ebfd9a34554b8139d5c4673bc3b5daa5ab0df5 (diff) |
Merge #49
49: Simplify r=matklad a=matklad
bors r+
Diffstat (limited to 'src/parser/grammar/mod.rs')
-rw-r--r-- | src/parser/grammar/mod.rs | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs index 5266354c1..f5b63aaab 100644 --- a/src/parser/grammar/mod.rs +++ b/src/parser/grammar/mod.rs | |||
@@ -110,65 +110,3 @@ fn error_block(p: &mut Parser, message: &str) { | |||
110 | } | 110 | } |
111 | err.complete(p, ERROR); | 111 | err.complete(p, ERROR); |
112 | } | 112 | } |
113 | |||
114 | impl<'p> Parser<'p> { | ||
115 | fn at<L: Lookahead>(&self, l: L) -> bool { | ||
116 | l.is_ahead(self) | ||
117 | } | ||
118 | |||
119 | fn err_and_bump(&mut self, message: &str) { | ||
120 | let err = self.start(); | ||
121 | self.error(message); | ||
122 | self.bump(); | ||
123 | err.complete(self, ERROR); | ||
124 | } | ||
125 | |||
126 | fn expect(&mut self, kind: SyntaxKind) -> bool { | ||
127 | if self.at(kind) { | ||
128 | self.bump(); | ||
129 | true | ||
130 | } else { | ||
131 | self.error(format!("expected {:?}", kind)); | ||
132 | false | ||
133 | } | ||
134 | } | ||
135 | |||
136 | fn eat(&mut self, kind: SyntaxKind) -> bool { | ||
137 | self.current() == kind && { | ||
138 | self.bump(); | ||
139 | true | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | |||
144 | trait Lookahead: Copy { | ||
145 | fn is_ahead(self, p: &Parser) -> bool; | ||
146 | } | ||
147 | |||
148 | impl Lookahead for SyntaxKind { | ||
149 | fn is_ahead(self, p: &Parser) -> bool { | ||
150 | p.current() == self | ||
151 | } | ||
152 | } | ||
153 | |||
154 | impl Lookahead for [SyntaxKind; 2] { | ||
155 | fn is_ahead(self, p: &Parser) -> bool { | ||
156 | p.current() == self[0] && p.nth(1) == self[1] | ||
157 | } | ||
158 | } | ||
159 | |||
160 | impl Lookahead for [SyntaxKind; 3] { | ||
161 | fn is_ahead(self, p: &Parser) -> bool { | ||
162 | p.current() == self[0] && p.nth(1) == self[1] && p.nth(2) == self[2] | ||
163 | } | ||
164 | } | ||
165 | |||
166 | #[derive(Clone, Copy)] | ||
167 | struct AnyOf<'a>(&'a [SyntaxKind]); | ||
168 | |||
169 | impl<'a> Lookahead for AnyOf<'a> { | ||
170 | fn is_ahead(self, p: &Parser) -> bool { | ||
171 | let curr = p.current(); | ||
172 | self.0.iter().any(|&k| k == curr) | ||
173 | } | ||
174 | } | ||