Parsing tests pass, eval ones fail
This commit is contained in:
parent
745afe981a
commit
ddea470ba8
@ -4,7 +4,7 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use super::tokenize;
|
use super::tokenize;
|
||||||
use super::ParseResult;
|
use super::ParseResult;
|
||||||
use crate::ast::{ItemIdStore, AST, Expression, Statement, StatementKind, IfExpressionBody, Discriminator, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody, InvocationArgument, FormalParam, PrefixOp, BinOp, QualifiedName, ImportSpecifier, ImportedNames, GuardArm, Guard};
|
use crate::ast::{ItemIdStore, AST, Expression, Statement, StatementKind, IfExpressionBody, Pattern, PatternLiteral, TypeBody, Enumerator, ForBody, InvocationArgument, FormalParam, PrefixOp, BinOp, QualifiedName, ImportSpecifier, ImportedNames, Condition, ConditionArm};
|
||||||
use super::Declaration::*;
|
use super::Declaration::*;
|
||||||
use super::Signature;
|
use super::Signature;
|
||||||
use super::TypeIdentifier::*;
|
use super::TypeIdentifier::*;
|
||||||
@ -345,14 +345,14 @@ fn parsing_block_expressions() {
|
|||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
"if a() then { b(); c() }", exst!(
|
"if a() then { b(); c() }", exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx! {
|
discriminator: Some(bx! {
|
||||||
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]})
|
||||||
},
|
}),
|
||||||
body: bx! {
|
body: bx! {
|
||||||
IfExpressionBody::SimpleConditional(
|
IfExpressionBody::SimpleConditional {
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
then_case: vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
||||||
None
|
else_case: None,
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -361,16 +361,14 @@ fn parsing_block_expressions() {
|
|||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
"if a() then { b(); c() } else { q }", exst!(
|
"if a() then { b(); c() } else { q }", exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx! {
|
discriminator: Some(bx! {
|
||||||
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]})
|
||||||
},
|
}),
|
||||||
body: bx! {
|
body: bx! {
|
||||||
IfExpressionBody::SimpleConditional(
|
IfExpressionBody::SimpleConditional {
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
then_case: vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
||||||
Some(
|
else_case: Some(vec![exst!(val!("q"))]),
|
||||||
vec![exst!(val!("q"))],
|
}
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -620,31 +618,41 @@ fn patterns() {
|
|||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
"if x is Some(a) then { 4 } else { 9 }", exst!(
|
"if x is Some(a) then { 4 } else { 9 }", exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some),
|
body: bx!(IfExpressionBody::SimplePatternMatch {
|
||||||
vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) }
|
pattern: Pattern::TupleStruct(qname!(Some), vec![Pattern::VarOrName(qname!(a))]),
|
||||||
|
then_case: vec![exst!(s "4")],
|
||||||
|
else_case: Some(vec![exst!(s "9")]) })
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
"if x is Some(a) then 4 else 9", exst!(
|
"if x is Some(a) then 4 else 9", exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(Pattern::TupleStruct(qname!(Some),
|
body: bx!(IfExpressionBody::SimplePatternMatch {
|
||||||
vec![Pattern::VarOrName(qname!(a))]), vec![exst!(s "4")], Some(vec![exst!(s "9")]))) }
|
pattern: Pattern::TupleStruct(qname!(Some), vec![Pattern::VarOrName(qname!(a))]),
|
||||||
|
then_case: vec![exst!(s "4")],
|
||||||
|
else_case: Some(vec![exst!(s "9")]) }
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
"if x is Something { a, b: x } then { 4 } else { 9 }", exst!(
|
"if x is Something { a, b: x } then { 4 } else { 9 }", exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch {
|
||||||
Pattern::Record(qname!(Something), vec![
|
pattern: Pattern::Record(qname!(Something), vec![
|
||||||
(rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))),
|
(rc!(a),Pattern::Literal(PatternLiteral::StringPattern(rc!(a)))),
|
||||||
(rc!(b),Pattern::VarOrName(qname!(x)))
|
(rc!(b),Pattern::VarOrName(qname!(x)))
|
||||||
]),
|
]),
|
||||||
vec![exst!(s "4")], Some(vec![exst!(s "9")])))
|
then_case: vec![exst!(s "4")],
|
||||||
|
else_case: Some(vec![exst!(s "9")])
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -656,12 +664,12 @@ fn pattern_literals() {
|
|||||||
"if x is -1 then 1 else 2",
|
"if x is -1 then 1 else 2",
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch {
|
||||||
Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }),
|
pattern: Pattern::Literal(PatternLiteral::NumPattern { neg: true, num: NatLiteral(1) }),
|
||||||
vec![exst!(NatLiteral(1))],
|
then_case: vec![exst!(NatLiteral(1))],
|
||||||
Some(vec![exst!(NatLiteral(2))]),
|
else_case: Some(vec![exst!(NatLiteral(2))]),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -670,12 +678,12 @@ fn pattern_literals() {
|
|||||||
"if x is 1 then 1 else 2",
|
"if x is 1 then 1 else 2",
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch {
|
||||||
Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }),
|
pattern: Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1) }),
|
||||||
vec![exst!(s "1")],
|
then_case: vec![exst!(s "1")],
|
||||||
Some(vec![exst!(s "2")]),
|
else_case: Some(vec![exst!(s "2")]),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -684,12 +692,13 @@ fn pattern_literals() {
|
|||||||
"if x is true then 1 else 2",
|
"if x is true then 1 else 2",
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(
|
||||||
Pattern::Literal(PatternLiteral::BoolPattern(true)),
|
IfExpressionBody::SimplePatternMatch {
|
||||||
vec![exst!(NatLiteral(1))],
|
pattern: Pattern::Literal(PatternLiteral::BoolPattern(true)),
|
||||||
Some(vec![exst!(NatLiteral(2))]),
|
then_case: vec![exst!(NatLiteral(1))],
|
||||||
))
|
else_case: Some(vec![exst!(NatLiteral(2))]),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -698,12 +707,12 @@ fn pattern_literals() {
|
|||||||
"if x is \"gnosticism\" then 1 else 2",
|
"if x is \"gnosticism\" then 1 else 2",
|
||||||
exst!(
|
exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::SimplePatternMatch(
|
body: bx!(IfExpressionBody::SimplePatternMatch {
|
||||||
Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
|
pattern: Pattern::Literal(PatternLiteral::StringPattern(rc!(gnosticism))),
|
||||||
vec![exst!(s "1")],
|
then_case: vec![exst!(s "1")],
|
||||||
Some(vec![exst!(s "2")]),
|
else_case: Some(vec![exst!(s "2")]),
|
||||||
))
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -753,7 +762,7 @@ fn imports_3() {
|
|||||||
fn imports_4() {
|
fn imports_4() {
|
||||||
parse_test_wrap_ast! {
|
parse_test_wrap_ast! {
|
||||||
"import bespouri::*",
|
"import bespouri::*",
|
||||||
import!(ImportSpecifier {
|
import!(ImportSpecifier {
|
||||||
id: ItemIdStore::new_id(),
|
id: ItemIdStore::new_id(),
|
||||||
path_components: vec![rc!(bespouri)],
|
path_components: vec![rc!(bespouri)],
|
||||||
imported_names: ImportedNames::All
|
imported_names: ImportedNames::All
|
||||||
@ -768,15 +777,17 @@ fn if_expr() {
|
|||||||
"if x { 1 then 5, else 20 }",
|
"if x { 1 then 5, else 20 }",
|
||||||
exst! {
|
exst! {
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx!(Discriminator::Simple(ex!(s "x"))),
|
discriminator: Some(bx!(ex!(s "x"))),
|
||||||
body: bx!(IfExpressionBody::GuardList(
|
body: bx!(IfExpressionBody::CondList(
|
||||||
vec![
|
vec![
|
||||||
GuardArm {
|
ConditionArm {
|
||||||
guard: Guard::Pat(Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1)})),
|
condition: Condition::Pattern(Pattern::Literal(PatternLiteral::NumPattern { neg: false, num: NatLiteral(1)})),
|
||||||
|
guard: None,
|
||||||
body: vec![exst!(s "5")],
|
body: vec![exst!(s "5")],
|
||||||
},
|
},
|
||||||
GuardArm {
|
ConditionArm {
|
||||||
guard: Guard::None,
|
condition: Condition::Else,
|
||||||
|
guard: None,
|
||||||
body: vec![exst!(s "20")],
|
body: vec![exst!(s "20")],
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user