Get rid of exprstatement! macro
For shorter exst! one
This commit is contained in:
parent
1e9aa91c5d
commit
eec315dd58
@ -1121,17 +1121,6 @@ mod parse_tests {
|
|||||||
macro_rules! val {
|
macro_rules! val {
|
||||||
($var:expr) => { Value(Rc::new($var.to_string())) }
|
($var:expr) => { Value(Rc::new($var.to_string())) }
|
||||||
}
|
}
|
||||||
macro_rules! exprstatement {
|
|
||||||
($expr_type:expr) => { Statement::ExpressionStatement(Expression($expr_type, None)) };
|
|
||||||
($expr_type:expr, $type_anno:expr) => { Statement::ExpressionStatement(Expression($expr_type, Some($type_anno))) };
|
|
||||||
(s $statement_text:expr) => {
|
|
||||||
{
|
|
||||||
let tokens: Vec<::tokenizing::Token> = tokenize($statement_text);
|
|
||||||
let mut parser = super::Parser::new(tokens);
|
|
||||||
parser.statement().unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
macro_rules! ty {
|
macro_rules! ty {
|
||||||
($name:expr) => { Singleton(tys!($name)) }
|
($name:expr) => { Singleton(tys!($name)) }
|
||||||
}
|
}
|
||||||
@ -1166,6 +1155,13 @@ mod parse_tests {
|
|||||||
($expr_type:expr) => { Statement::ExpressionStatement(Expression($expr_type, None)) };
|
($expr_type:expr) => { Statement::ExpressionStatement(Expression($expr_type, None)) };
|
||||||
($expr_type:expr, $type_anno:expr) => { Statement::ExpressionStatement(Expression($expr_type, Some($type_anno))) };
|
($expr_type:expr, $type_anno:expr) => { Statement::ExpressionStatement(Expression($expr_type, Some($type_anno))) };
|
||||||
($op:expr, $lhs:expr, $rhs:expr) => { Statement::ExpressionStatement(ex!(binexp!($op, $lhs, $rhs))) };
|
($op:expr, $lhs:expr, $rhs:expr) => { Statement::ExpressionStatement(ex!(binexp!($op, $lhs, $rhs))) };
|
||||||
|
(s $statement_text:expr) => {
|
||||||
|
{
|
||||||
|
let tokens: Vec<::tokenizing::Token> = tokenize($statement_text);
|
||||||
|
let mut parser = super::Parser::new(tokens);
|
||||||
|
parser.statement().unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1179,46 +1175,46 @@ mod parse_tests {
|
|||||||
parse_test! {"0xff", single_expr!(NatLiteral(255)) };
|
parse_test! {"0xff", single_expr!(NatLiteral(255)) };
|
||||||
parse_test! {"0xf_f_", single_expr!(NatLiteral(255)) };
|
parse_test! {"0xf_f_", single_expr!(NatLiteral(255)) };
|
||||||
|
|
||||||
parse_test!("0xf_f_+1", AST(vec![exprstatement!(binexp!("+", NatLiteral(255), NatLiteral(1)))]));
|
parse_test!("0xf_f_+1", AST(vec![exst!(binexp!("+", NatLiteral(255), NatLiteral(1)))]));
|
||||||
|
|
||||||
parse_test! {"3; 4; 4.3", AST(
|
parse_test! {"3; 4; 4.3", AST(
|
||||||
vec![exprstatement!(NatLiteral(3)), exprstatement!(NatLiteral(4)),
|
vec![exst!(NatLiteral(3)), exst!(NatLiteral(4)),
|
||||||
exprstatement!(FloatLiteral(4.3))])
|
exst!(FloatLiteral(4.3))])
|
||||||
};
|
};
|
||||||
|
|
||||||
parse_test!("1 + 2 * 3", AST(vec!
|
parse_test!("1 + 2 * 3", AST(vec!
|
||||||
[
|
[
|
||||||
exprstatement!(binexp!("+", NatLiteral(1), binexp!("*", NatLiteral(2), NatLiteral(3))))
|
exst!(binexp!("+", NatLiteral(1), binexp!("*", NatLiteral(2), NatLiteral(3))))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!("1 * 2 + 3", AST(vec!
|
parse_test!("1 * 2 + 3", AST(vec!
|
||||||
[
|
[
|
||||||
exprstatement!(binexp!("+", binexp!("*", NatLiteral(1), NatLiteral(2)), NatLiteral(3)))
|
exst!(binexp!("+", binexp!("*", NatLiteral(1), NatLiteral(2)), NatLiteral(3)))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!("1 && 2", AST(vec![exprstatement!(binexp!("&&", NatLiteral(1), NatLiteral(2)))]));
|
parse_test!("1 && 2", AST(vec![exst!(binexp!("&&", NatLiteral(1), NatLiteral(2)))]));
|
||||||
|
|
||||||
parse_test!("1 + 2 * 3 + 4", AST(vec![exprstatement!(
|
parse_test!("1 + 2 * 3 + 4", AST(vec![exst!(
|
||||||
binexp!("+",
|
binexp!("+",
|
||||||
binexp!("+", NatLiteral(1), binexp!("*", NatLiteral(2), NatLiteral(3))),
|
binexp!("+", NatLiteral(1), binexp!("*", NatLiteral(2), NatLiteral(3))),
|
||||||
NatLiteral(4)))]));
|
NatLiteral(4)))]));
|
||||||
|
|
||||||
parse_test!("(1 + 2) * 3", AST(vec!
|
parse_test!("(1 + 2) * 3", AST(vec!
|
||||||
[exprstatement!(binexp!("*", binexp!("+", NatLiteral(1), NatLiteral(2)), NatLiteral(3)))]));
|
[exst!(binexp!("*", binexp!("+", NatLiteral(1), NatLiteral(2)), NatLiteral(3)))]));
|
||||||
|
|
||||||
parse_test!(".1 + .2", AST(vec![exprstatement!(binexp!("+", FloatLiteral(0.1), FloatLiteral(0.2)))]));
|
parse_test!(".1 + .2", AST(vec![exst!(binexp!("+", FloatLiteral(0.1), FloatLiteral(0.2)))]));
|
||||||
parse_test!("1 / 2", AST(vec![exprstatement!(binexp!("/", NatLiteral(1), NatLiteral(2)))]));
|
parse_test!("1 / 2", AST(vec![exst!(binexp!("/", NatLiteral(1), NatLiteral(2)))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_tuples() {
|
fn parsing_tuples() {
|
||||||
parse_test!("()", AST(vec![exprstatement!(TupleLiteral(vec![]))]));
|
parse_test!("()", AST(vec![exst!(TupleLiteral(vec![]))]));
|
||||||
parse_test!("(\"hella\", 34)", AST(vec![exprstatement!(
|
parse_test!("(\"hella\", 34)", AST(vec![exst!(
|
||||||
TupleLiteral(
|
TupleLiteral(
|
||||||
vec![ex!(s r#""hella""#), ex!(s "34")]
|
vec![ex!(s r#""hella""#), ex!(s "34")]
|
||||||
)
|
)
|
||||||
)]));
|
)]));
|
||||||
parse_test!("((1+2), \"slough\")", AST(vec![exprstatement!(TupleLiteral(vec![
|
parse_test!("((1+2), \"slough\")", AST(vec![exst!(TupleLiteral(vec![
|
||||||
ex!(binexp!("+", NatLiteral(1), NatLiteral(2))),
|
ex!(binexp!("+", NatLiteral(1), NatLiteral(2))),
|
||||||
ex!(StringLiteral(rc!(slough))),
|
ex!(StringLiteral(rc!(slough))),
|
||||||
]))]))
|
]))]))
|
||||||
@ -1226,41 +1222,41 @@ mod parse_tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_identifiers() {
|
fn parsing_identifiers() {
|
||||||
parse_test!("a", AST(vec![exprstatement!(val!("a"))]));
|
parse_test!("a", AST(vec![exst!(val!("a"))]));
|
||||||
parse_test!("a + b", AST(vec![exprstatement!(binexp!("+", val!("a"), val!("b")))]));
|
parse_test!("a + b", AST(vec![exst!(binexp!("+", val!("a"), val!("b")))]));
|
||||||
//parse_test!("a[b]", AST(vec![Expression(
|
//parse_test!("a[b]", AST(vec![Expression(
|
||||||
//parse_test!("a[]", <- TODO THIS NEEDS TO FAIL
|
//parse_test!("a[]", <- TODO THIS NEEDS TO FAIL
|
||||||
//parse_test!(damn()[a] ,<- TODO needs to succeed
|
//parse_test!(damn()[a] ,<- TODO needs to succeed
|
||||||
parse_test!("a[b,c]", AST(vec![exprstatement!(Index { indexee: bx!(ex!(val!("a"))), indexers: vec![ex!(val!("b")), ex!(val!("c"))]} )]));
|
parse_test!("a[b,c]", AST(vec![exst!(Index { indexee: bx!(ex!(val!("a"))), indexers: vec![ex!(val!("b")), ex!(val!("c"))]} )]));
|
||||||
|
|
||||||
parse_test!("None", AST(vec![exprstatement!(val!("None"))]));
|
parse_test!("None", AST(vec![exst!(val!("None"))]));
|
||||||
parse_test!("Pandas { a: x + y }", AST(vec![
|
parse_test!("Pandas { a: x + y }", AST(vec![
|
||||||
exprstatement!(NamedStruct { name: rc!(Pandas), fields: vec![(rc!(a), ex!(binexp!("+", val!("x"), val!("y"))))]})
|
exst!(NamedStruct { name: rc!(Pandas), fields: vec![(rc!(a), ex!(binexp!("+", val!("x"), val!("y"))))]})
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_complicated_operators() {
|
fn parsing_complicated_operators() {
|
||||||
parse_test!("a <- b", AST(vec![exprstatement!(binexp!("<-", val!("a"), val!("b")))]));
|
parse_test!("a <- b", AST(vec![exst!(binexp!("<-", val!("a"), val!("b")))]));
|
||||||
parse_test!("a || b", AST(vec![exprstatement!(binexp!("||", val!("a"), val!("b")))]));
|
parse_test!("a || b", AST(vec![exst!(binexp!("||", val!("a"), val!("b")))]));
|
||||||
parse_test!("a<>b", AST(vec![exprstatement!(binexp!("<>", val!("a"), val!("b")))]));
|
parse_test!("a<>b", AST(vec![exst!(binexp!("<>", val!("a"), val!("b")))]));
|
||||||
parse_test!("a.b.c.d", AST(vec![exprstatement!(binexp!(".",
|
parse_test!("a.b.c.d", AST(vec![exst!(binexp!(".",
|
||||||
binexp!(".",
|
binexp!(".",
|
||||||
binexp!(".", val!("a"), val!("b")),
|
binexp!(".", val!("a"), val!("b")),
|
||||||
val!("c")),
|
val!("c")),
|
||||||
val!("d")))]));
|
val!("d")))]));
|
||||||
parse_test!("-3", AST(vec![exprstatement!(prefexp!("-", NatLiteral(3)))]));
|
parse_test!("-3", AST(vec![exst!(prefexp!("-", NatLiteral(3)))]));
|
||||||
parse_test!("-0.2", AST(vec![exprstatement!(prefexp!("-", FloatLiteral(0.2)))]));
|
parse_test!("-0.2", AST(vec![exst!(prefexp!("-", FloatLiteral(0.2)))]));
|
||||||
parse_test!("!3", AST(vec![exprstatement!(prefexp!("!", NatLiteral(3)))]));
|
parse_test!("!3", AST(vec![exst!(prefexp!("!", NatLiteral(3)))]));
|
||||||
parse_test!("a <- -b", AST(vec![exprstatement!(binexp!("<-", val!("a"), prefexp!("-", val!("b"))))]));
|
parse_test!("a <- -b", AST(vec![exst!(binexp!("<-", val!("a"), prefexp!("-", val!("b"))))]));
|
||||||
parse_test!("a <--b", AST(vec![exprstatement!(binexp!("<--", val!("a"), val!("b")))]));
|
parse_test!("a <--b", AST(vec![exst!(binexp!("<--", val!("a"), val!("b")))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_functions() {
|
fn parsing_functions() {
|
||||||
parse_test!("fn oi()", AST(vec![Declaration(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None }))]));
|
parse_test!("fn oi()", AST(vec![Declaration(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None }))]));
|
||||||
parse_test!("oi()", AST(vec![exprstatement!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })]));
|
parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })]));
|
||||||
parse_test!("oi(a, 2 + 2)", AST(vec![exprstatement!(Call
|
parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call
|
||||||
{ f: bx!(ex!(val!("oi"))),
|
{ f: bx!(ex!(val!("oi"))),
|
||||||
arguments: vec![ex!(val!("a")), ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))]
|
arguments: vec![ex!(val!("a")), ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))]
|
||||||
})]));
|
})]));
|
||||||
@ -1274,10 +1270,10 @@ mod parse_tests {
|
|||||||
|
|
||||||
parse_test!("fn a(x) { x() }", AST(vec![Declaration(
|
parse_test!("fn a(x) { x() }", 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![exprstatement!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
||||||
parse_test!("fn a(x) {\n x() }", AST(vec![Declaration(
|
parse_test!("fn a(x) {\n x() }", 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![exprstatement!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
||||||
|
|
||||||
let multiline = r#"
|
let multiline = r#"
|
||||||
fn a(x) {
|
fn a(x) {
|
||||||
@ -1286,7 +1282,7 @@ fn a(x) {
|
|||||||
"#;
|
"#;
|
||||||
parse_test!(multiline, AST(vec![Declaration(
|
parse_test!(multiline, 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![exprstatement!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
||||||
let multiline2 = r#"
|
let multiline2 = r#"
|
||||||
fn a(x) {
|
fn a(x) {
|
||||||
|
|
||||||
@ -1296,19 +1292,19 @@ 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![exprstatement!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })]))]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_bools() {
|
fn parsing_bools() {
|
||||||
parse_test!("false", AST(vec![exprstatement!(BoolLiteral(false))]));
|
parse_test!("false", AST(vec![exst!(BoolLiteral(false))]));
|
||||||
parse_test!("true", AST(vec![exprstatement!(BoolLiteral(true))]));
|
parse_test!("true", AST(vec![exst!(BoolLiteral(true))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_strings() {
|
fn parsing_strings() {
|
||||||
parse_test!(r#""hello""#, AST(vec![exprstatement!(StringLiteral(rc!(hello)))]));
|
parse_test!(r#""hello""#, AST(vec![exst!(StringLiteral(rc!(hello)))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1351,14 +1347,14 @@ fn a(x) {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parsing_block_expressions() {
|
fn parsing_block_expressions() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if a() then { b(); c() }", AST(vec![exprstatement!(
|
"if a() then { b(); c() }", AST(vec![exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx! {
|
discriminator: bx! {
|
||||||
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
||||||
},
|
},
|
||||||
body: bx! {
|
body: bx! {
|
||||||
IfExpressionBody::SimpleConditional(
|
IfExpressionBody::SimpleConditional(
|
||||||
vec![exprstatement!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exprstatement!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1367,16 +1363,16 @@ fn a(x) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if a() then { b(); c() } else { q }", AST(vec![exprstatement!(
|
"if a() then { b(); c() } else { q }", AST(vec![exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx! {
|
discriminator: bx! {
|
||||||
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
||||||
},
|
},
|
||||||
body: bx! {
|
body: bx! {
|
||||||
IfExpressionBody::SimpleConditional(
|
IfExpressionBody::SimpleConditional(
|
||||||
vec![exprstatement!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exprstatement!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
||||||
Some(
|
Some(
|
||||||
vec![exprstatement!(val!("q"))],
|
vec![exst!(val!("q"))],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1385,9 +1381,9 @@ fn a(x) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
parse_test!("if a() then { b(); c() }", AST(vec![exprstatement!(
|
parse_test!("if a() then { b(); c() }", AST(vec![exst!(
|
||||||
IfExpression(bx!(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]})),
|
IfExpression(bx!(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]})),
|
||||||
vec![exprstatement!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exprstatement!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
||||||
None)
|
None)
|
||||||
)]));
|
)]));
|
||||||
parse_test!(r#"
|
parse_test!(r#"
|
||||||
@ -1397,21 +1393,21 @@ fn a(x) {
|
|||||||
} else {
|
} else {
|
||||||
c
|
c
|
||||||
}"#,
|
}"#,
|
||||||
AST(vec![exprstatement!(IfExpression(bx!(ex!(BoolLiteral(true))),
|
AST(vec![exst!(IfExpression(bx!(ex!(BoolLiteral(true))),
|
||||||
vec![Declaration(Binding { name: rc!(a), constant: true, expr: ex!(NatLiteral(10)) }),
|
vec![Declaration(Binding { name: rc!(a), constant: true, expr: ex!(NatLiteral(10)) }),
|
||||||
exprstatement!(val!(rc!(b)))],
|
exst!(val!(rc!(b)))],
|
||||||
Some(vec![exprstatement!(val!(rc!(c)))])))])
|
Some(vec![exst!(val!(rc!(c)))])))])
|
||||||
);
|
);
|
||||||
|
|
||||||
parse_test!("if a { b } else { c }", AST(vec![exprstatement!(
|
parse_test!("if a { b } else { c }", AST(vec![exst!(
|
||||||
IfExpression(bx!(ex!(val!("a"))),
|
IfExpression(bx!(ex!(val!("a"))),
|
||||||
vec![exprstatement!(val!("b"))],
|
vec![exst!(val!("b"))],
|
||||||
Some(vec![exprstatement!(val!("c"))])))]));
|
Some(vec![exst!(val!("c"))])))]));
|
||||||
|
|
||||||
parse_test!("if (A {a: 1}) { b } else { c }", AST(vec![exprstatement!(
|
parse_test!("if (A {a: 1}) { b } else { c }", AST(vec![exst!(
|
||||||
IfExpression(bx!(ex!(NamedStruct { name: rc!(A), fields: vec![(rc!(a), ex!(NatLiteral(1)))]})),
|
IfExpression(bx!(ex!(NamedStruct { name: rc!(A), fields: vec![(rc!(a), ex!(NatLiteral(1)))]})),
|
||||||
vec![exprstatement!(val!("b"))],
|
vec![exst!(val!("b"))],
|
||||||
Some(vec![exprstatement!(val!("c"))])))]));
|
Some(vec![exst!(val!("c"))])))]));
|
||||||
|
|
||||||
parse_error!("if A {a: 1} { b } else { c }");
|
parse_error!("if A {a: 1} { b } else { c }");
|
||||||
*/
|
*/
|
||||||
@ -1465,21 +1461,21 @@ fn a(x) {
|
|||||||
Expression(val!("b"), Some(ty!("Int"))) })]));
|
Expression(val!("b"), Some(ty!("Int"))) })]));
|
||||||
|
|
||||||
parse_test!("a : Int", AST(vec![
|
parse_test!("a : Int", AST(vec![
|
||||||
exprstatement!(val!("a"), ty!("Int"))
|
exst!(val!("a"), ty!("Int"))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!("a : Option<Int>", AST(vec![
|
parse_test!("a : Option<Int>", AST(vec![
|
||||||
exprstatement!(val!("a"), Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("Int")] }))
|
exst!(val!("a"), Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("Int")] }))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!("a : KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >", AST(vec![
|
parse_test!("a : KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >", AST(vec![
|
||||||
exprstatement!(val!("a"), Singleton(TypeSingletonName { name: rc!(KoreanBBQSpecifier), params: vec![
|
exst!(val!("a"), Singleton(TypeSingletonName { name: rc!(KoreanBBQSpecifier), params: vec![
|
||||||
ty!("Kimchi"), Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("Bulgogi")] })
|
ty!("Kimchi"), Singleton(TypeSingletonName { name: rc!(Option), params: vec![ty!("Bulgogi")] })
|
||||||
] }))
|
] }))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!("a : (Int, Yolo<a>)", AST(vec![
|
parse_test!("a : (Int, Yolo<a>)", AST(vec![
|
||||||
exprstatement!(val!("a"), Tuple(
|
exst!(val!("a"), Tuple(
|
||||||
vec![ty!("Int"), Singleton(TypeSingletonName {
|
vec![ty!("Int"), Singleton(TypeSingletonName {
|
||||||
name: rc!(Yolo), params: vec![ty!("a")]
|
name: rc!(Yolo), params: vec![ty!("a")]
|
||||||
})]))]));
|
})]))]));
|
||||||
@ -1492,7 +1488,7 @@ fn a(x) {
|
|||||||
) }
|
) }
|
||||||
|
|
||||||
parse_test!(r#"\ (x: Int, y) { a;b;c;}"#, AST(vec![
|
parse_test!(r#"\ (x: Int, y) { a;b;c;}"#, AST(vec![
|
||||||
exprstatement!(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!(val!("a")), exst!(val!("b")), exst!(val!("c"))]
|
||||||
@ -1500,21 +1496,21 @@ fn a(x) {
|
|||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!(r#"\(x){y}(1)"#, AST(vec![
|
parse_test!(r#"\(x){y}(1)"#, AST(vec![
|
||||||
exprstatement!(Call { f: bx!(ex!(
|
exst!(Call { f: bx!(ex!(
|
||||||
Lambda {
|
Lambda {
|
||||||
params: vec![(rc!(x), None)],
|
params: vec![(rc!(x), None)],
|
||||||
type_anno: None,
|
type_anno: None,
|
||||||
body: vec![exprstatement!(val!("y"))] }
|
body: vec![exst!(val!("y"))] }
|
||||||
)),
|
)),
|
||||||
arguments: vec![ex!(NatLiteral(1))] })]));
|
arguments: vec![ex!(NatLiteral(1))] })]));
|
||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
r#"\(x: Int): String { "q" }"#,
|
r#"\(x: Int): String { "q" }"#,
|
||||||
AST(vec![
|
AST(vec![
|
||||||
exprstatement!(Lambda {
|
exst!(Lambda {
|
||||||
params: vec![(rc!(x), Some(ty!("Int")))],
|
params: vec![(rc!(x), Some(ty!("Int")))],
|
||||||
type_anno: Some(ty!("String")),
|
type_anno: Some(ty!("String")),
|
||||||
body: vec![exprstatement!(s r#""q""#)]
|
body: vec![exst!(s r#""q""#)]
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@ -1524,7 +1520,7 @@ fn a(x) {
|
|||||||
fn list_literals() {
|
fn list_literals() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"[1,2]", AST(vec![
|
"[1,2]", AST(vec![
|
||||||
exprstatement!(ListLiteral(vec![ex!(NatLiteral(1)), ex!(NatLiteral(2))]))])
|
exst!(ListLiteral(vec![ex!(NatLiteral(1)), ex!(NatLiteral(2))]))])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1532,12 +1528,12 @@ fn a(x) {
|
|||||||
fn while_expr() {
|
fn while_expr() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"while { }", AST(vec![
|
"while { }", AST(vec![
|
||||||
exprstatement!(WhileExpression { condition: None, body: vec![] })])
|
exst!(WhileExpression { condition: None, body: vec![] })])
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"while a == b { }", AST(vec![
|
"while a == b { }", AST(vec![
|
||||||
exprstatement!(WhileExpression { condition: Some(bx![ex![binexp!("==", val!("a"), val!("b"))]]), body: vec![] })])
|
exst!(WhileExpression { condition: Some(bx![ex![binexp!("==", val!("a"), val!("b"))]]), body: vec![] })])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1545,7 +1541,7 @@ fn a(x) {
|
|||||||
fn for_expr() {
|
fn for_expr() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"for { a <- maybeValue } return 1", AST(vec![
|
"for { a <- maybeValue } return 1", AST(vec![
|
||||||
exprstatement!(ForExpression {
|
exst!(ForExpression {
|
||||||
enumerators: vec![Enumerator { id: rc!(a), generator: ex!(val!("maybeValue")) }],
|
enumerators: vec![Enumerator { id: rc!(a), generator: ex!(val!("maybeValue")) }],
|
||||||
body: bx!(MonadicReturn(ex!(NatLiteral(1))))
|
body: bx!(MonadicReturn(ex!(NatLiteral(1))))
|
||||||
})])
|
})])
|
||||||
@ -1553,8 +1549,8 @@ fn a(x) {
|
|||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"for n <- someRange { f(n); }", AST(vec![
|
"for n <- someRange { f(n); }", AST(vec![
|
||||||
exprstatement!(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![exprstatement!(Call { f: bx![ex!(val!("f"))], arguments: vec![ex!(val!("n"))] })]))
|
body: bx!(ForBody::StatementBlock(vec![exst!(Call { f: bx![ex!(val!("f"))], arguments: vec![ex!(val!("n"))] })]))
|
||||||
})])
|
})])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1563,27 +1559,27 @@ fn a(x) {
|
|||||||
fn patterns() {
|
fn patterns() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if x is Some(a) then { 4 } else { 9 }", AST(vec![
|
"if x is Some(a) then { 4 } else { 9 }", AST(vec![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(rc!(Some), vec![Pattern::Literal(PatternLiteral::VarPattern(rc!(a)))]), vec![exprstatement!(NatLiteral(4))], Some(vec![exprstatement!(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))]))) }
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if x is Some(a) then 4 else 9", AST(vec![
|
"if x is Some(a) then 4 else 9", AST(vec![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(rc!(Some), vec![Pattern::Literal(PatternLiteral::VarPattern(rc!(a)))]), vec![exprstatement!(NatLiteral(4))], Some(vec![exprstatement!(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))]))) }
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"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![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
@ -1591,7 +1587,7 @@ fn a(x) {
|
|||||||
(rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))),
|
(rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))),
|
||||||
(rc!(b),Pattern::Literal(PatternLiteral::VarPattern(rc!(x))))
|
(rc!(b),Pattern::Literal(PatternLiteral::VarPattern(rc!(x))))
|
||||||
]),
|
]),
|
||||||
vec![exprstatement!(NatLiteral(4))], Some(vec![exprstatement!(NatLiteral(9))])))
|
vec![exst!(NatLiteral(4))], Some(vec![exst!(NatLiteral(9))])))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
@ -1603,13 +1599,13 @@ fn a(x) {
|
|||||||
fn pattern_literals() {
|
fn pattern_literals() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if x is -1 then 1 else 2", AST(vec![
|
"if x is -1 then 1 else 2", AST(vec![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(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![exprstatement!(NatLiteral(1))],
|
vec![exst!(NatLiteral(1))],
|
||||||
Some(vec![exprstatement!(NatLiteral(2))]),
|
Some(vec![exst!(NatLiteral(2))]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1618,13 +1614,13 @@ fn a(x) {
|
|||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if x is 1 then 1 else 2", AST(vec![
|
"if x is 1 then 1 else 2", AST(vec![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(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![exprstatement!(NatLiteral(1))],
|
vec![exst!(NatLiteral(1))],
|
||||||
Some(vec![exprstatement!(NatLiteral(2))]),
|
Some(vec![exst!(NatLiteral(2))]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1633,13 +1629,13 @@ fn a(x) {
|
|||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if x is true then 1 else 2", AST(vec![
|
"if x is true then 1 else 2", AST(vec![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Literal(PatternLiteral::BoolPattern(true)),
|
Pattern::Literal(PatternLiteral::BoolPattern(true)),
|
||||||
vec![exprstatement!(NatLiteral(1))],
|
vec![exst!(NatLiteral(1))],
|
||||||
Some(vec![exprstatement!(NatLiteral(2))]),
|
Some(vec![exst!(NatLiteral(2))]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1648,13 +1644,13 @@ fn a(x) {
|
|||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"if x is \"gnosticism\" then 1 else 2", AST(vec![
|
"if x is \"gnosticism\" then 1 else 2", AST(vec![
|
||||||
exprstatement!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
discriminator: bx!(Discriminator::Simple(ex!(Value(rc!(x))))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch(
|
||||||
Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
|
Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
|
||||||
vec![exprstatement!(NatLiteral(1))],
|
vec![exst!(NatLiteral(1))],
|
||||||
Some(vec![exprstatement!(NatLiteral(2))]),
|
Some(vec![exst!(NatLiteral(2))]),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user