Added fairly limited type inference

This commit is contained in:
Mia
2026-03-07 19:16:29 +01:00
parent 168a12b4fc
commit 2aababbbe1
5 changed files with 102 additions and 18 deletions
+8 -1
View File
@@ -178,8 +178,15 @@ pub struct Field {
#[derive(Debug)]
pub struct StructCtor {
pub r#type: Expr,
pub r#type: Option<Expr>,
pub r#values: IndexMap<Substr, NameValuePair>,
pub(crate) range: Range<usize>,
}
impl StructCtor {
pub fn range(&self) -> Range<usize> {
self.range.clone()
}
}
#[derive(Debug)]
+11 -2
View File
@@ -81,9 +81,18 @@ peg::parser! {
lhs:@ "(" __ args:(expr() ** list_separator()) __ ")" { Expr::Call { func: lhs.into(), args } }
value:@ "[" __ index:expr() __ "]" { Expr::Index(IndexingExpr { value, index }.into()) }
r#type:@ __ "#{" __ values:name_value_pairs() __ "}" { Expr::Struct(
ty:@ __ "#{" __ values:name_value_pairs() __ "}" e:position!() { Expr::Struct(
StructCtor {
r#type, values: values.into_iter().map(|v| (v.name.0.clone(), v)).collect()
range: ty.range().start..e,
r#type: Some(ty),
values: values.into_iter().map(|v| (v.name.0.clone(), v)).collect(),
}.into()
) }
s:position!() "#{" __ values:name_value_pairs() __ "}" e:position!() { Expr::Struct(
StructCtor {
r#type: None,
values: values.into_iter().map(|v| (v.name.0.clone(), v)).collect(),
range: s..e,
}.into()
) }
--