From cea2f63b447c64356f20c53a2f12d7bf10854dff Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 5 Nov 2018 20:12:10 -0800 Subject: [PATCH] Use macros to make types more concise --- schala-lang/language/src/parsing.rs | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 3c24adc..4d944db 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -1292,8 +1292,7 @@ fn a(x) { "#; parse_test!(multiline2, AST(vec![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![] })]))])); - + vec![exst!(s "x()")]))])); } #[test] @@ -1484,14 +1483,14 @@ fn a(x) { #[test] fn parsing_lambdas() { parse_test! { r#"\(x) { x + 1}"#, single_expr!( - Lambda { params: vec![(rc!(x), None)], type_anno: None, body: vec![exst!("+", val!("x"), NatLiteral(1))] } + Lambda { params: vec![(rc!(x), None)], type_anno: None, body: vec![exst!(s "x + 1")] } ) } parse_test!(r#"\ (x: Int, y) { a;b;c;}"#, AST(vec![ exst!(Lambda { params: vec![(rc!(x), Some(ty!("Int"))), (rc!(y), None)], type_anno: None, - body: vec![exst!(val!("a")), exst!(val!("b")), exst!(val!("c"))] + body: vec![exst!(s "a"), exst!(s "b"), exst!(s "c")] }) ])); @@ -1500,7 +1499,7 @@ fn a(x) { Lambda { params: vec![(rc!(x), None)], type_anno: None, - body: vec![exst!(val!("y"))] } + body: vec![exst!(s "y")] } )), arguments: vec![ex!(NatLiteral(1))] })])); @@ -1550,7 +1549,7 @@ fn a(x) { parse_test! { "for n <- someRange { f(n); }", AST(vec![ exst!(ForExpression { enumerators: vec![Enumerator { id: rc!(n), generator: ex!(val!("someRange"))}], - body: bx!(ForBody::StatementBlock(vec![exst!(Call { f: bx![ex!(val!("f"))], arguments: vec![ex!(val!("n"))] })])) + body: bx!(ForBody::StatementBlock(vec![exst!(s "f(n)")])) })]) } } @@ -1561,7 +1560,7 @@ fn a(x) { "if x is Some(a) then { 4 } else { 9 }", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(rc!(Some), vec![Pattern::Literal(PatternLiteral::VarPattern(rc!(a)))]), vec![exst!(NatLiteral(4))], Some(vec![exst!(NatLiteral(9))]))) } ) ]) @@ -1571,7 +1570,7 @@ fn a(x) { "if x is Some(a) then 4 else 9", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(rc!(Some), vec![Pattern::Literal(PatternLiteral::VarPattern(rc!(a)))]), vec![exst!(NatLiteral(4))], Some(vec![exst!(NatLiteral(9))]))) } ) ]) @@ -1581,7 +1580,7 @@ fn a(x) { "if x is Something { a, b: x } then { 4 } else { 9 }", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch( Pattern::Record(rc!(Something), vec![ (rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))), @@ -1601,7 +1600,7 @@ fn a(x) { "if x is -1 then 1 else 2", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch( Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }), vec![exst!(NatLiteral(1))], @@ -1616,11 +1615,11 @@ fn a(x) { "if x is 1 then 1 else 2", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch( Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }), - vec![exst!(NatLiteral(1))], - Some(vec![exst!(NatLiteral(2))]), + vec![exst!(s "1")], + Some(vec![exst!(s "2")]), )) } ) @@ -1631,7 +1630,7 @@ fn a(x) { "if x is true then 1 else 2", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch( Pattern::Literal(PatternLiteral::BoolPattern(true)), vec![exst!(NatLiteral(1))], @@ -1646,11 +1645,11 @@ fn a(x) { "if x is \"gnosticism\" then 1 else 2", AST(vec![ exst!( IfExpression { - discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))), + discriminator: bx!(Discriminator::Simple(ex!(s "x"))), body: bx!(IfExpressionBody::SimplePatternMatch( Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))), - vec![exst!(NatLiteral(1))], - Some(vec![exst!(NatLiteral(2))]), + vec![exst!(s "1")], + Some(vec![exst!(s "2")]), )) } )