From c12cb99b24cc439d2650078a13509af4b75c8d2e Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 18 Sep 2019 10:07:20 -0700 Subject: [PATCH] ItemId on statement --- schala-lang/language/src/ast.rs | 5 ++++- schala-lang/language/src/parsing.rs | 4 ++-- schala-lang/language/src/parsing/test.rs | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index ff813e0..bf77ef1 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -83,8 +83,11 @@ pub struct AST { pub statements: Vec> } -#[derive(Debug, PartialEq, Clone)] +#[derive(Derivative, Debug, Clone)] +#[derivative(PartialEq)] pub struct Statement { + #[derivative(PartialEq="ignore")] + pub id: ItemId, pub kind: StatementKind, } diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index d364395..b1b7ec8 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -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)]) } } diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 5f720e7..b0bf34e 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -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) => { {