[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(),
|
||||
panic: false,
|
||||
};
|
||||
parser.current = parser.tokens.next();
|
||||
parser.next = parser.tokens.next();
|
||||
parser.skip_ephemera();
|
||||
|
||||
// Getting started: put the first token into `next` and then fast
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
@ -385,15 +393,12 @@ impl<'a> CParser<'a> {
|
|||
});
|
||||
// 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.skip_ephemera();
|
||||
self.next_real_token();
|
||||
}
|
||||
|
||||
fn skip_ephemera(&mut self) {
|
||||
while self.current.kind == TokenKind::Whitespace || self.current.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);
|
||||
fn next_real_token(&mut self) {
|
||||
self.next = self.tokens.next();
|
||||
while self.next.kind == TokenKind::Whitespace || self.next.kind == TokenKind::Comment {
|
||||
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)
|
||||
}
|
||||
|
||||
const PATTERN_START: &[TokenKind] = &[TokenKind::Identifier, TokenKind::Underscore];
|
||||
|
||||
fn pattern(p: &mut CParser, right_power: u8) {
|
||||
let m = p.start();
|
||||
|
||||
|
|
@ -1260,7 +1267,7 @@ fn match_body(p: &mut CParser) {
|
|||
|
||||
p.expect_start(TokenKind::LeftBrace);
|
||||
while !p.at(TokenKind::RightBrace) && !p.eof() {
|
||||
if p.at(TokenKind::Identifier) {
|
||||
if p.at_any(PATTERN_START) {
|
||||
// TODO: type_expr_first ?
|
||||
match_arm(p);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue