cl-ast: Re-add(?) the Infer type-pattern
This commit is contained in:
parent
584207fc8c
commit
11c8daaed0
@ -221,6 +221,7 @@ pub struct Ty {
|
|||||||
pub enum TyKind {
|
pub enum TyKind {
|
||||||
Never,
|
Never,
|
||||||
Empty,
|
Empty,
|
||||||
|
Infer,
|
||||||
Path(Path),
|
Path(Path),
|
||||||
Array(TyArray),
|
Array(TyArray),
|
||||||
Slice(TySlice),
|
Slice(TySlice),
|
||||||
|
@ -149,7 +149,7 @@ mod display {
|
|||||||
' '.fmt(f)?;
|
' '.fmt(f)?;
|
||||||
write!(f.delimit(BRACES), "{items}")
|
write!(f.delimit(BRACES), "{items}")
|
||||||
}
|
}
|
||||||
None => Ok(())
|
None => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,6 +290,7 @@ mod display {
|
|||||||
match self {
|
match self {
|
||||||
TyKind::Never => "!".fmt(f),
|
TyKind::Never => "!".fmt(f),
|
||||||
TyKind::Empty => "()".fmt(f),
|
TyKind::Empty => "()".fmt(f),
|
||||||
|
TyKind::Infer => "_".fmt(f),
|
||||||
TyKind::Path(v) => v.fmt(f),
|
TyKind::Path(v) => v.fmt(f),
|
||||||
TyKind::Array(v) => v.fmt(f),
|
TyKind::Array(v) => v.fmt(f),
|
||||||
TyKind::Slice(v) => v.fmt(f),
|
TyKind::Slice(v) => v.fmt(f),
|
||||||
|
@ -523,6 +523,7 @@ pub fn or_fold_ty_kind<F: Fold + ?Sized>(folder: &mut F, kind: TyKind) -> TyKind
|
|||||||
match kind {
|
match kind {
|
||||||
TyKind::Never => TyKind::Never,
|
TyKind::Never => TyKind::Never,
|
||||||
TyKind::Empty => TyKind::Empty,
|
TyKind::Empty => TyKind::Empty,
|
||||||
|
TyKind::Infer => TyKind::Infer,
|
||||||
TyKind::Path(p) => TyKind::Path(folder.fold_path(p)),
|
TyKind::Path(p) => TyKind::Path(folder.fold_path(p)),
|
||||||
TyKind::Array(a) => TyKind::Array(folder.fold_ty_array(a)),
|
TyKind::Array(a) => TyKind::Array(folder.fold_ty_array(a)),
|
||||||
TyKind::Slice(s) => TyKind::Slice(folder.fold_ty_slice(s)),
|
TyKind::Slice(s) => TyKind::Slice(folder.fold_ty_slice(s)),
|
||||||
|
@ -455,6 +455,7 @@ pub fn or_visit_ty_kind<'a, V: Visit<'a>>(visitor: &mut V, kind: &'a TyKind) {
|
|||||||
match kind {
|
match kind {
|
||||||
TyKind::Never => {}
|
TyKind::Never => {}
|
||||||
TyKind::Empty => {}
|
TyKind::Empty => {}
|
||||||
|
TyKind::Infer => {}
|
||||||
TyKind::Path(p) => visitor.visit_path(p),
|
TyKind::Path(p) => visitor.visit_path(p),
|
||||||
TyKind::Array(t) => visitor.visit_ty_array(t),
|
TyKind::Array(t) => visitor.visit_ty_array(t),
|
||||||
TyKind::Slice(t) => visitor.visit_ty_slice(t),
|
TyKind::Slice(t) => visitor.visit_ty_slice(t),
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use cl_ast::{ast_visitor::Visit, *};
|
use cl_ast::{ast_visitor::Visit, *};
|
||||||
use cl_structures::intern::interned::Interned;
|
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
/// A work-in-progress tree walk interpreter for Conlang
|
/// A work-in-progress tree walk interpreter for Conlang
|
||||||
pub trait Interpret {
|
pub trait Interpret {
|
||||||
|
@ -496,7 +496,7 @@ impl Parse<'_> for TypedParam {
|
|||||||
if p.match_type(TokenKind::Colon, Parsing::Param).is_ok() {
|
if p.match_type(TokenKind::Colon, Parsing::Param).is_ok() {
|
||||||
TyKind::parse(p)?
|
TyKind::parse(p)?
|
||||||
} else {
|
} else {
|
||||||
TyKind::Path(Path::from(Sym::from("_")))
|
TyKind::Infer
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -742,7 +742,14 @@ impl Parse<'_> for TyKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TokenKind::Fn => TyFn::parse(p)?.into(),
|
TokenKind::Fn => TyFn::parse(p)?.into(),
|
||||||
path_like!() => Path::parse(p)?.into(),
|
path_like!() => {
|
||||||
|
let path = Path::parse(p)?;
|
||||||
|
if path.is_sinkhole() {
|
||||||
|
TyKind::Infer
|
||||||
|
} else {
|
||||||
|
TyKind::Path(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
t => Err(p.error(Unexpected(t), P))?,
|
t => Err(p.error(Unexpected(t), P))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -637,6 +637,7 @@ pub mod yamlify {
|
|||||||
match self {
|
match self {
|
||||||
TyKind::Never => y.value("Never"),
|
TyKind::Never => y.value("Never"),
|
||||||
TyKind::Empty => y.value("Empty"),
|
TyKind::Empty => y.value("Empty"),
|
||||||
|
TyKind::Infer => y.value("_"),
|
||||||
TyKind::Path(t) => y.yaml(t),
|
TyKind::Path(t) => y.yaml(t),
|
||||||
TyKind::Tuple(t) => y.yaml(t),
|
TyKind::Tuple(t) => y.yaml(t),
|
||||||
TyKind::Ref(t) => y.yaml(t),
|
TyKind::Ref(t) => y.yaml(t),
|
||||||
|
@ -42,6 +42,10 @@ impl TypeExpression for TyKind {
|
|||||||
match self {
|
match self {
|
||||||
TyKind::Never => Ok(table.anon_type(TypeKind::Never)),
|
TyKind::Never => Ok(table.anon_type(TypeKind::Never)),
|
||||||
TyKind::Empty => Ok(table.anon_type(TypeKind::Empty)),
|
TyKind::Empty => Ok(table.anon_type(TypeKind::Empty)),
|
||||||
|
TyKind::Infer => {
|
||||||
|
eprintln!("TODO: Introduce type variables");
|
||||||
|
Err(Error::BadPath { parent: node, path: vec![PathPart::Ident("_".into())] })
|
||||||
|
}
|
||||||
TyKind::Path(p) => p.evaluate(table, node),
|
TyKind::Path(p) => p.evaluate(table, node),
|
||||||
TyKind::Array(a) => a.evaluate(table, node),
|
TyKind::Array(a) => a.evaluate(table, node),
|
||||||
TyKind::Slice(s) => s.evaluate(table, node),
|
TyKind::Slice(s) => s.evaluate(table, node),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user