Added fairly limited type inference
This commit is contained in:
+8
-1
@@ -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
@@ -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()
|
||||
) }
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user