forked from Orchid/orchid
bkp
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use orchid_base::location::Pos;
|
||||
|
||||
use crate::{atom::{AtomicFeatures, TypAtom}, error::{ProjectError, ProjectResult}, expr::{atom, bot_obj, ExprHandle, GenExpr, OwnedExpr}, system::downcast_atom};
|
||||
use crate::atom::{AtomicFeatures, TypAtom};
|
||||
use crate::error::{ProjectError, ProjectResult};
|
||||
use crate::expr::{atom, bot_obj, ExprHandle, GenExpr, OwnedExpr};
|
||||
use crate::system::downcast_atom;
|
||||
|
||||
pub trait TryFromExpr: Sized {
|
||||
fn try_from_expr(expr: ExprHandle) -> ProjectResult<Self>;
|
||||
@@ -25,14 +28,14 @@ impl ProjectError for ErrorNotAtom {
|
||||
pub struct ErrorUnexpectedType(Pos);
|
||||
impl ProjectError for ErrorUnexpectedType {
|
||||
const DESCRIPTION: &'static str = "Type error";
|
||||
fn one_position(&self) -> Pos {
|
||||
self.0.clone()
|
||||
}
|
||||
fn one_position(&self) -> Pos { self.0.clone() }
|
||||
}
|
||||
|
||||
impl<A: AtomicFeatures> TryFromExpr for TypAtom<A> {
|
||||
fn try_from_expr(expr: ExprHandle) -> ProjectResult<Self> {
|
||||
OwnedExpr::new(expr).foreign_atom().map_err(|ex| ErrorNotAtom(ex.pos.clone()).pack())
|
||||
OwnedExpr::new(expr)
|
||||
.foreign_atom()
|
||||
.map_err(|ex| ErrorNotAtom(ex.pos.clone()).pack())
|
||||
.and_then(|f| downcast_atom(f).map_err(|f| ErrorUnexpectedType(f.pos).pack()))
|
||||
}
|
||||
}
|
||||
@@ -43,13 +46,13 @@ pub trait ToExpr {
|
||||
|
||||
impl<T: ToExpr> ToExpr for ProjectResult<T> {
|
||||
fn to_expr(self) -> GenExpr {
|
||||
match self {
|
||||
Err(e) => bot_obj(e),
|
||||
Ok(t) => t.to_expr(),
|
||||
}
|
||||
match self {
|
||||
Err(e) => bot_obj(e),
|
||||
Ok(t) => t.to_expr(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AtomicFeatures> ToExpr for A {
|
||||
fn to_expr(self) -> GenExpr { atom(self) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user