Use macros to make types more concise
This commit is contained in:
parent
eec315dd58
commit
cea2f63b44
@ -1292,8 +1292,7 @@ fn a(x) {
|
|||||||
"#;
|
"#;
|
||||||
parse_test!(multiline2, AST(vec![Declaration(
|
parse_test!(multiline2, AST(vec![Declaration(
|
||||||
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
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]
|
#[test]
|
||||||
@ -1484,14 +1483,14 @@ fn a(x) {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parsing_lambdas() {
|
fn parsing_lambdas() {
|
||||||
parse_test! { r#"\(x) { x + 1}"#, single_expr!(
|
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![
|
parse_test!(r#"\ (x: Int, y) { a;b;c;}"#, AST(vec![
|
||||||
exst!(Lambda {
|
exst!(Lambda {
|
||||||
params: vec![(rc!(x), Some(ty!("Int"))), (rc!(y), None)],
|
params: vec![(rc!(x), Some(ty!("Int"))), (rc!(y), None)],
|
||||||
type_anno: 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 {
|
Lambda {
|
||||||
params: vec![(rc!(x), None)],
|
params: vec![(rc!(x), None)],
|
||||||
type_anno: None,
|
type_anno: None,
|
||||||
body: vec![exst!(val!("y"))] }
|
body: vec![exst!(s "y")] }
|
||||||
)),
|
)),
|
||||||
arguments: vec![ex!(NatLiteral(1))] })]));
|
arguments: vec![ex!(NatLiteral(1))] })]));
|
||||||
|
|
||||||
@ -1550,7 +1549,7 @@ fn a(x) {
|
|||||||
parse_test! {
|
parse_test! {
|
||||||
"for n <- someRange { f(n); }", AST(vec![
|
"for n <- someRange { f(n); }", AST(vec![
|
||||||
exst!(ForExpression { enumerators: vec![Enumerator { id: rc!(n), generator: ex!(val!("someRange"))}],
|
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![
|
"if x is Some(a) then { 4 } else { 9 }", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
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))]))) }
|
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![
|
"if x is Some(a) then 4 else 9", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
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))]))) }
|
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![
|
"if x is Something { a, b: x } then { 4 } else { 9 }", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Record(rc!(Something), vec![
|
Pattern::Record(rc!(Something), vec![
|
||||||
(rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))),
|
(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![
|
"if x is -1 then 1 else 2", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }),
|
Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }),
|
||||||
vec![exst!(NatLiteral(1))],
|
vec![exst!(NatLiteral(1))],
|
||||||
@ -1616,11 +1615,11 @@ fn a(x) {
|
|||||||
"if x is 1 then 1 else 2", AST(vec![
|
"if x is 1 then 1 else 2", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }),
|
Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }),
|
||||||
vec![exst!(NatLiteral(1))],
|
vec![exst!(s "1")],
|
||||||
Some(vec![exst!(NatLiteral(2))]),
|
Some(vec![exst!(s "2")]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1631,7 +1630,7 @@ fn a(x) {
|
|||||||
"if x is true then 1 else 2", AST(vec![
|
"if x is true then 1 else 2", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Literal(PatternLiteral::BoolPattern(true)),
|
Pattern::Literal(PatternLiteral::BoolPattern(true)),
|
||||||
vec![exst!(NatLiteral(1))],
|
vec![exst!(NatLiteral(1))],
|
||||||
@ -1646,11 +1645,11 @@ fn a(x) {
|
|||||||
"if x is \"gnosticism\" then 1 else 2", AST(vec![
|
"if x is \"gnosticism\" then 1 else 2", AST(vec![
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
|
Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
|
||||||
vec![exst!(NatLiteral(1))],
|
vec![exst!(s "1")],
|
||||||
Some(vec![exst!(NatLiteral(2))]),
|
Some(vec![exst!(s "2")]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user