Take care of all expression tests
This commit is contained in:
parent
c3d36ab320
commit
96d12f3659
@ -135,10 +135,10 @@ peg::parser! {
|
|||||||
":" _ identifier:type_identifier() { identifier }
|
":" _ identifier:type_identifier() { identifier }
|
||||||
|
|
||||||
pub rule expression() -> Expression =
|
pub rule expression() -> Expression =
|
||||||
_ kind:expression_kind() _ type_anno:type_anno()? { Expression { id: Default::default(), type_anno, kind: kind } }
|
__ kind:expression_kind() _ type_anno:type_anno()? { Expression { id: Default::default(), type_anno, kind } }
|
||||||
|
|
||||||
rule expression_no_struct() -> Expression =
|
rule expression_no_struct() -> Expression =
|
||||||
_ kind:expression_kind_no_struct() { Expression { id: Default::default(), type_anno: None, kind: kind } }
|
__ kind:expression_kind_no_struct() { Expression { id: Default::default(), type_anno: None, kind: kind } }
|
||||||
|
|
||||||
rule expression_kind() -> ExpressionKind =
|
rule expression_kind() -> ExpressionKind =
|
||||||
precedence_expr(true)
|
precedence_expr(true)
|
||||||
@ -333,7 +333,7 @@ peg::parser! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rule cond_block() -> IfExpressionBody =
|
rule cond_block() -> IfExpressionBody =
|
||||||
"{" _ cond_arms:(cond_arm() ++ ",") _ "}" { IfExpressionBody::CondList(cond_arms) }
|
"{" __ cond_arms:(cond_arm() ++ (delimiter()+)) __ "}" { IfExpressionBody::CondList(cond_arms) }
|
||||||
|
|
||||||
rule cond_arm() -> ConditionArm =
|
rule cond_arm() -> ConditionArm =
|
||||||
_ "else" _ body:expr_or_block() { ConditionArm { condition: Condition::Else, guard: None, body } } /
|
_ "else" _ body:expr_or_block() { ConditionArm { condition: Condition::Else, guard: None, body } } /
|
||||||
@ -347,7 +347,6 @@ peg::parser! {
|
|||||||
rule condition_guard() -> Option<Expression> =
|
rule condition_guard() -> Option<Expression> =
|
||||||
("if" _ expr:expression() { expr } )?
|
("if" _ expr:expression() { expr } )?
|
||||||
|
|
||||||
|
|
||||||
rule expr_or_block() -> Block = block() / ex:expression() {
|
rule expr_or_block() -> Block = block() / ex:expression() {
|
||||||
Statement {
|
Statement {
|
||||||
id: Default::default(), location: Default::default(),
|
id: Default::default(), location: Default::default(),
|
||||||
@ -388,7 +387,7 @@ peg::parser! {
|
|||||||
"true" { Pattern::Literal(PatternLiteral::BoolPattern(true)) } /
|
"true" { Pattern::Literal(PatternLiteral::BoolPattern(true)) } /
|
||||||
"false" { Pattern::Literal(PatternLiteral::BoolPattern(false)) } /
|
"false" { Pattern::Literal(PatternLiteral::BoolPattern(false)) } /
|
||||||
s:bare_string_literal() { Pattern::Literal(PatternLiteral::StringPattern(Rc::new(s.to_string()))) } /
|
s:bare_string_literal() { Pattern::Literal(PatternLiteral::StringPattern(Rc::new(s.to_string()))) } /
|
||||||
sign:("-"?) num:nat_literal() {
|
sign:("-"?) num:(float_literal() / nat_literal()) {
|
||||||
let neg = sign.is_some();
|
let neg = sign.is_some();
|
||||||
Pattern::Literal(PatternLiteral::NumPattern { neg, num })
|
Pattern::Literal(PatternLiteral::NumPattern { neg, num })
|
||||||
} /
|
} /
|
||||||
|
@ -133,13 +133,6 @@ macro_rules! assert_fail2 {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! assert_expr {
|
|
||||||
($input:expr, $correct:expr) => {
|
|
||||||
let mut parser = make_parser($input);
|
|
||||||
assert_eq!(parser.expression().unwrap(), $correct);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_expr2 {
|
macro_rules! assert_expr2 {
|
||||||
($input:expr, $correct:expr) => {
|
($input:expr, $correct:expr) => {
|
||||||
let expr = schala_parser::expression($input);
|
let expr = schala_parser::expression($input);
|
||||||
@ -1103,7 +1096,7 @@ fn if_exprs() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr!(
|
assert_expr2!(
|
||||||
r#"
|
r#"
|
||||||
if true then {
|
if true then {
|
||||||
let a = 10
|
let a = 10
|
||||||
@ -1188,7 +1181,7 @@ fn pattern_matching() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr2!(
|
||||||
"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))))),
|
||||||
body: bx(IfExpressionBody::CondList(vec![
|
body: bx(IfExpressionBody::CondList(vec![
|
||||||
@ -1221,7 +1214,7 @@ fn pattern_matching() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_expr! {
|
assert_expr2! {
|
||||||
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user