diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index 491776a..3a973ad 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -1,6 +1,7 @@ use std::rc::Rc; use std::convert::From; +use crate::derivative::Derivative; use crate::typechecking::TypeData; use crate::symbol_table::FullyQualifiedSymbolName; @@ -52,8 +53,11 @@ impl From for Meta { } } -#[derive(Debug, PartialEq)] +#[derive(Derivative, Debug)] +#[derivative(PartialEq)] pub struct AST { + #[derivative(PartialEq="ignore")] + pub id: ItemId, pub statements: Vec> } diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index e601ac3..ea13cec 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -334,7 +334,7 @@ impl Parser { ), } } - Ok(AST { statements }) + Ok(AST { id: ItemId::new(0), statements }) } /// `statement := expression | declaration` diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index 06fd114..8a95a84 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use super::tokenize; use super::ParseResult; -use crate::ast::{AST, Meta, Expression, Statement, StatementKind, IfExpressionBody, Discriminator, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody, InvocationArgument, FormalParam, PrefixOp, BinOp, QualifiedName}; +use crate::ast::{ItemId, AST, Meta, Expression, Statement, StatementKind, IfExpressionBody, Discriminator, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody, InvocationArgument, FormalParam, PrefixOp, BinOp, QualifiedName}; use super::Declaration::*; use super::Signature; use super::TypeIdentifier::*; @@ -25,7 +25,7 @@ macro_rules! parse_test { }; } macro_rules! parse_test_wrap_ast { - ($string:expr, $correct:expr) => { parse_test!($string, AST { statements: vec![$correct] }) } + ($string:expr, $correct:expr) => { parse_test!($string, AST { id: ItemId::new(4), statements: vec![$correct] }) } } macro_rules! parse_error { ($string:expr) => { assert!(parse($string).is_err()) } @@ -99,6 +99,7 @@ fn parsing_number_literals_and_binexps() { parse_test! {"3; 4; 4.3", AST { + id: ItemId::new(0), statements: vec![exst!(NatLiteral(3)), exst!(NatLiteral(4)), exst!(FloatLiteral(4.3))] } @@ -549,6 +550,7 @@ fn more_advanced_lambdas() { r#"fn wahoo() { let a = 10; \(x) { x + a } }; wahoo()(3) "#, AST { + id: ItemId::new(0), statements: vec![ exst!(s r"fn wahoo() { let a = 10; \(x) { x + a } }"), exst! {