Working error recovery
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
void main() {
|
void main() {
|
||||||
app_instance.boot();
|
app_instance.boot();
|
||||||
app_instance.run();
|
app_instance.run();
|
||||||
|
|
||||||
hi
|
|
||||||
}
|
}
|
||||||
+7
-2
@@ -18,13 +18,18 @@ pub fn parse<'a>(source: &'a str) -> Result<Vec<TopLevel>, ParseError<'a, Vec<To
|
|||||||
|
|
||||||
let mut statements = vec![];
|
let mut statements = vec![];
|
||||||
|
|
||||||
|
let mut analyzer = error::AstErrorAnalyzer(None);
|
||||||
|
|
||||||
for pair in pairs.next().unwrap().into_inner() {
|
for pair in pairs.next().unwrap().into_inner() {
|
||||||
if pair.as_rule() != Rule::EOI {
|
if pair.as_rule() != Rule::EOI {
|
||||||
statements.push(TopLevel::try_from(pair).get()?);
|
statements.push(analyzer.get(TopLevel::try_from(pair)).get()?);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(statements)
|
match analyzer.build(statements) {
|
||||||
|
Ok(v) => Ok(v),
|
||||||
|
Err(e) => Err(ParseError::Ast(e)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|||||||
@@ -18,14 +18,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevel {
|
|||||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||||
let mut inner = pair.into_inner();
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
let attributes = collect_recovered(inner.next().unwrap().into_inner()).get()?;
|
let attributes = collect_recovered(inner.next().unwrap().into_inner());
|
||||||
|
|
||||||
Ok(TopLevel(
|
ast_expr!(TopLevel(
|
||||||
inner
|
inner
|
||||||
.next()
|
.next()
|
||||||
.map(TopLevelKind::try_from)
|
.map(TopLevelKind::try_from)
|
||||||
.unwrap_or(Ok(TopLevelKind::ModAttribute))
|
.unwrap_or(Ok(TopLevelKind::ModAttribute)),
|
||||||
.get()?,
|
|
||||||
attributes,
|
attributes,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user