ItemId on statement

This commit is contained in:
greg 2019-09-18 10:07:20 -07:00
parent 8dc8833eb3
commit c12cb99b24
3 changed files with 10 additions and 7 deletions

View File

@ -83,8 +83,11 @@ pub struct AST {
pub statements: Vec<Meta<Statement>>
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Derivative, Debug, Clone)]
#[derivative(PartialEq)]
pub struct Statement {
#[derivative(PartialEq="ignore")]
pub id: ItemId,
pub kind: StatementKind,
}

View File

@ -351,7 +351,7 @@ impl Parser {
Keyword(Impl) => self.impl_declaration().map(|decl| StatementKind::Declaration(decl)),
_ => self.expression().map(|expr| { StatementKind::Expression(expr.into()) } ),
}?;
Ok(Statement { kind })
Ok(Statement { kind, id: self.id_store.fresh() })
}
#[recursive_descent_method]
@ -1063,7 +1063,7 @@ impl Parser {
LCurlyBrace => self.block(),
_ => {
let expr = self.expression()?;
let s = Statement { kind: StatementKind::Expression(expr.into()) };
let s = Statement { id: self.id_store.fresh(), kind: StatementKind::Expression(expr.into()) };
Ok(vec![Meta::new(s)])
}
}

View File

@ -42,7 +42,7 @@ macro_rules! tys {
macro_rules! decl {
($expr_type:expr) => {
Statement { kind: StatementKind::Declaration($expr_type) }
Statement { id: ItemIdStore::new_id(), kind: StatementKind::Declaration($expr_type) }
};
}
@ -70,10 +70,10 @@ macro_rules! prefexp {
($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_str($op).unwrap(), bx!(Expression::new($lhs).into())) }
}
macro_rules! exst {
($expr_type:expr) => { Meta::new(Statement { kind: StatementKind::Expression(Expression::new($expr_type).into())}) };
($expr_type:expr, $type_anno:expr) => { Meta::new(Statement { kind: StatementKind::Expression(Expression::with_anno($expr_type, $type_anno).into())}) };
($expr_type:expr) => { Meta::new(Statement { id: ItemIdStore::new_id(), kind: StatementKind::Expression(Expression::new($expr_type).into())}) };
($expr_type:expr, $type_anno:expr) => { Meta::new(Statement { id: ItemIdStore::new_id(), kind: StatementKind::Expression(Expression::with_anno($expr_type, $type_anno).into())}) };
($op:expr, $lhs:expr, $rhs:expr) => { Meta::new(
Statement { kind: StatementKind::Expression(ex!(binexp!($op, $lhs, $rhs)))}
Statement { id: ItemIdStore::new_id(), ,kind: StatementKind::Expression(ex!(binexp!($op, $lhs, $rhs)))}
)};
(s $statement_text:expr) => {
{