mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Simplify
This commit is contained in:
parent
3cd2b2473b
commit
60725def49
2 changed files with 5 additions and 28 deletions
|
@ -57,7 +57,7 @@ impl<'p> Parser<'p> {
|
|||
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 @@ impl<'p> Parser<'p> {
|
|||
|
||||
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 @@ impl<'a> Lookahead for AnyOf<'a> {
|
|||
let curr = p.current();
|
||||
self.0.iter().any(|&k| k == curr)
|
||||
}
|
||||
|
||||
fn consume(p: &mut Parser) {
|
||||
p.bump();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,13 +136,6 @@ impl<'t> Parser<'t> {
|
|||
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 @@ impl<'t> Parser<'t> {
|
|||
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 a new issue