Get rid of "2" in parse test macros
This commit is contained in:
parent
c67adc3a38
commit
671ce54dd3
@ -85,7 +85,7 @@ fn ty_simple(name: &str) -> TypeIdentifier {
|
|||||||
TypeIdentifier::Singleton(TypeSingletonName { name: rc(name), params: vec![] })
|
TypeIdentifier::Singleton(TypeSingletonName { name: rc(name), params: vec![] })
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_ast2 {
|
macro_rules! assert_ast {
|
||||||
($input:expr, $statements:expr) => {
|
($input:expr, $statements:expr) => {
|
||||||
let ast = schala_parser::program($input);
|
let ast = schala_parser::program($input);
|
||||||
let expected = AST { id: Default::default(), statements: $statements.into() };
|
let expected = AST { id: Default::default(), statements: $statements.into() };
|
||||||
@ -97,14 +97,14 @@ macro_rules! assert_ast2 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_fail2 {
|
macro_rules! assert_fail {
|
||||||
($input:expr, $failure:expr) => {
|
($input:expr, $failure:expr) => {
|
||||||
let err = schala_parser::program($input).unwrap_err();
|
let err = schala_parser::program($input).unwrap_err();
|
||||||
assert_eq!(err.to_string(), $failure);
|
assert_eq!(err.to_string(), $failure);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_expr2 {
|
macro_rules! assert_expr {
|
||||||
($input:expr, $correct:expr) => {
|
($input:expr, $correct:expr) => {
|
||||||
let expr = schala_parser::expression($input);
|
let expr = schala_parser::expression($input);
|
||||||
if expr.is_err() {
|
if expr.is_err() {
|
||||||
@ -115,7 +115,7 @@ macro_rules! assert_expr2 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_fail_expr2 {
|
macro_rules! assert_fail_expr {
|
||||||
($input:expr, $failure:expr) => {
|
($input:expr, $failure:expr) => {
|
||||||
let _err = schala_parser::expression($input).unwrap_err();
|
let _err = schala_parser::expression($input).unwrap_err();
|
||||||
//TODO make real tests for failures
|
//TODO make real tests for failures
|
||||||
@ -126,25 +126,25 @@ macro_rules! assert_fail_expr2 {
|
|||||||
fn basic_literals() {
|
fn basic_literals() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!(".2", expr(FloatLiteral(0.2)));
|
assert_expr!(".2", expr(FloatLiteral(0.2)));
|
||||||
assert_expr2!("8.1", expr(FloatLiteral(8.1)));
|
assert_expr!("8.1", expr(FloatLiteral(8.1)));
|
||||||
assert_expr2!("0b010", expr(NatLiteral(2)));
|
assert_expr!("0b010", expr(NatLiteral(2)));
|
||||||
assert_expr2!("0b0_1_0", expr(NatLiteral(2)));
|
assert_expr!("0b0_1_0", expr(NatLiteral(2)));
|
||||||
assert_expr2!("0xff", expr(NatLiteral(255)));
|
assert_expr!("0xff", expr(NatLiteral(255)));
|
||||||
assert_expr2!("0x032f", expr(NatLiteral(815)));
|
assert_expr!("0x032f", expr(NatLiteral(815)));
|
||||||
assert_expr2!("0xf_f_", expr(NatLiteral(255)));
|
assert_expr!("0xf_f_", expr(NatLiteral(255)));
|
||||||
assert_expr2!("false", expr(BoolLiteral(false)));
|
assert_expr!("false", expr(BoolLiteral(false)));
|
||||||
assert_expr2!("true", expr(BoolLiteral(true)));
|
assert_expr!("true", expr(BoolLiteral(true)));
|
||||||
assert_expr2!(r#""hello""#, expr(StringLiteral(rc("hello"))));
|
assert_expr!(r#""hello""#, expr(StringLiteral(rc("hello"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_literals() {
|
fn list_literals() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("[]", expr(ListLiteral(vec![])));
|
assert_expr!("[]", expr(ListLiteral(vec![])));
|
||||||
assert_expr2!("[1,2]", expr(ListLiteral(vec![expr(NatLiteral(1)), expr(NatLiteral(2)),])));
|
assert_expr!("[1,2]", expr(ListLiteral(vec![expr(NatLiteral(1)), expr(NatLiteral(2)),])));
|
||||||
assert_fail_expr2!("[1,,2]", "some failure");
|
assert_fail_expr!("[1,,2]", "some failure");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -152,8 +152,8 @@ fn binexps() {
|
|||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
use StatementKind::Expression;
|
use StatementKind::Expression;
|
||||||
|
|
||||||
assert_expr2!("0xf_f_+1", binop("+", expr(NatLiteral(255)), expr(NatLiteral(1))));
|
assert_expr!("0xf_f_+1", binop("+", expr(NatLiteral(255)), expr(NatLiteral(1))));
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"3; 4; 4.3",
|
"3; 4; 4.3",
|
||||||
vec![
|
vec![
|
||||||
stmt(Expression(expr(NatLiteral(3)))),
|
stmt(Expression(expr(NatLiteral(3)))),
|
||||||
@ -162,16 +162,16 @@ fn binexps() {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"1 + 2 * 3",
|
"1 + 2 * 3",
|
||||||
binop("+", expr(NatLiteral(1)), binop("*", expr(NatLiteral(2)), expr(NatLiteral(3))))
|
binop("+", expr(NatLiteral(1)), binop("*", expr(NatLiteral(2)), expr(NatLiteral(3))))
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"1 * 2 + 3",
|
"1 * 2 + 3",
|
||||||
binop("+", binop("*", expr(NatLiteral(1)), expr(NatLiteral(2))), expr(NatLiteral(3)))
|
binop("+", binop("*", expr(NatLiteral(1)), expr(NatLiteral(2))), expr(NatLiteral(3)))
|
||||||
);
|
);
|
||||||
assert_expr2!("1 && 2", binop("&&", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
assert_expr!("1 && 2", binop("&&", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"1 + 2 * 3 + 4",
|
"1 + 2 * 3 + 4",
|
||||||
binop(
|
binop(
|
||||||
"+",
|
"+",
|
||||||
@ -179,48 +179,48 @@ fn binexps() {
|
|||||||
expr(NatLiteral(4))
|
expr(NatLiteral(4))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"(1 + 2) * 3",
|
"(1 + 2) * 3",
|
||||||
binop("*", binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))), expr(NatLiteral(3)))
|
binop("*", binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))), expr(NatLiteral(3)))
|
||||||
);
|
);
|
||||||
assert_expr2!(".1 + .2", binop("+", expr(FloatLiteral(0.1)), expr(FloatLiteral(0.2))));
|
assert_expr!(".1 + .2", binop("+", expr(FloatLiteral(0.1)), expr(FloatLiteral(0.2))));
|
||||||
assert_expr2!("1 / 2.", binop("/", expr(NatLiteral(1)), expr(FloatLiteral(2.))));
|
assert_expr!("1 / 2.", binop("/", expr(NatLiteral(1)), expr(FloatLiteral(2.))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn prefix_exps() {
|
fn prefix_exps() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("-3", prefixop("-", expr(NatLiteral(3))));
|
assert_expr!("-3", prefixop("-", expr(NatLiteral(3))));
|
||||||
assert_expr2!("-0.2", prefixop("-", expr(FloatLiteral(0.2))));
|
assert_expr!("-0.2", prefixop("-", expr(FloatLiteral(0.2))));
|
||||||
assert_expr2!("!3", prefixop("!", expr(NatLiteral(3))));
|
assert_expr!("!3", prefixop("!", expr(NatLiteral(3))));
|
||||||
assert_expr2!("!t", prefixop("!", expr(Value(qn!(t)))));
|
assert_expr!("!t", prefixop("!", expr(Value(qn!(t)))));
|
||||||
assert_expr2!("a <- -b", binop("<-", expr(Value(qn!(a))), prefixop("-", expr(Value(qn!(b))))));
|
assert_expr!("a <- -b", binop("<-", expr(Value(qn!(a))), prefixop("-", expr(Value(qn!(b))))));
|
||||||
assert_expr2!("a <--b", binop("<--", expr(Value(qn!(a))), expr(Value(qn!(b)))));
|
assert_expr!("a <--b", binop("<--", expr(Value(qn!(a))), expr(Value(qn!(b)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn operators() {
|
fn operators() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("a <- 1", binop("<-", expr(Value(qn!(a))), expr(NatLiteral(1))));
|
assert_expr!("a <- 1", binop("<-", expr(Value(qn!(a))), expr(NatLiteral(1))));
|
||||||
assert_expr2!("a || 1", binop("||", expr(Value(qn!(a))), expr(NatLiteral(1))));
|
assert_expr!("a || 1", binop("||", expr(Value(qn!(a))), expr(NatLiteral(1))));
|
||||||
assert_expr2!("a <> 1", binop("<>", expr(Value(qn!(a))), expr(NatLiteral(1))));
|
assert_expr!("a <> 1", binop("<>", expr(Value(qn!(a))), expr(NatLiteral(1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accessors() {
|
fn accessors() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("a.b", expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }));
|
assert_expr!("a.b", expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }));
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a.b.c",
|
"a.b.c",
|
||||||
expr(Access {
|
expr(Access {
|
||||||
name: rc("c"),
|
name: rc("c"),
|
||||||
expr: bx(expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }))
|
expr: bx(expr(Access { name: rc("b"), expr: bx(expr(Value(qn!(a)))) }))
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a.b.c(3)",
|
"a.b.c(3)",
|
||||||
expr(Call {
|
expr(Call {
|
||||||
f: bx(expr(Access {
|
f: bx(expr(Access {
|
||||||
@ -230,7 +230,7 @@ fn accessors() {
|
|||||||
arguments: vec![InvocationArgument::Positional(expr(NatLiteral(3)))],
|
arguments: vec![InvocationArgument::Positional(expr(NatLiteral(3)))],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a.b().c",
|
"a.b().c",
|
||||||
expr(Access {
|
expr(Access {
|
||||||
name: rc("c"),
|
name: rc("c"),
|
||||||
@ -246,12 +246,12 @@ fn accessors() {
|
|||||||
fn tuples() {
|
fn tuples() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("()", expr(TupleLiteral(vec![])));
|
assert_expr!("()", expr(TupleLiteral(vec![])));
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"("hella", 34)"#,
|
r#"("hella", 34)"#,
|
||||||
expr(TupleLiteral(vec![expr(StringLiteral(rc("hella"))), expr(NatLiteral(34))]))
|
expr(TupleLiteral(vec![expr(StringLiteral(rc("hella"))), expr(NatLiteral(34))]))
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"(1+2, "slough")"#,
|
r#"(1+2, "slough")"#,
|
||||||
expr(TupleLiteral(vec![
|
expr(TupleLiteral(vec![
|
||||||
binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))),
|
binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))),
|
||||||
@ -264,12 +264,12 @@ fn tuples() {
|
|||||||
fn identifiers() {
|
fn identifiers() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("a", expr(Value(qn!(a))));
|
assert_expr!("a", expr(Value(qn!(a))));
|
||||||
assert_expr2!("some_value", expr(Value(qn!(some_value))));
|
assert_expr!("some_value", expr(Value(qn!(some_value))));
|
||||||
assert_expr2!("alpha::beta::gamma", expr(Value(qn!(alpha, beta, gamma))));
|
assert_expr!("alpha::beta::gamma", expr(Value(qn!(alpha, beta, gamma))));
|
||||||
assert_expr2!("a + b", binop("+", expr(Value(qn!(a))), expr(Value(qn!(b)))));
|
assert_expr!("a + b", binop("+", expr(Value(qn!(a))), expr(Value(qn!(b)))));
|
||||||
assert_expr2!("None", expr(Value(qn!(None))));
|
assert_expr!("None", expr(Value(qn!(None))));
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"thing::item::call()",
|
"thing::item::call()",
|
||||||
expr(Call { f: bx(expr(Value(qn!(thing, item, call)))), arguments: vec![] })
|
expr(Call { f: bx(expr(Value(qn!(thing, item, call)))), arguments: vec![] })
|
||||||
);
|
);
|
||||||
@ -278,14 +278,14 @@ fn identifiers() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn named_struct() {
|
fn named_struct() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"Pandas { a: x + y }",
|
"Pandas { a: x + y }",
|
||||||
expr(NamedStruct {
|
expr(NamedStruct {
|
||||||
name: qn!(Pandas),
|
name: qn!(Pandas),
|
||||||
fields: vec![(rc("a"), binop("+", expr(Value(qn!(x))), expr(Value(qn!(y)))))]
|
fields: vec![(rc("a"), binop("+", expr(Value(qn!(x))), expr(Value(qn!(y)))))]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"Trousers { a:1, b:800 }",
|
"Trousers { a:1, b:800 }",
|
||||||
expr(NamedStruct {
|
expr(NamedStruct {
|
||||||
name: qn!(Trousers),
|
name: qn!(Trousers),
|
||||||
@ -297,14 +297,14 @@ fn named_struct() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn index() {
|
fn index() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"armok[b,c]",
|
"armok[b,c]",
|
||||||
expr(Index {
|
expr(Index {
|
||||||
indexee: bx(expr(Value(qn!(armok)))),
|
indexee: bx(expr(Value(qn!(armok)))),
|
||||||
indexers: vec![expr(Value(qn!(b))), expr(Value(qn!(c)))]
|
indexers: vec![expr(Value(qn!(b))), expr(Value(qn!(c)))]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a[b,c][1]",
|
"a[b,c][1]",
|
||||||
expr(Index {
|
expr(Index {
|
||||||
indexee: bx(expr(Index {
|
indexee: bx(expr(Index {
|
||||||
@ -314,7 +314,7 @@ fn index() {
|
|||||||
indexers: vec![expr(NatLiteral(1))]
|
indexers: vec![expr(NatLiteral(1))]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"perspicacity()[a]",
|
"perspicacity()[a]",
|
||||||
expr(Index {
|
expr(Index {
|
||||||
indexee: bx(expr(Call { f: bx(expr(Value(qn!(perspicacity)))), arguments: vec![] })),
|
indexee: bx(expr(Call { f: bx(expr(Value(qn!(perspicacity)))), arguments: vec![] })),
|
||||||
@ -326,17 +326,17 @@ fn index() {
|
|||||||
let b = expr(Index { indexee: bx(a), indexers: vec![expr(Value(qn!(b)))] });
|
let b = expr(Index { indexee: bx(a), indexers: vec![expr(Value(qn!(b)))] });
|
||||||
let c = expr(Call { f: bx(b), arguments: vec![] });
|
let c = expr(Call { f: bx(b), arguments: vec![] });
|
||||||
let d = expr(Index { indexee: bx(c), indexers: vec![expr(Value(qn!(d)))] });
|
let d = expr(Index { indexee: bx(c), indexers: vec![expr(Value(qn!(d)))] });
|
||||||
assert_expr2!("a()[b]()[d]", d);
|
assert_expr!("a()[b]()[d]", d);
|
||||||
|
|
||||||
assert_fail_expr2!("a[]", "Empty index expressions are not allowed");
|
assert_fail_expr!("a[]", "Empty index expressions are not allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn while_expression() {
|
fn while_expression() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!("while { }", expr(WhileExpression { condition: None, body: Block::default() }));
|
assert_expr!("while { }", expr(WhileExpression { condition: None, body: Block::default() }));
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"while a == b { }",
|
"while a == b { }",
|
||||||
expr(WhileExpression {
|
expr(WhileExpression {
|
||||||
condition: Some(bx(binop("==", expr(Value(qn!(a))), expr(Value(qn!(b)))))),
|
condition: Some(bx(binop("==", expr(Value(qn!(a))), expr(Value(qn!(b)))))),
|
||||||
@ -349,7 +349,7 @@ fn while_expression() {
|
|||||||
fn for_expression() {
|
fn for_expression() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"for { a <- garodzny::maybeValue } return 1",
|
"for { a <- garodzny::maybeValue } return 1",
|
||||||
expr(ForExpression {
|
expr(ForExpression {
|
||||||
enumerators: vec![Enumerator { id: rc("a"), generator: expr(Value(qn!(garodzny, maybeValue))) }],
|
enumerators: vec![Enumerator { id: rc("a"), generator: expr(Value(qn!(garodzny, maybeValue))) }],
|
||||||
@ -357,7 +357,7 @@ fn for_expression() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"for n <- someRange { f(n) ; }",
|
"for n <- someRange { f(n) ; }",
|
||||||
expr(ForExpression {
|
expr(ForExpression {
|
||||||
enumerators: vec![Enumerator { id: rc("n"), generator: expr(Value(qn!(someRange))) }],
|
enumerators: vec![Enumerator { id: rc("n"), generator: expr(Value(qn!(someRange))) }],
|
||||||
@ -376,7 +376,7 @@ fn for_expression() {
|
|||||||
fn lambda_expressions() {
|
fn lambda_expressions() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"\(x) { x + 1}"#,
|
r#"\(x) { x + 1}"#,
|
||||||
expr(Lambda {
|
expr(Lambda {
|
||||||
params: vec![FormalParam { name: rc!(x), anno: None, default: None }],
|
params: vec![FormalParam { name: rc!(x), anno: None, default: None }],
|
||||||
@ -387,7 +387,7 @@ fn lambda_expressions() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"\ (x: Int, y) { a;b;c;}"#,
|
r#"\ (x: Int, y) { a;b;c;}"#,
|
||||||
expr(Lambda {
|
expr(Lambda {
|
||||||
params: vec![
|
params: vec![
|
||||||
@ -404,7 +404,7 @@ fn lambda_expressions() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"\(x){y}(1)"#,
|
r#"\(x){y}(1)"#,
|
||||||
expr(Call {
|
expr(Call {
|
||||||
f: bx(expr(Lambda {
|
f: bx(expr(Lambda {
|
||||||
@ -416,7 +416,7 @@ fn lambda_expressions() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"\(x: Int): String { "q" }"#,
|
r#"\(x: Int): String { "q" }"#,
|
||||||
expr(Lambda {
|
expr(Lambda {
|
||||||
params: vec![FormalParam { name: rc!(x), anno: Some(ty_simple("Int")), default: None },],
|
params: vec![FormalParam { name: rc!(x), anno: Some(ty_simple("Int")), default: None },],
|
||||||
@ -433,7 +433,7 @@ fn lambda_expressions() {
|
|||||||
fn single_param_lambda() {
|
fn single_param_lambda() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"\x { x + 10 }"#,
|
r#"\x { x + 10 }"#,
|
||||||
expr(Lambda {
|
expr(Lambda {
|
||||||
params: vec![FormalParam { name: rc!(x), anno: None, default: None },],
|
params: vec![FormalParam { name: rc!(x), anno: None, default: None },],
|
||||||
@ -447,7 +447,7 @@ fn single_param_lambda() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"\x: Int { x + 10 }"#,
|
r#"\x: Int { x + 10 }"#,
|
||||||
expr(Lambda {
|
expr(Lambda {
|
||||||
params: vec![FormalParam { name: rc!(x), anno: Some(ty_simple("Int")), default: None },],
|
params: vec![FormalParam { name: rc!(x), anno: Some(ty_simple("Int")), default: None },],
|
||||||
@ -467,7 +467,7 @@ fn complex_lambdas() {
|
|||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
//TODO support this without the semicolon after the lambda
|
//TODO support this without the semicolon after the lambda
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
r#"fn wahoo() { let a = 10; \(x) { x + a }; }
|
r#"fn wahoo() { let a = 10; \(x) { x + a }; }
|
||||||
wahoo()(3) "#,
|
wahoo()(3) "#,
|
||||||
vec![
|
vec![
|
||||||
@ -503,7 +503,7 @@ fn complex_lambdas() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reserved_words() {
|
fn reserved_words() {
|
||||||
assert_fail2!("module::item::call()", "error at 1:7: expected ['a' ..= 'z' | 'A' ..= 'Z' | '_']");
|
assert_fail!("module::item::call()", "error at 1:7: expected ['a' ..= 'z' | 'A' ..= 'Z' | '_']");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -511,7 +511,7 @@ fn type_annotations() {
|
|||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
use TypeIdentifier::*;
|
use TypeIdentifier::*;
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"let a = b : Int",
|
"let a = b : Int",
|
||||||
vec![decl(Declaration::Binding {
|
vec![decl(Declaration::Binding {
|
||||||
name: rc("a"),
|
name: rc("a"),
|
||||||
@ -521,11 +521,11 @@ fn type_annotations() {
|
|||||||
})]
|
})]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a: Int",
|
"a: Int",
|
||||||
expr_anno(Value(qn!(a)), Singleton(TypeSingletonName { name: rc("Int"), params: vec![] }))
|
expr_anno(Value(qn!(a)), Singleton(TypeSingletonName { name: rc("Int"), params: vec![] }))
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a: Option<Int>",
|
"a: Option<Int>",
|
||||||
expr_anno(
|
expr_anno(
|
||||||
Value(qn!(a)),
|
Value(qn!(a)),
|
||||||
@ -535,7 +535,7 @@ fn type_annotations() {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a: KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >",
|
"a: KoreanBBQSpecifier<Kimchi, Option<Bulgogi> >",
|
||||||
expr_anno(
|
expr_anno(
|
||||||
Value(qn!(a)),
|
Value(qn!(a)),
|
||||||
@ -551,7 +551,7 @@ fn type_annotations() {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"a: (Int, Yolo<a>)",
|
"a: (Int, Yolo<a>)",
|
||||||
expr_anno(
|
expr_anno(
|
||||||
Value(qn!(a)),
|
Value(qn!(a)),
|
||||||
@ -569,7 +569,7 @@ fn type_annotations() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn type_declarations() {
|
fn type_declarations() {
|
||||||
use Declaration::TypeDecl;
|
use Declaration::TypeDecl;
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"type Alpha = Alpha", vec![
|
"type Alpha = Alpha", vec![
|
||||||
decl(TypeDecl {
|
decl(TypeDecl {
|
||||||
name: TypeSingletonName { name: rc("Alpha"), params: vec![] },
|
name: TypeSingletonName { name: rc("Alpha"), params: vec![] },
|
||||||
@ -585,7 +585,7 @@ fn type_declarations() {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"type mut Kuah = Kuah",
|
"type mut Kuah = Kuah",
|
||||||
decl(TypeDecl {
|
decl(TypeDecl {
|
||||||
name: TypeSingletonName { name: rc("Kuah"), params: vec![] },
|
name: TypeSingletonName { name: rc("Kuah"), params: vec![] },
|
||||||
@ -598,7 +598,7 @@ fn type_declarations() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"type Alpha = Alpha { a: Int, b: Int }",
|
"type Alpha = Alpha { a: Int, b: Int }",
|
||||||
vec![decl(TypeDecl {
|
vec![decl(TypeDecl {
|
||||||
name: TypeSingletonName { name: rc("Alpha"), params: vec![] },
|
name: TypeSingletonName { name: rc("Alpha"), params: vec![] },
|
||||||
@ -616,7 +616,7 @@ fn type_declarations() {
|
|||||||
})]
|
})]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"type Alpha = { a: Int, b: Int }",
|
"type Alpha = { a: Int, b: Int }",
|
||||||
vec![decl(TypeDecl {
|
vec![decl(TypeDecl {
|
||||||
name: TypeSingletonName { name: rc("Alpha"), params: vec![] },
|
name: TypeSingletonName { name: rc("Alpha"), params: vec![] },
|
||||||
@ -629,7 +629,7 @@ fn type_declarations() {
|
|||||||
})]
|
})]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"type Option<T> = None | Some(T)",
|
"type Option<T> = None | Some(T)",
|
||||||
vec![decl(TypeDecl {
|
vec![decl(TypeDecl {
|
||||||
name: TypeSingletonName {
|
name: TypeSingletonName {
|
||||||
@ -651,12 +651,12 @@ fn type_declarations() {
|
|||||||
})]
|
})]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"type alias Alpha = Beta",
|
"type alias Alpha = Beta",
|
||||||
decl(Declaration::TypeAlias { alias: rc("Alpha"), original: rc("Beta") })
|
decl(Declaration::TypeAlias { alias: rc("Alpha"), original: rc("Beta") })
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!("type Complex<T, U> = Unit | Record { field: AnotherType<Bool>, field2: (Nat, Int), field3: T } | Tuple(Int, (String, T))",
|
assert_ast!("type Complex<T, U> = Unit | Record { field: AnotherType<Bool>, field2: (Nat, Int), field3: T } | Tuple(Int, (String, T))",
|
||||||
decl(TypeDecl {
|
decl(TypeDecl {
|
||||||
name: TypeSingletonName { name: rc("Complex"), params: vec![
|
name: TypeSingletonName { name: rc("Complex"), params: vec![
|
||||||
TypeIdentifier::Singleton(TypeSingletonName { name: rc("T"), params: vec![] }),
|
TypeIdentifier::Singleton(TypeSingletonName { name: rc("T"), params: vec![] }),
|
||||||
@ -693,7 +693,7 @@ fn type_declarations() {
|
|||||||
fn declarations() {
|
fn declarations() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"let q_q = Yolo::Swaggins",
|
"let q_q = Yolo::Swaggins",
|
||||||
vec![decl(Declaration::Binding {
|
vec![decl(Declaration::Binding {
|
||||||
name: rc("q_q"),
|
name: rc("q_q"),
|
||||||
@ -708,7 +708,7 @@ fn declarations() {
|
|||||||
fn bindings() {
|
fn bindings() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"let mut a = 10",
|
"let mut a = 10",
|
||||||
vec![decl(Declaration::Binding {
|
vec![decl(Declaration::Binding {
|
||||||
name: rc("a"),
|
name: rc("a"),
|
||||||
@ -718,7 +718,7 @@ fn bindings() {
|
|||||||
})]
|
})]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"let a = 2 + a",
|
"let a = 2 + a",
|
||||||
vec![stmt(StatementKind::Declaration(Declaration::Binding {
|
vec![stmt(StatementKind::Declaration(Declaration::Binding {
|
||||||
name: rc("a"),
|
name: rc("a"),
|
||||||
@ -728,7 +728,7 @@ fn bindings() {
|
|||||||
}))]
|
}))]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"let a: Nat = 2",
|
"let a: Nat = 2",
|
||||||
vec![stmt(StatementKind::Declaration(Declaration::Binding {
|
vec![stmt(StatementKind::Declaration(Declaration::Binding {
|
||||||
name: rc("a"),
|
name: rc("a"),
|
||||||
@ -742,7 +742,7 @@ fn bindings() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn functions() {
|
fn functions() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"fn oi()",
|
"fn oi()",
|
||||||
vec![stmt(StatementKind::Declaration(Declaration::FuncSig(Signature {
|
vec![stmt(StatementKind::Declaration(Declaration::FuncSig(Signature {
|
||||||
name: rc("oi"),
|
name: rc("oi"),
|
||||||
@ -752,12 +752,12 @@ fn functions() {
|
|||||||
})))]
|
})))]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"oi()",
|
"oi()",
|
||||||
vec![stmt(StatementKind::Expression(expr(Call { f: bx(expr(Value(qn!(oi)))), arguments: vec![] })))]
|
vec![stmt(StatementKind::Expression(expr(Call { f: bx(expr(Value(qn!(oi)))), arguments: vec![] })))]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"oi(a, 2+2)",
|
"oi(a, 2+2)",
|
||||||
expr(Call {
|
expr(Call {
|
||||||
f: bx(expr(Value(qn!(oi)))),
|
f: bx(expr(Value(qn!(oi)))),
|
||||||
@ -767,9 +767,9 @@ fn functions() {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_fail2!("a(b,,c)","error at 1:5: expected one of \"(\", \".\", \"0b\", \"0x\", \"[\", \"\\\"\", \"_\", \"false\", \"for\", \"if\", \"true\", \"while\", ['+' | '-' | '!'], ['0' ..= '9'], ['a' ..= 'z' | 'A' ..= 'Z' | '_'], r#\"\\\"#");
|
assert_fail!("a(b,,c)","error at 1:5: expected one of \"(\", \".\", \"0b\", \"0x\", \"[\", \"\\\"\", \"_\", \"false\", \"for\", \"if\", \"true\", \"while\", ['+' | '-' | '!'], ['0' ..= '9'], ['a' ..= 'z' | 'A' ..= 'Z' | '_'], r#\"\\\"#");
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"fn a(b, c: Int): Int",
|
"fn a(b, c: Int): Int",
|
||||||
vec![stmt(StatementKind::Declaration(Declaration::FuncSig(Signature {
|
vec![stmt(StatementKind::Declaration(Declaration::FuncSig(Signature {
|
||||||
name: rc("a"),
|
name: rc("a"),
|
||||||
@ -794,7 +794,7 @@ fn functions() {
|
|||||||
|
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
source,
|
source,
|
||||||
vec![fn_decl(
|
vec![fn_decl(
|
||||||
Signature { name: rc("some_function"), operator: false, type_anno: None, params: vec![] },
|
Signature { name: rc("some_function"), operator: false, type_anno: None, params: vec![] },
|
||||||
@ -810,9 +810,9 @@ fn max_function_params() {
|
|||||||
write!(buf, "a{}, ", n).unwrap();
|
write!(buf, "a{}, ", n).unwrap();
|
||||||
}
|
}
|
||||||
write!(buf, ") {{ return 20 }}").unwrap();
|
write!(buf, ") {{ return 20 }}").unwrap();
|
||||||
//assert_fail2!(&buf, "A function cannot have more than 255 arguments");
|
//assert_fail!(&buf, "A function cannot have more than 255 arguments");
|
||||||
//TODO better errors again
|
//TODO better errors again
|
||||||
assert_fail2!(&buf, "error at 1:1439: expected ['a' ..= 'z' | 'A' ..= 'Z' | '_']");
|
assert_fail!(&buf, "error at 1:1439: expected ['a' ..= 'z' | 'A' ..= 'Z' | '_']");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -834,7 +834,7 @@ fn functions_with_different_whitespace() {
|
|||||||
"#;
|
"#;
|
||||||
|
|
||||||
for item in [a, b, c].iter() {
|
for item in [a, b, c].iter() {
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
item,
|
item,
|
||||||
vec![fn_decl(
|
vec![fn_decl(
|
||||||
Signature {
|
Signature {
|
||||||
@ -857,7 +857,7 @@ fn functions_with_different_whitespace() {
|
|||||||
fn functions_with_default_args() {
|
fn functions_with_default_args() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"fn func(x: Int, y: Int = 4) { }",
|
"fn func(x: Int, y: Int = 4) { }",
|
||||||
vec![fn_decl(
|
vec![fn_decl(
|
||||||
Signature {
|
Signature {
|
||||||
@ -881,7 +881,7 @@ fn functions_with_default_args() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn interface() {
|
fn interface() {
|
||||||
let glue = TypeIdentifier::Singleton(TypeSingletonName { name: rc("Glue"), params: vec![] });
|
let glue = TypeIdentifier::Singleton(TypeSingletonName { name: rc("Glue"), params: vec![] });
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"interface Unglueable { fn unglue(a: Glue); fn mar(): Glue }",
|
"interface Unglueable { fn unglue(a: Glue); fn mar(): Glue }",
|
||||||
vec![decl(Declaration::Interface {
|
vec![decl(Declaration::Interface {
|
||||||
name: rc("Unglueable"),
|
name: rc("Unglueable"),
|
||||||
@ -913,13 +913,13 @@ fn impls() {
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"impl Heh { fn yolo() { }; fn swagg() { } }",
|
"impl Heh { fn yolo() { }; fn swagg() { } }",
|
||||||
vec![decl(Impl { type_name: ty_simple("Heh"), interface_name: None, block: block.clone() })]
|
vec![decl(Impl { type_name: ty_simple("Heh"), interface_name: None, block: block.clone() })]
|
||||||
);
|
);
|
||||||
|
|
||||||
//TODO `"impl Heh<X> { fn yolo() { }; fn swagg() { }; }"` ought to work
|
//TODO `"impl Heh<X> { fn yolo() { }; fn swagg() { }; }"` ought to work
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"impl Heh<X> { fn yolo() { }; fn swagg() { } }",
|
"impl Heh<X> { fn yolo() { }; fn swagg() { } }",
|
||||||
vec![decl(Impl {
|
vec![decl(Impl {
|
||||||
type_name: TypeIdentifier::Singleton(TypeSingletonName {
|
type_name: TypeIdentifier::Singleton(TypeSingletonName {
|
||||||
@ -931,7 +931,7 @@ fn impls() {
|
|||||||
})]
|
})]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"impl Heh for Saraz { fn yolo() {}; fn swagg() {} }",
|
"impl Heh for Saraz { fn yolo() {}; fn swagg() {} }",
|
||||||
vec![decl(Impl {
|
vec![decl(Impl {
|
||||||
type_name: ty_simple("Saraz"),
|
type_name: ty_simple("Saraz"),
|
||||||
@ -940,7 +940,7 @@ fn impls() {
|
|||||||
})]
|
})]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
"impl Heh<T> for (Int, Codepoint) {}",
|
"impl Heh<T> for (Int, Codepoint) {}",
|
||||||
vec![decl(Impl {
|
vec![decl(Impl {
|
||||||
type_name: TypeIdentifier::Tuple(vec![ty_simple("Int"), ty_simple("Codepoint")]),
|
type_name: TypeIdentifier::Tuple(vec![ty_simple("Int"), ty_simple("Codepoint")]),
|
||||||
@ -959,7 +959,7 @@ fn annotations() {
|
|||||||
vec![].into(),
|
vec![].into(),
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
r#"
|
r#"
|
||||||
@test_annotation
|
@test_annotation
|
||||||
fn some_function() {
|
fn some_function() {
|
||||||
@ -973,7 +973,7 @@ fn annotations() {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
r#"
|
r#"
|
||||||
@test_annotation(some,value)
|
@test_annotation(some,value)
|
||||||
@another_annotation
|
@another_annotation
|
||||||
@ -993,7 +993,7 @@ fn annotations() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn modules() {
|
fn modules() {
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
r#"
|
r#"
|
||||||
module ephraim {
|
module ephraim {
|
||||||
let mut a = 10
|
let mut a = 10
|
||||||
@ -1016,7 +1016,7 @@ fn modules() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn imports() {
|
fn imports() {
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"import harbinger::draughts::Norgleheim",
|
"import harbinger::draughts::Norgleheim",
|
||||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||||
id: ItemId::default(),
|
id: ItemId::default(),
|
||||||
@ -1025,7 +1025,7 @@ fn imports() {
|
|||||||
}))]
|
}))]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"import harbinger::draughts::{Norgleheim, Xraksenlaigar}",
|
"import harbinger::draughts::{Norgleheim, Xraksenlaigar}",
|
||||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||||
id: ItemId::default(),
|
id: ItemId::default(),
|
||||||
@ -1035,7 +1035,7 @@ fn imports() {
|
|||||||
}))]
|
}))]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"import bespouri::{}",
|
"import bespouri::{}",
|
||||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
@ -1044,7 +1044,7 @@ fn imports() {
|
|||||||
}))]
|
}))]
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ast2! {
|
assert_ast! {
|
||||||
"import bespouri::*",
|
"import bespouri::*",
|
||||||
vec![stmt(StatementKind::Import(ImportSpecifier {
|
vec![stmt(StatementKind::Import(ImportSpecifier {
|
||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
@ -1057,7 +1057,7 @@ fn imports() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn if_exprs() {
|
fn if_exprs() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"if a() then { tuah(); }",
|
"if a() then { tuah(); }",
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Call { f: bx(expr(Value(qn!(a)))), arguments: vec![] }))),
|
discriminator: Some(bx(expr(Call { f: bx(expr(Value(qn!(a)))), arguments: vec![] }))),
|
||||||
@ -1068,7 +1068,7 @@ fn if_exprs() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"if a then b else c",
|
"if a then b else c",
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(a))))),
|
discriminator: Some(bx(expr(Value(qn!(a))))),
|
||||||
@ -1079,7 +1079,7 @@ fn if_exprs() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"
|
r#"
|
||||||
if true then {
|
if true then {
|
||||||
let a = 10
|
let a = 10
|
||||||
@ -1111,7 +1111,7 @@ fn pattern_matching() {
|
|||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
for item in ["if x is Some(a) then { 4 } else { 9 }", "if x is Some(a) then 4 else 9"] {
|
for item in ["if x is Some(a) then { 4 } else { 9 }", "if x is Some(a) then 4 else 9"] {
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
item,
|
item,
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(x))))),
|
discriminator: Some(bx(expr(Value(qn!(x))))),
|
||||||
@ -1124,7 +1124,7 @@ fn pattern_matching() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"if x is Something { a, b: x } then { 4 } else { 9 }",
|
"if x is Something { a, b: x } then { 4 } else { 9 }",
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(x))))),
|
discriminator: Some(bx(expr(Value(qn!(x))))),
|
||||||
@ -1139,7 +1139,7 @@ fn pattern_matching() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"if x is -1 then 1 else 2",
|
"if x is -1 then 1 else 2",
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(x))))),
|
discriminator: Some(bx(expr(Value(qn!(x))))),
|
||||||
@ -1151,7 +1151,7 @@ fn pattern_matching() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"if x is true then 1 else 2",
|
"if x is true then 1 else 2",
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(x))))),
|
discriminator: Some(bx(expr(Value(qn!(x))))),
|
||||||
@ -1163,7 +1163,7 @@ fn pattern_matching() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
"if x { is 1 then 5; else 20 }",
|
"if x { is 1 then 5; else 20 }",
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(x))))),
|
discriminator: Some(bx(expr(Value(qn!(x))))),
|
||||||
@ -1185,7 +1185,7 @@ fn pattern_matching() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr!(
|
||||||
r#"if x is "gnosticism" then 1 else 2"#,
|
r#"if x is "gnosticism" then 1 else 2"#,
|
||||||
expr(IfExpression {
|
expr(IfExpression {
|
||||||
discriminator: Some(bx(expr(Value(qn!(x))))),
|
discriminator: Some(bx(expr(Value(qn!(x))))),
|
||||||
@ -1197,7 +1197,7 @@ fn pattern_matching() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2! {
|
assert_expr! {
|
||||||
r#"
|
r#"
|
||||||
if (45, "panda", false, 2.2) {
|
if (45, "panda", false, 2.2) {
|
||||||
is (49, "pablo", _, 28.4) then "no"
|
is (49, "pablo", _, 28.4) then "no"
|
||||||
@ -1259,7 +1259,7 @@ fn flow_control() {
|
|||||||
return 10;
|
return 10;
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
assert_ast2!(
|
assert_ast!(
|
||||||
source,
|
source,
|
||||||
vec![fn_decl(
|
vec![fn_decl(
|
||||||
Signature { name: rc("test"), operator: false, type_anno: None, params: vec![] },
|
Signature { name: rc("test"), operator: false, type_anno: None, params: vec![] },
|
||||||
@ -1297,12 +1297,12 @@ fn comments() {
|
|||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
|
|
||||||
let source = "1 + /* hella /* bro */ */ 2";
|
let source = "1 + /* hella /* bro */ */ 2";
|
||||||
assert_expr2!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
assert_expr!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
||||||
|
|
||||||
//TODO make sure this error message makes sense
|
//TODO make sure this error message makes sense
|
||||||
let source = "1 + /* hella /* bro */ 2";
|
let source = "1 + /* hella /* bro */ 2";
|
||||||
assert_fail_expr2!(source, "foo");
|
assert_fail_expr!(source, "foo");
|
||||||
|
|
||||||
let source = "1 + /* hella */ bro */ 2";
|
let source = "1 + /* hella */ bro */ 2";
|
||||||
assert_fail_expr2!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
assert_fail_expr!(source, binop("+", expr(NatLiteral(1)), expr(NatLiteral(2))));
|
||||||
}
|
}
|
||||||
|
@ -129,11 +129,10 @@ pub(crate) struct SourceReference {
|
|||||||
|
|
||||||
impl SourceReference {
|
impl SourceReference {
|
||||||
fn new() -> SourceReference {
|
fn new() -> SourceReference {
|
||||||
SourceReference { last_source: None, newline_offsets: vec![]}
|
SourceReference { last_source: None, newline_offsets: vec![] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_new_source(&mut self, source: &str) {
|
fn load_new_source(&mut self, source: &str) {
|
||||||
|
|
||||||
for (offset, ch) in source.as_bytes().iter().enumerate() {
|
for (offset, ch) in source.as_bytes().iter().enumerate() {
|
||||||
if *ch == ('\n' as u8) {
|
if *ch == ('\n' as u8) {
|
||||||
self.newline_offsets.push(offset);
|
self.newline_offsets.push(offset);
|
||||||
|
@ -226,9 +226,7 @@ pub fn tokenize(input: &str) -> Vec<Token> {
|
|||||||
c if is_operator(&c) => handle_operator(c, &mut input),
|
c if is_operator(&c) => handle_operator(c, &mut input),
|
||||||
unknown => Error(format!("Unexpected character: {}", unknown)),
|
unknown => Error(format!("Unexpected character: {}", unknown)),
|
||||||
};
|
};
|
||||||
let location = Location {
|
let location = Location { offset: 0 };
|
||||||
offset: 0,
|
|
||||||
};
|
|
||||||
tokens.push(Token { kind: cur_tok_kind, location });
|
tokens.push(Token { kind: cur_tok_kind, location });
|
||||||
}
|
}
|
||||||
tokens
|
tokens
|
||||||
|
Loading…
Reference in New Issue
Block a user