This commit is contained in:
Aleksey Kladov 2018-01-28 00:05:31 +03:00
parent d280c72338
commit caba13a2dd
2 changed files with 22 additions and 11 deletions

View file

@ -45,7 +45,6 @@ fn item(p: &mut Parser) {
} }
err_token => { err_token => {
item.abandon(p); item.abandon(p);
let err = p.start();
let message = if err_token == SEMI { let message = if err_token == SEMI {
//TODO: if the item is incomplete, this message is misleading //TODO: if the item is incomplete, this message is misleading
"expected item, found `;`\n\ "expected item, found `;`\n\
@ -53,11 +52,7 @@ fn item(p: &mut Parser) {
} else { } else {
"expected item" "expected item"
}; };
p.error() p.err_and_bump(message);
.message(message)
.emit();
p.bump();
err.complete(p, ERROR);
return; return;
} }
}; };
@ -127,7 +122,7 @@ fn pos_fields(p: &mut Parser) {
if !p.expect(L_PAREN) { if !p.expect(L_PAREN) {
return; return;
} }
while !(p.at(R_PAREN) || p.at(EOF)) { while !p.at(R_PAREN) && !p.at(EOF) {
let pos_field = p.start(); let pos_field = p.start();
visibility(p); visibility(p);
types::type_ref(p); types::type_ref(p);
@ -173,7 +168,7 @@ fn use_item(p: &mut Parser) {
use_tree(p); use_tree(p);
p.expect(SEMI); p.expect(SEMI);
fn use_tree(p: &mut Parser) -> bool { fn use_tree(p: &mut Parser){
let la = p.raw_lookahead(1); let la = p.raw_lookahead(1);
let m = p.start(); let m = p.start();
match (p.current(), la) { match (p.current(), la) {
@ -216,16 +211,23 @@ fn use_item(p: &mut Parser) {
} }
_ => { _ => {
m.abandon(p); m.abandon(p);
return false p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`");
return;
}, },
} }
m.complete(p, USE_TREE); m.complete(p, USE_TREE);
return true;
} }
fn nested_trees(p: &mut Parser) { fn nested_trees(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
p.curly_block(|p| comma_list(p, EOF, use_tree)); p.bump();
while !p.at(EOF) && !p.at(R_CURLY) {
use_tree(p);
if !p.at(R_CURLY) {
p.expect(COMMA);
}
}
p.expect(R_CURLY);
} }
} }

View file

@ -84,6 +84,15 @@ impl<'p> Parser<'p> {
l.is_ahead(self) l.is_ahead(self)
} }
fn err_and_bump(&mut self, message: &str) {
let err = self.start();
self.error()
.message(message)
.emit();
self.bump();
err.complete(self, ERROR);
}
pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool {
if self.at(kind) { if self.at(kind) {
self.bump(); self.bump();