conlang: Add constructor expression for structs!
grammar: - Add new rules `PathLike`, `Structor`, `Fielder` - Replace Path with PathLike in Primary expressions cl-ast: - Add nodes for Structor and Fielder cl-parser: - Add branch to path-expression parsing - Parse Structor bodies interpret: - Add TODO
This commit is contained in:
@@ -424,6 +424,7 @@ mod display {
|
||||
ExprKind::Binary(v) => v.fmt(f),
|
||||
ExprKind::Unary(v) => v.fmt(f),
|
||||
ExprKind::Index(v) => v.fmt(f),
|
||||
ExprKind::Structor(v) => v.fmt(f),
|
||||
ExprKind::Path(v) => v.fmt(f),
|
||||
ExprKind::Literal(v) => v.fmt(f),
|
||||
ExprKind::Array(v) => v.fmt(f),
|
||||
@@ -540,6 +541,25 @@ mod display {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Structor {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { to, init } = self;
|
||||
write!(f, "{to}: ")?;
|
||||
separate(init, ", ")(f.delimit(INLINE_BRACES))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Fielder {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { name, init } = self;
|
||||
write!(f, "{name}")?;
|
||||
if let Some(init) = init {
|
||||
write!(f, ": {init}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Array {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
separate(&self.values, ", ")(f.delimit(INLINE_SQUARE))
|
||||
|
||||
Reference in New Issue
Block a user