49: Simplify r=matklad a=matklad

bors r+
This commit is contained in:
bors[bot] 2018-02-11 10:19:32 +00:00
commit 7a0ada860b
4 changed files with 35 additions and 64 deletions

View file

@ -1,7 +1,7 @@
use super::*;
pub(super) fn inner_attributes(p: &mut Parser) {
while p.at([POUND, EXCL]) {
while p.current() == POUND && p.nth(1) == EXCL {
attribute(p, true)
}
}

View file

@ -110,65 +110,3 @@ fn error_block(p: &mut Parser, message: &str) {
}
err.complete(p, ERROR);
}
impl<'p> Parser<'p> {
fn at<L: Lookahead>(&self, l: L) -> bool {
l.is_ahead(self)
}
fn err_and_bump(&mut self, message: &str) {
let err = self.start();
self.error(message);
self.bump();
err.complete(self, ERROR);
}
fn expect(&mut self, kind: SyntaxKind) -> bool {
if self.at(kind) {
self.bump();
true
} else {
self.error(format!("expected {:?}", kind));
false
}
}
fn eat(&mut self, kind: SyntaxKind) -> bool {
self.current() == kind && {
self.bump();
true
}
}
}
trait Lookahead: Copy {
fn is_ahead(self, p: &Parser) -> bool;
}
impl Lookahead for SyntaxKind {
fn is_ahead(self, p: &Parser) -> bool {
p.current() == self
}
}
impl Lookahead for [SyntaxKind; 2] {
fn is_ahead(self, p: &Parser) -> bool {
p.current() == self[0] && p.nth(1) == self[1]
}
}
impl Lookahead for [SyntaxKind; 3] {
fn is_ahead(self, p: &Parser) -> bool {
p.current() == self[0] && p.nth(1) == self[1] && p.nth(2) == self[2]
}
}
#[derive(Clone, Copy)]
struct AnyOf<'a>(&'a [SyntaxKind]);
impl<'a> Lookahead for AnyOf<'a> {
fn is_ahead(self, p: &Parser) -> bool {
let curr = p.current();
self.0.iter().any(|&k| k == curr)
}
}

View file

@ -1,7 +1,10 @@
use super::*;
pub(super) fn is_path_start(p: &Parser) -> bool {
AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p)
match p.current() {
IDENT | SELF_KW | SUPER_KW | COLONCOLON => true,
_ => false,
}
}
pub(super) fn use_path(p: &mut Parser) {

View file

@ -26,3 +26,33 @@ fn is_insignificant(kind: SyntaxKind) -> bool {
_ => false,
}
}
impl<'p> parser::Parser<'p> {
fn at(&self, kind: SyntaxKind) -> bool {
self.current() == kind
}
fn err_and_bump(&mut self, message: &str) {
let err = self.start();
self.error(message);
self.bump();
err.complete(self, ERROR);
}
fn expect(&mut self, kind: SyntaxKind) -> bool {
if self.at(kind) {
self.bump();
true
} else {
self.error(format!("expected {:?}", kind));
false
}
}
fn eat(&mut self, kind: SyntaxKind) -> bool {
self.at(kind) && {
self.bump();
true
}
}
}