preserve context in parsing of self
varref
This commit is contained in:
parent
728b269199
commit
06b64345d6
1 changed files with 11 additions and 9 deletions
|
@ -541,12 +541,13 @@ impl<'a> Parser<'a> {
|
||||||
// if the next token is the given keyword, eat it and return
|
// if the next token is the given keyword, eat it and return
|
||||||
// true. Otherwise, return false.
|
// true. Otherwise, return false.
|
||||||
pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool {
|
pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool {
|
||||||
let is_kw = match self.token {
|
match self.token {
|
||||||
token::IDENT(sid, false) => kw.to_ident().name == sid.name,
|
token::IDENT(sid, false) if kw.to_ident().name == sid.name => {
|
||||||
|
self.bump();
|
||||||
|
true
|
||||||
|
}
|
||||||
_ => false
|
_ => false
|
||||||
};
|
}
|
||||||
if is_kw { self.bump() }
|
|
||||||
is_kw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the given word is not a keyword, signal an error.
|
// if the given word is not a keyword, signal an error.
|
||||||
|
@ -1917,7 +1918,7 @@ impl<'a> Parser<'a> {
|
||||||
return self.mk_expr(blk.span.lo, blk.span.hi,
|
return self.mk_expr(blk.span.lo, blk.span.hi,
|
||||||
ExprBlock(blk));
|
ExprBlock(blk));
|
||||||
},
|
},
|
||||||
_ if token::is_bar(&self.token) => {
|
token::BINOP(token::OR) | token::OROR => {
|
||||||
return self.parse_lambda_expr();
|
return self.parse_lambda_expr();
|
||||||
},
|
},
|
||||||
_ if self.eat_keyword(keywords::Proc) => {
|
_ if self.eat_keyword(keywords::Proc) => {
|
||||||
|
@ -1933,8 +1934,9 @@ impl<'a> Parser<'a> {
|
||||||
});
|
});
|
||||||
return self.mk_expr(lo, body.span.hi, ExprProc(decl, fakeblock));
|
return self.mk_expr(lo, body.span.hi, ExprProc(decl, fakeblock));
|
||||||
},
|
},
|
||||||
_ if self.eat_keyword(keywords::Self) => {
|
token::IDENT(id @ ast::Ident{name:token::SELF_KEYWORD_NAME,ctxt:_},false) => {
|
||||||
let path = ast_util::ident_to_path(mk_sp(lo, hi), special_idents::self_);
|
self.bump();
|
||||||
|
let path = ast_util::ident_to_path(mk_sp(lo, hi), id);
|
||||||
ex = ExprPath(path);
|
ex = ExprPath(path);
|
||||||
hi = self.last_span.hi;
|
hi = self.last_span.hi;
|
||||||
}
|
}
|
||||||
|
@ -1982,7 +1984,7 @@ impl<'a> Parser<'a> {
|
||||||
},
|
},
|
||||||
token::LBRACKET => {
|
token::LBRACKET => {
|
||||||
self.bump();
|
self.bump();
|
||||||
|
|
||||||
if self.token == token::RBRACKET {
|
if self.token == token::RBRACKET {
|
||||||
// Empty vector.
|
// Empty vector.
|
||||||
self.bump();
|
self.bump();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue