Fix issue with block formatting
This commit is contained in:
parent
87141fcca3
commit
02fc76c8fc
@ -19,7 +19,13 @@ peg::parser! {
|
|||||||
id: Default::default(), location: Default::default(), kind: StatementKind::Expression(expr) }
|
id: Default::default(), location: Default::default(), kind: StatementKind::Expression(expr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
rule block() -> Block = "{" _ items:(statement() ** delimiter()) _ "}" { items.into() }
|
//Note - this is a hack, ideally the rule `rule block() -> Block = "{" _ items:(statement() **
|
||||||
|
//delimiter()) _ "}" { items.into() }` would've worked, but it doesn't.
|
||||||
|
pub rule block() -> Block = "{" _ items:block_item()* _ "}" { items.into() } /
|
||||||
|
"{" _ stmt:statement() _ "}" { vec![stmt].into() }
|
||||||
|
|
||||||
|
rule block_item() -> Statement =
|
||||||
|
stmt:statement() delimiter()+ { stmt }
|
||||||
|
|
||||||
pub rule expression() -> Expression =
|
pub rule expression() -> Expression =
|
||||||
_ kind:expression_kind() { Expression { id: Default::default(), type_anno: None, kind: kind } }
|
_ kind:expression_kind() { Expression { id: Default::default(), type_anno: None, kind: kind } }
|
||||||
|
@ -151,7 +151,6 @@ macro_rules! assert_fail_expr2 {
|
|||||||
//assert_eq!(err.to_string(), $failure);
|
//assert_eq!(err.to_string(), $failure);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_literals() {
|
fn basic_literals() {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
@ -388,8 +387,7 @@ fn for_expression() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert_expr2!(
|
assert_expr2!(
|
||||||
//TODO make "for n <- someRange { f(n); }" work!!
|
"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))) }],
|
||||||
body: bx(ForBody::StatementBlock(
|
body: bx(ForBody::StatementBlock(
|
||||||
@ -1295,3 +1293,15 @@ fn flow_control() {
|
|||||||
)]
|
)]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn blocks() {
|
||||||
|
use ExpressionKind::*;
|
||||||
|
|
||||||
|
let cases = ["{ a }", "{ a; }", "{a}", "{ a\n }", "{ a\n\n }", "{ a;\n\n; }"];
|
||||||
|
|
||||||
|
for case in cases.iter() {
|
||||||
|
let block = schala_parser::block(case);
|
||||||
|
assert_eq!(block.unwrap(), vec![exst(Value(qn!(a)))].into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user