cl-ast: Re-add(?) the Infer type-pattern
This commit is contained in:
		| @@ -221,6 +221,7 @@ pub struct Ty { | ||||
| pub enum TyKind { | ||||
|     Never, | ||||
|     Empty, | ||||
|     Infer, | ||||
|     Path(Path), | ||||
|     Array(TyArray), | ||||
|     Slice(TySlice), | ||||
|   | ||||
| @@ -149,7 +149,7 @@ mod display { | ||||
|                     ' '.fmt(f)?; | ||||
|                     write!(f.delimit(BRACES), "{items}") | ||||
|                 } | ||||
|                 None => Ok(()) | ||||
|                 None => Ok(()), | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @@ -216,7 +216,7 @@ mod display { | ||||
|             let Self { name, variants: kind } = self; | ||||
|             write!(f, "enum {name}")?; | ||||
|             match kind { | ||||
|                 Some(v) =>  separate(v, ",\n")(f.delimit(SPACED_BRACES)), | ||||
|                 Some(v) => separate(v, ",\n")(f.delimit(SPACED_BRACES)), | ||||
|                 None => ";".fmt(f), | ||||
|             } | ||||
|         } | ||||
| @@ -290,6 +290,7 @@ mod display { | ||||
|             match self { | ||||
|                 TyKind::Never => "!".fmt(f), | ||||
|                 TyKind::Empty => "()".fmt(f), | ||||
|                 TyKind::Infer => "_".fmt(f), | ||||
|                 TyKind::Path(v) => v.fmt(f), | ||||
|                 TyKind::Array(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 { | ||||
|         TyKind::Never => TyKind::Never, | ||||
|         TyKind::Empty => TyKind::Empty, | ||||
|         TyKind::Infer => TyKind::Infer, | ||||
|         TyKind::Path(p) => TyKind::Path(folder.fold_path(p)), | ||||
|         TyKind::Array(a) => TyKind::Array(folder.fold_ty_array(a)), | ||||
|         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 { | ||||
|         TyKind::Never => {} | ||||
|         TyKind::Empty => {} | ||||
|         TyKind::Infer => {} | ||||
|         TyKind::Path(p) => visitor.visit_path(p), | ||||
|         TyKind::Array(t) => visitor.visit_ty_array(t), | ||||
|         TyKind::Slice(t) => visitor.visit_ty_slice(t), | ||||
|   | ||||
| @@ -7,7 +7,6 @@ | ||||
|  | ||||
| use super::*; | ||||
| use cl_ast::{ast_visitor::Visit, *}; | ||||
| use cl_structures::intern::interned::Interned; | ||||
| use std::borrow::Borrow; | ||||
| /// A work-in-progress tree walk interpreter for Conlang | ||||
| pub trait Interpret { | ||||
|   | ||||
| @@ -496,7 +496,7 @@ impl Parse<'_> for TypedParam { | ||||
|             if p.match_type(TokenKind::Colon, Parsing::Param).is_ok() { | ||||
|                 TyKind::parse(p)? | ||||
|             } else { | ||||
|                 TyKind::Path(Path::from(Sym::from("_"))) | ||||
|                 TyKind::Infer | ||||
|             }, | ||||
|         )) | ||||
|     } | ||||
| @@ -742,7 +742,14 @@ impl Parse<'_> for TyKind { | ||||
|                 } | ||||
|             } | ||||
|             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))?, | ||||
|         }; | ||||
|  | ||||
|   | ||||
| @@ -637,6 +637,7 @@ pub mod yamlify { | ||||
|             match self { | ||||
|                 TyKind::Never => y.value("Never"), | ||||
|                 TyKind::Empty => y.value("Empty"), | ||||
|                 TyKind::Infer => y.value("_"), | ||||
|                 TyKind::Path(t) => y.yaml(t), | ||||
|                 TyKind::Tuple(t) => y.yaml(t), | ||||
|                 TyKind::Ref(t) => y.yaml(t), | ||||
|   | ||||
| @@ -42,6 +42,10 @@ impl TypeExpression for TyKind { | ||||
|         match self { | ||||
|             TyKind::Never => Ok(table.anon_type(TypeKind::Never)), | ||||
|             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::Array(a) => a.evaluate(table, node), | ||||
|             TyKind::Slice(s) => s.evaluate(table, node), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user