Simplify
This commit is contained in:
parent
3cd2b2473b
commit
60725def49
@ -57,7 +57,7 @@ fn err_and_bump(&mut self, message: &str) {
|
||||
err.complete(self, ERROR);
|
||||
}
|
||||
|
||||
pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool {
|
||||
fn expect(&mut self, kind: SyntaxKind) -> bool {
|
||||
if self.at(kind) {
|
||||
self.bump();
|
||||
true
|
||||
@ -77,40 +77,24 @@ fn eat(&mut self, kind: SyntaxKind) -> bool {
|
||||
|
||||
trait Lookahead: Copy {
|
||||
fn is_ahead(self, p: &Parser) -> bool;
|
||||
fn consume(p: &mut Parser);
|
||||
}
|
||||
|
||||
impl Lookahead for SyntaxKind {
|
||||
fn is_ahead(self, p: &Parser) -> bool {
|
||||
p.current() == self
|
||||
}
|
||||
|
||||
fn consume(p: &mut Parser) {
|
||||
p.bump();
|
||||
}
|
||||
}
|
||||
|
||||
impl Lookahead for [SyntaxKind; 2] {
|
||||
fn is_ahead(self, p: &Parser) -> bool {
|
||||
p.current() == self[0] && p.raw_lookahead(1) == self[1]
|
||||
}
|
||||
|
||||
fn consume(p: &mut Parser) {
|
||||
p.bump();
|
||||
p.bump();
|
||||
}
|
||||
}
|
||||
|
||||
impl Lookahead for [SyntaxKind; 3] {
|
||||
fn is_ahead(self, p: &Parser) -> bool {
|
||||
p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2]
|
||||
}
|
||||
|
||||
fn consume(p: &mut Parser) {
|
||||
p.bump();
|
||||
p.bump();
|
||||
p.bump();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@ -121,8 +105,4 @@ fn is_ahead(self, p: &Parser) -> bool {
|
||||
let curr = p.current();
|
||||
self.0.iter().any(|&k| k == curr)
|
||||
}
|
||||
|
||||
fn consume(p: &mut Parser) {
|
||||
p.bump();
|
||||
}
|
||||
}
|
||||
|
@ -136,13 +136,6 @@ pub(crate) fn into_events(self) -> Vec<Event> {
|
||||
self.events
|
||||
}
|
||||
|
||||
pub(crate) fn current(&self) -> SyntaxKind {
|
||||
if self.pos == self.tokens.len() {
|
||||
return EOF;
|
||||
}
|
||||
self.tokens[self.pos].kind
|
||||
}
|
||||
|
||||
pub(crate) fn start(&mut self) -> Marker {
|
||||
let m = Marker {
|
||||
pos: self.events.len() as u32,
|
||||
@ -175,6 +168,10 @@ pub(crate) fn raw_lookahead(&self, n: usize) -> SyntaxKind {
|
||||
self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF)
|
||||
}
|
||||
|
||||
pub(crate) fn current(&self) -> SyntaxKind {
|
||||
self.raw_lookahead(0)
|
||||
}
|
||||
|
||||
fn event(&mut self, event: Event) {
|
||||
self.events.push(event)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user