[fine] Some resilience, a design improvement for iterator

This commit is contained in:
John Doty 2024-01-29 10:04:47 -08:00
parent 15548afc38
commit f2e82942df
4 changed files with 29 additions and 8 deletions

View file

@ -318,6 +318,7 @@ struct CParser<'a> {
current: Token<'a>,
fuel: Cell<u32>,
events: Vec<ParseEvent<'a>>,
panic: bool,
}
impl<'a> CParser<'a> {
@ -327,6 +328,7 @@ impl<'a> CParser<'a> {
current: Token::new(TokenKind::EOF, 0, ""),
fuel: Cell::new(256),
events: Vec::new(),
panic: false,
};
parser.current = parser.tokens.next();
parser.skip_ephemera();
@ -412,6 +414,7 @@ impl<'a> CParser<'a> {
fn eat(&mut self, kind: TokenKind) -> bool {
if self.at(kind) {
self.panic = false; // Check
self.advance();
true
} else {
@ -454,6 +457,11 @@ impl<'a> CParser<'a> {
where
T: Into<String>,
{
if self.panic {
return;
}
self.panic = true;
let message: String = message.into();
let mut final_message = "Error ".to_string();
@ -472,6 +480,10 @@ impl<'a> CParser<'a> {
});
}
fn synchronize(&mut self) {
if self.panic {}
}
fn build_tree(self) -> (SyntaxTree<'a>, Lines) {
let mut events = self.events;
let mut stack = Vec::new();
@ -599,21 +611,23 @@ fn field_decl(p: &mut CParser) {
p.end(m, TreeKind::FieldDecl);
}
const PARAM_LIST_RECOVERY: &[TokenKind] = &[TokenKind::Arrow, TokenKind::LeftBrace, TokenKind::Fun];
const PARAM_LIST_RECOVERY: &[TokenKind] = &[
TokenKind::Arrow,
TokenKind::LeftBrace,
TokenKind::Fun,
TokenKind::RightParen,
];
fn param_list(p: &mut CParser) {
let m = p.start();
p.expect_start(TokenKind::LeftParen);
while !p.at(TokenKind::RightParen) && !p.eof() {
while !p.at_any(PARAM_LIST_RECOVERY) && !p.eof() {
if p.at(TokenKind::Identifier) {
parameter(p);
} else if p.at(TokenKind::Selff) {
self_parameter(p);
} else {
if p.at_any(PARAM_LIST_RECOVERY) {
break;
}
p.advance_with_error("expected parameter");
}
}