[fine] Improve wildcard parsing, fix ephemera bug with peek_next
This commit is contained in:
parent
65ec2d4cca
commit
28ec6b5e85
1 changed files with 18 additions and 11 deletions
|
|
@ -343,9 +343,17 @@ impl<'a> CParser<'a> {
|
||||||
events: Vec::new(),
|
events: Vec::new(),
|
||||||
panic: false,
|
panic: false,
|
||||||
};
|
};
|
||||||
parser.current = parser.tokens.next();
|
|
||||||
parser.next = parser.tokens.next();
|
// Getting started: put the first token into `next` and then fast
|
||||||
parser.skip_ephemera();
|
// forward past ephemera to the first "real" token.
|
||||||
|
parser.next_real_token();
|
||||||
|
|
||||||
|
// Put `next` into `current`.
|
||||||
|
std::mem::swap(&mut parser.current, &mut parser.next);
|
||||||
|
|
||||||
|
// Now set `next` to the *next* real token.
|
||||||
|
parser.next_real_token();
|
||||||
|
|
||||||
parser
|
parser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -385,15 +393,12 @@ impl<'a> CParser<'a> {
|
||||||
});
|
});
|
||||||
// Move next into current (and current into next but who cares, thanks rust.)
|
// Move next into current (and current into next but who cares, thanks rust.)
|
||||||
std::mem::swap(&mut self.current, &mut self.next);
|
std::mem::swap(&mut self.current, &mut self.next);
|
||||||
self.next = self.tokens.next();
|
self.next_real_token();
|
||||||
self.skip_ephemera();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn skip_ephemera(&mut self) {
|
fn next_real_token(&mut self) {
|
||||||
while self.current.kind == TokenKind::Whitespace || self.current.kind == TokenKind::Comment
|
self.next = self.tokens.next();
|
||||||
{
|
while self.next.kind == TokenKind::Whitespace || self.next.kind == TokenKind::Comment {
|
||||||
// Move next into current (and current into next but who cares, thanks rust.)
|
|
||||||
std::mem::swap(&mut self.current, &mut self.next);
|
|
||||||
self.next = self.tokens.next();
|
self.next = self.tokens.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -991,6 +996,8 @@ fn is_expression(p: &mut CParser, left: MarkClosed, right_power: u8) -> MarkClos
|
||||||
p.end(m, TreeKind::IsExpression)
|
p.end(m, TreeKind::IsExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PATTERN_START: &[TokenKind] = &[TokenKind::Identifier, TokenKind::Underscore];
|
||||||
|
|
||||||
fn pattern(p: &mut CParser, right_power: u8) {
|
fn pattern(p: &mut CParser, right_power: u8) {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
|
|
||||||
|
|
@ -1260,7 +1267,7 @@ fn match_body(p: &mut CParser) {
|
||||||
|
|
||||||
p.expect_start(TokenKind::LeftBrace);
|
p.expect_start(TokenKind::LeftBrace);
|
||||||
while !p.at(TokenKind::RightBrace) && !p.eof() {
|
while !p.at(TokenKind::RightBrace) && !p.eof() {
|
||||||
if p.at(TokenKind::Identifier) {
|
if p.at_any(PATTERN_START) {
|
||||||
// TODO: type_expr_first ?
|
// TODO: type_expr_first ?
|
||||||
match_arm(p);
|
match_arm(p);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue