error system: types
This commit is contained in:
@@ -272,3 +272,9 @@ pub enum Literal {
|
|||||||
Bool(bool),
|
Bool(bool),
|
||||||
Tuple(Vec<Expression>),
|
Tuple(Vec<Expression>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TypeExpr {
|
||||||
|
pub fn no_px(kind: TypeExprKind) -> Self {
|
||||||
|
Self(kind, Vec::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Rule,
|
Rule,
|
||||||
ast::*,
|
ast::*,
|
||||||
error::{AstError, IntoErr, collect_recovered},
|
ast_expr,
|
||||||
|
error::{AstError, GetLength, IntoErr, collect_recovered},
|
||||||
parser::{consume_rule, listen_rule},
|
parser::{consume_rule, listen_rule},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,15 +48,15 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExprKind {
|
|||||||
let mut inner = pair.into_inner();
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
match rule {
|
match rule {
|
||||||
Rule::tuple_type => Ok(TypeExprKind::Tuple(collect_recovered(inner).get()?)),
|
Rule::tuple_type => ast_expr!(TypeExprKind::Tuple(collect_recovered(inner))),
|
||||||
Rule::path_type => {
|
Rule::path_type => {
|
||||||
let path = Path::try_from(inner.next().unwrap()).get()?;
|
let path = Path::try_from(inner.next().unwrap());
|
||||||
let params = collect_recovered(inner).get()?;
|
let params = collect_recovered(inner);
|
||||||
|
|
||||||
if params.len() == 0 {
|
if params.len() == 0 {
|
||||||
Ok(TypeExprKind::Path(path))
|
ast_expr!(TypeExprKind::Path(path))
|
||||||
} else {
|
} else {
|
||||||
Ok(TypeExprKind::PathParams(path, params))
|
ast_expr!(TypeExprKind::PathParams(path, params))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unimplemented!("{rule:#?}"),
|
_ => unimplemented!("{rule:#?}"),
|
||||||
@@ -71,15 +72,14 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TypeExpr {
|
|||||||
let mut inner = pair.into_inner();
|
let mut inner = pair.into_inner();
|
||||||
|
|
||||||
match rule {
|
match rule {
|
||||||
Rule::type_expr => Ok(TypeExpr(
|
Rule::type_expr => ast_expr!(TypeExpr(
|
||||||
inner.next().unwrap().try_into().get()?,
|
inner.next().unwrap().try_into(),
|
||||||
collect_recovered(inner).get()?,
|
collect_recovered(inner),
|
||||||
)),
|
)),
|
||||||
Rule::type_expr_param => Self::try_from(inner.next().unwrap()),
|
Rule::type_expr_param => Self::try_from(inner.next().unwrap()),
|
||||||
Rule::lifetime => Ok(TypeExpr(
|
Rule::lifetime => ast_expr!(TypeExprKind::Lifetime(inner.next().unwrap().try_into()))
|
||||||
TypeExprKind::Lifetime(inner.next().unwrap().try_into().get()?),
|
.get_map(TypeExpr::no_px)
|
||||||
Vec::new(),
|
.map(TypeExpr::no_px),
|
||||||
)),
|
|
||||||
_ => unimplemented!("{rule:#?}"),
|
_ => unimplemented!("{rule:#?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Generics {
|
|||||||
let inner = pair.clone().into_inner();
|
let inner = pair.clone().into_inner();
|
||||||
|
|
||||||
match rule {
|
match rule {
|
||||||
Rule::generics => Ok(Generics(collect_recovered(inner).get()?)),
|
Rule::generics => ast_expr!(Generics(collect_recovered(inner))),
|
||||||
_ => unimplemented!("{rule:#?}"),
|
_ => unimplemented!("{rule:#?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,13 +106,13 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for Generic {
|
|||||||
let mut inner = pair.clone().into_inner();
|
let mut inner = pair.clone().into_inner();
|
||||||
|
|
||||||
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
if let Some(pair) = consume_rule(&mut inner, Rule::lifetime) {
|
||||||
Ok(Generic::Lifetime(
|
ast_expr!(Generic::Lifetime(
|
||||||
pair.into_inner().next().unwrap().try_into().get()?,
|
pair.into_inner().next().unwrap().try_into(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(Generic::Type(
|
ast_expr!(Generic::Type(
|
||||||
inner.next().unwrap().try_into().get()?,
|
inner.next().unwrap().try_into(),
|
||||||
collect_recovered(inner).get()?,
|
collect_recovered(inner),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user