From b35262c4443ee6e7354956ead01d86bb048f62ff Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 21 Feb 2019 01:49:15 -0800 Subject: [PATCH] Rename Node -> Meta --- schala-lang/language/src/ast.rs | 28 +++++------ schala-lang/language/src/parsing.rs | 66 ++++++++++++------------- schala-lang/language/src/reduced_ast.rs | 4 +- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/schala-lang/language/src/ast.rs b/schala-lang/language/src/ast.rs index cf1f89f..aa23496 100644 --- a/schala-lang/language/src/ast.rs +++ b/schala-lang/language/src/ast.rs @@ -5,15 +5,15 @@ use crate::builtin::{BinOp, PrefixOp}; use crate::typechecking::TypeData; #[derive(Clone, Debug, PartialEq)] -pub struct Node { +pub struct Meta { n: T, source_map: SourceMap, type_data: TypeData, } -impl Node { - pub fn new(n: T) -> Node { - Node { n, source_map: SourceMap::default(), type_data: TypeData::new() } +impl Meta { + pub fn new(n: T) -> Meta { + Meta { n, source_map: SourceMap::default(), type_data: TypeData::new() } } pub fn node(&self) -> &T { @@ -26,22 +26,22 @@ impl Node { struct SourceMap { } -impl From for Node { - fn from(expr: Expression) -> Node { - Node { n: expr, source_map: SourceMap::default(), type_data: TypeData::new() } +impl From for Meta { + fn from(expr: Expression) -> Meta { + Meta { n: expr, source_map: SourceMap::default(), type_data: TypeData::new() } } } #[derive(Debug, PartialEq)] -pub struct AST(pub Vec>); +pub struct AST(pub Vec>); #[derive(Debug, PartialEq, Clone)] pub enum Statement { - ExpressionStatement(Node), + ExpressionStatement(Meta), Declaration(Declaration), } -pub type Block = Vec>; +pub type Block = Vec>; pub type ParamName = Rc; pub type FormalParam = (ParamName, Option); @@ -115,9 +115,9 @@ pub enum ExpressionKind { FloatLiteral(f64), StringLiteral(Rc), BoolLiteral(bool), - BinExp(BinOp, Box>, Box>), - PrefixExp(PrefixOp, Box>), - TupleLiteral(Vec>), + BinExp(BinOp, Box>, Box>), + PrefixExp(PrefixOp, Box>), + TupleLiteral(Vec>), Value(Rc), NamedStruct { name: Rc, @@ -125,7 +125,7 @@ pub enum ExpressionKind { }, Call { f: Box, - arguments: Vec>, + arguments: Vec>, }, Index { indexee: Box, diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index a2b83b6..a17a3d2 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -288,7 +288,7 @@ impl Parser { continue; }, _ => statements.push( - Node::new(self.statement()?) + Meta::new(self.statement()?) ), } } @@ -413,9 +413,9 @@ impl Parser { } #[recursive_descent_method] - fn nonempty_func_body(&mut self) -> ParseResult>> { + fn nonempty_func_body(&mut self) -> ParseResult>> { let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict); - Ok(statements.into_iter().map(|s| Node::new(s)).collect()) + Ok(statements.into_iter().map(|s| Meta::new(s)).collect()) } #[recursive_descent_method] @@ -589,7 +589,7 @@ impl Parser { let mut expr = self.index_expr()?; while let LParen = self.token_handler.peek_kind() { let arguments = delimited!(self, LParen, expression, Comma, RParen); - let arguments = arguments.into_iter().map(|s| Node::new(s)).collect(); + let arguments = arguments.into_iter().map(|s| Meta::new(s)).collect(); expr = Expression(ExpressionKind::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect } @@ -669,7 +669,7 @@ impl Parser { 0 => Ok(Expression(TupleLiteral(vec![]), None)), 1 => Ok(inner.pop().unwrap()), _ => { - let inner: Vec> = inner.into_iter().map(|ex| ex.into()).collect(); + let inner: Vec> = inner.into_iter().map(|ex| ex.into()).collect(); Ok(Expression(TupleLiteral(inner), None)) } } @@ -904,7 +904,7 @@ impl Parser { #[recursive_descent_method] fn block(&mut self) -> ParseResult { let block = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict); - Ok(block.into_iter().map(|s| { Node::new(s) }).collect()) + Ok(block.into_iter().map(|s| { Meta::new(s) }).collect()) } #[recursive_descent_method] @@ -913,7 +913,7 @@ impl Parser { LCurlyBrace => self.block(), _ => { let expr = self.expression()?; - Ok(vec![Node::new(Statement::ExpressionStatement(expr.into()))]) + Ok(vec![Meta::new(Statement::ExpressionStatement(expr.into()))]) } } } @@ -973,7 +973,7 @@ impl Parser { Ok(match tok.get_kind() { LCurlyBrace => { let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict); - StatementBlock(statements.into_iter().map(|s| Node::new(s)).collect()) + StatementBlock(statements.into_iter().map(|s| Meta::new(s)).collect()) }, Keyword(Kw::Return) => { self.token_handler.next(); @@ -1117,7 +1117,7 @@ mod parse_tests { use super::tokenize; use super::ParseResult; use crate::builtin::{PrefixOp, BinOp}; - use crate::ast::{AST, Node, Expression, Statement, IfExpressionBody, Discriminator, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody}; + use crate::ast::{AST, Meta, Expression, Statement, IfExpressionBody, Discriminator, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody}; use super::Statement::*; use super::Declaration::*; use super::Signature; @@ -1173,14 +1173,14 @@ mod parse_tests { ($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_sigil($op), bx!(Expression($lhs, None).into())) } } macro_rules! exst { - ($expr_type:expr) => { Node::new(Statement::ExpressionStatement(Expression($expr_type, None).into())) }; - ($expr_type:expr, $type_anno:expr) => { Node::new(Statement::ExpressionStatement(Expression($expr_type, Some($type_anno)).into())) }; - ($op:expr, $lhs:expr, $rhs:expr) => { Node::new(Statement::ExpressionStatement(ex!(binexp!($op, $lhs, $rhs)))) }; + ($expr_type:expr) => { Meta::new(Statement::ExpressionStatement(Expression($expr_type, None).into())) }; + ($expr_type:expr, $type_anno:expr) => { Meta::new(Statement::ExpressionStatement(Expression($expr_type, Some($type_anno)).into())) }; + ($op:expr, $lhs:expr, $rhs:expr) => { Meta::new(Statement::ExpressionStatement(ex!(binexp!($op, $lhs, $rhs)))) }; (s $statement_text:expr) => { { let tokens: Vec = tokenize($statement_text); let mut parser = super::Parser::new(tokens); - Node::new(parser.statement().unwrap()) + Meta::new(parser.statement().unwrap()) } } } @@ -1286,7 +1286,7 @@ mod parse_tests { #[test] fn parsing_functions() { - parse_test!("fn oi()", AST(vec![Node::new(Declaration(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None })))])); + parse_test!("fn oi()", AST(vec![Meta::new(Declaration(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None })))])); parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })])); parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), @@ -1294,16 +1294,16 @@ mod parse_tests { })])); parse_error!("a(b,,c)"); - parse_test!("fn a(b, c: Int): Int", AST(vec![Node::new(Declaration( + parse_test!("fn a(b, c: Int): Int", AST(vec![Meta::new(Declaration( FuncSig(Signature { name: rc!(a), operator: false, params: vec![ (rc!(b), None), (rc!(c), Some(ty!("Int"))) ], type_anno: Some(ty!("Int")) })))])); - parse_test!("fn a(x) { x() }", AST(vec![Node::new(Declaration( + parse_test!("fn a(x) { x() }", AST(vec![Meta::new(Declaration( FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None }, vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])))])); - parse_test!("fn a(x) {\n x() }", AST(vec![Node::new(Declaration( + parse_test!("fn a(x) {\n x() }", AST(vec![Meta::new(Declaration( FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None }, vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])))])); @@ -1312,7 +1312,7 @@ fn a(x) { x() } "#; - parse_test!(multiline, AST(vec![Node::new(Declaration( + parse_test!(multiline, AST(vec![Meta::new(Declaration( FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None }, vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])))])); let multiline2 = r#" @@ -1322,7 +1322,7 @@ fn a(x) { } "#; - parse_test!(multiline2, AST(vec![Node::new(Declaration( + parse_test!(multiline2, AST(vec![Meta::new(Declaration( FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None }, vec![exst!(s "x()")])))])); } @@ -1340,11 +1340,11 @@ fn a(x) { #[test] fn parsing_types() { - parse_test!("type Yolo = Yolo", AST(vec![Node::new(Declaration(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: false} ))])); - parse_test!("type mut Yolo = Yolo", AST(vec![Node::new(Declaration(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: true} ))])); - parse_test!("type alias Sex = Drugs", AST(vec![Node::new(Declaration(TypeAlias(rc!(Sex), rc!(Drugs))))])); + parse_test!("type Yolo = Yolo", AST(vec![Meta::new(Declaration(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: false} ))])); + parse_test!("type mut Yolo = Yolo", AST(vec![Meta::new(Declaration(TypeDecl { name: tys!("Yolo"), body: TypeBody(vec![UnitStruct(rc!(Yolo))]), mutable: true} ))])); + parse_test!("type alias Sex = Drugs", AST(vec![Meta::new(Declaration(TypeAlias(rc!(Sex), rc!(Drugs))))])); parse_test!("type Sanchez = Miguel | Alejandro(Int, Option) | Esperanza { a: Int, b: String }", - AST(vec![Node::new(Declaration(TypeDecl{ + AST(vec![Meta::new(Declaration(TypeDecl{ name: tys!("Sanchez"), body: TypeBody(vec![ UnitStruct(rc!(Miguel)), @@ -1364,7 +1364,7 @@ fn a(x) { }))])); parse_test!("type Jorge = Diego | Kike(a)", AST(vec![ - Node::new(Declaration(TypeDecl{ + Meta::new(Declaration(TypeDecl{ name: TypeSingletonName { name: rc!(Jorge), params: vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })] }, body: TypeBody(vec![UnitStruct(rc!(Diego)), TupleStruct(rc!(Kike), vec![Singleton(TypeSingletonName { name: rc!(a), params: vec![] })])]), mutable: false @@ -1374,9 +1374,9 @@ fn a(x) { #[test] fn parsing_bindings() { - parse_test!("let mut a = 10", AST(vec![Node::new(Declaration(Binding { name: rc!(a), constant: false, type_anno: None, expr: ex!(NatLiteral(10)) } ))])); - parse_test!("let a = 2 + 2", AST(vec![Node::new(Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) }) )])); - parse_test!("let a: Nat = 2 + 2", AST(vec![Node::new(Declaration( + parse_test!("let mut a = 10", AST(vec![Meta::new(Declaration(Binding { name: rc!(a), constant: false, type_anno: None, expr: ex!(NatLiteral(10)) } ))])); + parse_test!("let a = 2 + 2", AST(vec![Meta::new(Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) }) )])); + parse_test!("let a: Nat = 2 + 2", AST(vec![Meta::new(Declaration( Binding { name: rc!(a), constant: true, type_anno: Some(Singleton(TypeSingletonName { name: rc!(Nat), params: vec![] })), expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) } ))])); @@ -1453,7 +1453,7 @@ fn a(x) { #[test] fn parsing_interfaces() { parse_test!("interface Unglueable { fn unglue(a: Glue); fn mar(): Glue }", AST(vec![ - Node::new(Declaration(Interface { + Meta::new(Declaration(Interface { name: rc!(Unglueable), signatures: vec![ Signature { name: rc!(unglue), operator: false, params: vec![(rc!(a), Some(Singleton(TypeSingletonName { name: rc!(Glue), params: vec![] })))], type_anno: None }, @@ -1466,7 +1466,7 @@ fn a(x) { #[test] fn parsing_impls() { parse_test!("impl Heh { fn yolo(); fn swagg(); }", AST(vec![ - Node::new( + Meta::new( Declaration(Impl { type_name: ty!("Heh"), interface_name: None, @@ -1476,7 +1476,7 @@ fn a(x) { ] }))])); parse_test!("impl Mondai for Lollerino { fn yolo(); fn swagg(); }", AST(vec![ - Node::new(Declaration(Impl { + Meta::new(Declaration(Impl { type_name: ty!("Lollerino"), interface_name: Some(TypeSingletonName { name: rc!(Mondai), params: vec![] }), block: vec![ @@ -1485,7 +1485,7 @@ fn a(x) { ] }))])); parse_test!("impl Hella for (Alpha, Omega) { }", AST(vec![ - Node::new(Declaration(Impl { + Meta::new(Declaration(Impl { type_name: Tuple(vec![ty!("Alpha"), ty!("Omega")]), interface_name: Some(TypeSingletonName { name: rc!(Hella), params: vec![ty!("T")] }), block: vec![] @@ -1493,7 +1493,7 @@ fn a(x) { ])); parse_test!("impl Option { fn oi() }", AST(vec![ - Node::new( + Meta::new( Declaration(Impl { type_name: Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("WTFMate")]}), interface_name: None, @@ -1506,7 +1506,7 @@ fn a(x) { #[test] fn parsing_type_annotations() { parse_test!("let a = b : Int", AST(vec![ - Node::new( + Meta::new( Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr: Expression(val!("b"), Some(ty!("Int"))) }))])); diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 8a6adce..cbd1335 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -377,7 +377,7 @@ impl Declaration { } impl BinOp { - fn reduce(&self, symbol_table: &SymbolTable, lhs: &Box>, rhs: &Box>) -> Expr { + fn reduce(&self, symbol_table: &SymbolTable, lhs: &Box>, rhs: &Box>) -> Expr { if **self.sigil() == "=" { Expr::Assign { val: Box::new(lhs.node().reduce(symbol_table)), @@ -391,7 +391,7 @@ impl BinOp { } impl PrefixOp { - fn reduce(&self, symbol_table: &SymbolTable, arg: &Box>) -> Expr { + fn reduce(&self, symbol_table: &SymbolTable, arg: &Box>) -> Expr { let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone()))); Expr::Call { f, args: vec![arg.node().reduce(symbol_table)]} }