Add ItemId type to AST
This commit is contained in:
parent
73519d5be5
commit
b517bc2366
@ -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<Expression> for Meta<Expression> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Derivative, Debug)]
|
||||
#[derivative(PartialEq)]
|
||||
pub struct AST {
|
||||
#[derivative(PartialEq="ignore")]
|
||||
pub id: ItemId,
|
||||
pub statements: Vec<Meta<Statement>>
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ impl Parser {
|
||||
),
|
||||
}
|
||||
}
|
||||
Ok(AST { statements })
|
||||
Ok(AST { id: ItemId::new(0), statements })
|
||||
}
|
||||
|
||||
/// `statement := expression | declaration`
|
||||
|
@ -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! {
|
||||
|
Loading…
Reference in New Issue
Block a user