Removed error recovery from items
This commit is contained in:
@@ -78,44 +78,3 @@ macro_rules! ast_ensure {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! ast_expr {
|
||||
(use $r:expr, $($v:expr),* $(,)?) => {{
|
||||
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||
|
||||
$(
|
||||
analyzer.get($v).get()?;
|
||||
)*
|
||||
|
||||
analyzer.build($r)
|
||||
}};
|
||||
|
||||
($($item:ident)::+ { $($k:ident: $v:expr),* $(,)? }) => {{
|
||||
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||
|
||||
let v = $($item)::+ { $($k: analyzer.get($v).get()?),* };
|
||||
|
||||
analyzer.build(v)
|
||||
}};
|
||||
|
||||
($($item:ident)::+ ( $($v:expr),* $(,)? )) => {{
|
||||
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||
|
||||
let v = $($item)::+ ( $(analyzer.get($v).get()?),* );
|
||||
|
||||
analyzer.build(v)
|
||||
}};
|
||||
|
||||
(( $($v:expr),* $(,)? )) => {{
|
||||
let mut analyzer = $crate::error::AstErrorAnalyzer(None);
|
||||
|
||||
let v = ( $(analyzer.get($v).get()?),* );
|
||||
|
||||
analyzer.build(v)
|
||||
}};
|
||||
|
||||
($($item:ident)::+) => {
|
||||
$($item)::+
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
error::{AstError, IntoErr, collect_recovered},
|
||||
error::{AstError, collect_recovered},
|
||||
};
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Attribute {
|
||||
@@ -18,7 +18,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Attribute {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
// first item is always the path
|
||||
let path = inner.next().unwrap().try_into().get()?;
|
||||
let path = inner.next().unwrap().try_into()?;
|
||||
|
||||
// check what comes next
|
||||
match inner.next() {
|
||||
@@ -32,7 +32,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Attribute {
|
||||
// #[path = literal]
|
||||
Ok(Attribute::NameValue {
|
||||
path,
|
||||
value: next.try_into().get()?,
|
||||
value: next.try_into()?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Attribute {
|
||||
// #[path(...)]
|
||||
Ok(Attribute::List {
|
||||
path,
|
||||
items: collect_recovered(next.into_inner()).get()?,
|
||||
items: collect_recovered(next.into_inner())?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
error::{AstError, IntoErr},
|
||||
parser::consume_rule,
|
||||
};
|
||||
use crate::{Rule, ast::*, error::AstError, parser::consume_rule};
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ClassConstructor {
|
||||
type Error = AstError<'a>;
|
||||
@@ -12,21 +7,19 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ClassConstructor {
|
||||
let mut inner = pair.into_inner();
|
||||
|
||||
Ok(Self {
|
||||
visibility: Visibility::try_from(&mut inner).get()?,
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.get()?
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
|
||||
params: consume_rule(&mut inner, Rule::param_list)
|
||||
.map(ParamList::try_from)
|
||||
.transpose()
|
||||
.get()?
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
|
||||
body: inner.next().unwrap().try_into().get()?,
|
||||
body: inner.next().unwrap().try_into()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -38,11 +31,9 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ClassItem {
|
||||
let rule = pair.as_rule();
|
||||
|
||||
match rule {
|
||||
Rule::impl_decl | Rule::impl_for_decl => {
|
||||
Ok(ClassItem::ImplDecl(pair.try_into().get()?))
|
||||
}
|
||||
Rule::impl_decl | Rule::impl_for_decl => Ok(ClassItem::ImplDecl(pair.try_into()?)),
|
||||
|
||||
Rule::function_decl => Ok(ClassItem::Method(pair.try_into().get()?)),
|
||||
Rule::function_decl => Ok(ClassItem::Method(pair.try_into()?)),
|
||||
|
||||
_ => AstError::bug_unimplemented(pair),
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
error::{AstError, IntoErr, collect_recovered},
|
||||
error::{AstError, collect_recovered},
|
||||
};
|
||||
|
||||
impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for EnumItem {
|
||||
@@ -12,20 +12,19 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for EnumItem {
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
match rule {
|
||||
Rule::enum_named => Ok(EnumItem::Named(inner.next().unwrap().try_into().get()?)),
|
||||
Rule::enum_named => Ok(EnumItem::Named(inner.next().unwrap().try_into()?)),
|
||||
|
||||
Rule::enum_tuple => Ok(EnumItem::Tuple(
|
||||
inner.next().unwrap().try_into().get()?,
|
||||
collect_recovered(inner.next().unwrap().into_inner()).get()?,
|
||||
inner.next().unwrap().try_into()?,
|
||||
collect_recovered(inner.next().unwrap().into_inner())?,
|
||||
)),
|
||||
|
||||
Rule::enum_struct => Ok(EnumItem::Struct(
|
||||
inner.next().unwrap().try_into().get()?,
|
||||
inner.next().unwrap().try_into()?,
|
||||
inner
|
||||
.next()
|
||||
.map(|pair| collect_recovered::<FieldDecl, FieldDecl>(pair.into_inner()))
|
||||
.transpose()
|
||||
.get()?
|
||||
.map(|pair| collect_recovered::<FieldDecl>(pair.into_inner()))
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
)),
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
ast_ensure, ast_expr,
|
||||
error::{self, AstError, AstResult, IntoErr},
|
||||
ast_ensure,
|
||||
error::{self, AstError, AstResult},
|
||||
parser::{consume_rule, listen_rule},
|
||||
};
|
||||
|
||||
@@ -12,18 +12,18 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
ast_ensure!(pair, Rule::function_decl => {
|
||||
let mut inner = pair.into_inner();
|
||||
let visibility = Visibility::try_from(&mut inner);
|
||||
let visibility = Visibility::try_from(&mut inner)?;
|
||||
|
||||
let return_type = consume_rule(&mut inner, Rule::type_expr)
|
||||
.map(TypeExpr::try_from)
|
||||
.transpose();
|
||||
.transpose()?;
|
||||
|
||||
let name = Identifier::try_from(inner.next().unwrap());
|
||||
let name = Identifier::try_from(inner.next().unwrap())?;
|
||||
|
||||
let generics = consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default());
|
||||
.map(|v| v.unwrap_or_default())?;
|
||||
|
||||
let self_param = consume_rule(&mut inner, Rule::self_param).map(|param| {
|
||||
let mut param_inner = param.into_inner();
|
||||
@@ -61,11 +61,11 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for FunctionDecl {
|
||||
Ok(params)
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| Ok(ParamList(self_param.into_iter().collect())));
|
||||
.unwrap_or_else(|| Ok(ParamList(self_param.into_iter().collect())))?;
|
||||
|
||||
let is_override = consume_rule(&mut inner, Rule::override_kw).map(Override::try_from).transpose();
|
||||
let is_override = consume_rule(&mut inner, Rule::override_kw).map(Override::try_from).transpose()?;
|
||||
|
||||
let body = inner.next().map(Block::try_from).transpose();
|
||||
let body = inner.next().map(Block::try_from).transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
visibility: visibility,
|
||||
@@ -85,7 +85,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Override {
|
||||
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
ast_ensure!(pair, Rule::override_kw => {
|
||||
Ok(Override(pair.into_inner().next().map(ExprPath::try_from).transpose()))
|
||||
Ok(Override(pair.into_inner().next().map(ExprPath::try_from).transpose()?))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Lifetime {
|
||||
|
||||
match pair.as_rule() {
|
||||
Rule::ref_lifetime => inner.next().unwrap().try_into(),
|
||||
Rule::lifetime => Ok(Lifetime::Lifetime(inner.next().unwrap().try_into())),
|
||||
Rule::lifetime => Ok(Lifetime::Lifetime(inner.next().unwrap().try_into()?)),
|
||||
Rule::unsafe_kw => Ok(Lifetime::Unsafe),
|
||||
_ => error::AstError::bug_unimplemented(pair),
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
error::{AstError, IntoErr, collect_recovered},
|
||||
error::{AstError, collect_recovered},
|
||||
parser::consume_rule,
|
||||
};
|
||||
|
||||
@@ -16,23 +16,21 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for ImplDecl {
|
||||
Rule::impl_for_decl => Ok(ImplDecl {
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.get()?
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
trait_: Some(inner.next().unwrap().try_into().get()?),
|
||||
target: inner.next().unwrap().try_into().get()?,
|
||||
methods: collect_recovered(inner).get()?,
|
||||
trait_: Some(inner.next().unwrap().try_into()?),
|
||||
target: inner.next().unwrap().try_into()?,
|
||||
methods: collect_recovered(inner)?,
|
||||
}),
|
||||
|
||||
Rule::impl_decl => Ok(ImplDecl {
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.get()?
|
||||
.transpose()?
|
||||
.unwrap_or_default(),
|
||||
trait_: None,
|
||||
target: inner.next().unwrap().try_into().get()?,
|
||||
methods: collect_recovered(inner).get()?,
|
||||
target: inner.next().unwrap().try_into()?,
|
||||
methods: collect_recovered(inner)?,
|
||||
}),
|
||||
|
||||
_ => AstError::bug_unimplemented(pair),
|
||||
|
||||
@@ -7,8 +7,7 @@ pub mod impl_decl;
|
||||
use crate::{
|
||||
Rule,
|
||||
ast::*,
|
||||
ast_expr,
|
||||
error::{AstError, IntoErr, collect_recovered},
|
||||
error::{AstError, collect_recovered},
|
||||
parser::consume_rule,
|
||||
};
|
||||
|
||||
@@ -18,13 +17,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevel {
|
||||
fn try_from(pair: pest::iterators::Pair<'a, Rule>) -> Result<Self, Self::Error> {
|
||||
let mut inner = pair.clone().into_inner();
|
||||
|
||||
let attributes = collect_recovered(inner.next().unwrap().into_inner());
|
||||
let attributes = collect_recovered(inner.next().unwrap().into_inner())?;
|
||||
|
||||
Ok(TopLevel(
|
||||
inner
|
||||
.next()
|
||||
.map(Spanned::try_from)
|
||||
.unwrap_or_else(move || Ok(Spanned::new_pair(pair, TopLevelKind::ModAttribute))),
|
||||
.unwrap_or_else(move || Ok(Spanned::new_pair(pair, TopLevelKind::ModAttribute)))?,
|
||||
attributes,
|
||||
))
|
||||
}
|
||||
@@ -39,88 +38,88 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
|
||||
|
||||
match rule {
|
||||
Rule::import => Ok(TopLevelKind::Import(
|
||||
Visibility::try_from(&mut inner),
|
||||
Path::try_from(inner.next().unwrap()),
|
||||
Visibility::try_from(&mut inner)?,
|
||||
Path::try_from(inner.next().unwrap())?,
|
||||
)),
|
||||
|
||||
Rule::function_decl => Ok(TopLevelKind::FunctionDecl(pair.try_into())),
|
||||
Rule::function_decl => Ok(TopLevelKind::FunctionDecl(pair.try_into()?)),
|
||||
|
||||
Rule::struct_decl => Ok(TopLevelKind::StructDecl {
|
||||
visibility: Visibility::try_from(&mut inner),
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
name: inner.next().unwrap().try_into(),
|
||||
name: inner.next().unwrap().try_into()?,
|
||||
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
|
||||
fields: inner
|
||||
.next()
|
||||
.map(|pair| collect_recovered(pair.into_inner()))
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
}),
|
||||
|
||||
Rule::class_decl => Ok(TopLevelKind::ClassDecl {
|
||||
visibility: Visibility::try_from(&mut inner),
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
name: inner.next().unwrap().try_into(),
|
||||
name: inner.next().unwrap().try_into()?,
|
||||
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
|
||||
inherits: consume_rule(&mut inner, Rule::expr_path)
|
||||
.map(ExprPath::try_from)
|
||||
.transpose(),
|
||||
.transpose()?,
|
||||
|
||||
fields: collect_recovered(inner.next().unwrap().into_inner()),
|
||||
fields: collect_recovered(inner.next().unwrap().into_inner())?,
|
||||
|
||||
constructor: consume_rule(&mut inner, Rule::class_constructor)
|
||||
.map(Spanned::try_from)
|
||||
.transpose(),
|
||||
.transpose()?,
|
||||
|
||||
items: collect_recovered(inner),
|
||||
items: collect_recovered(inner)?,
|
||||
}),
|
||||
|
||||
Rule::enum_decl => Ok(TopLevelKind::EnumDecl {
|
||||
visibility: Visibility::try_from(&mut inner),
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
name: inner.next().unwrap().try_into(),
|
||||
name: inner.next().unwrap().try_into()?,
|
||||
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
|
||||
fields: collect_recovered(inner),
|
||||
fields: collect_recovered(inner)?,
|
||||
}),
|
||||
|
||||
Rule::declare_module => Ok(TopLevelKind::DeclareModule(
|
||||
Visibility::try_from(&mut inner),
|
||||
inner.next().unwrap().try_into(),
|
||||
Visibility::try_from(&mut inner)?,
|
||||
inner.next().unwrap().try_into()?,
|
||||
)),
|
||||
|
||||
Rule::impl_for_decl | Rule::impl_decl => Ok(TopLevelKind::ImplDecl(pair.try_into())),
|
||||
Rule::impl_for_decl | Rule::impl_decl => Ok(TopLevelKind::ImplDecl(pair.try_into()?)),
|
||||
|
||||
Rule::trait_decl => Ok(TopLevelKind::TraitDecl {
|
||||
visibility: Visibility::try_from(&mut inner),
|
||||
visibility: Visibility::try_from(&mut inner)?,
|
||||
|
||||
name: inner.next().unwrap().try_into(),
|
||||
name: inner.next().unwrap().try_into()?,
|
||||
|
||||
generics: consume_rule(&mut inner, Rule::generics_decl)
|
||||
.map(GenericsDecl::try_from)
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
|
||||
requirements: consume_rule(&mut inner, Rule::trait_requirements)
|
||||
.map(|pair| collect_recovered(pair.into_inner()))
|
||||
.transpose()
|
||||
.map(|v| v.unwrap_or_default()),
|
||||
.map(|v| v.unwrap_or_default())?,
|
||||
|
||||
items: collect_recovered(&mut inner),
|
||||
items: collect_recovered(&mut inner)?,
|
||||
}),
|
||||
|
||||
_ => AstError::bug_unimplemented(pair),
|
||||
|
||||
Reference in New Issue
Block a user