From 91985df449e59ec678f63fd12a8debfe12a5b23f Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 21 Nov 2021 02:23:50 -0800 Subject: [PATCH] Fix various parser bugs --- schala-lang/src/parsing/peg_parser.rs | 4 ++-- schala-lang/src/parsing/test.rs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/schala-lang/src/parsing/peg_parser.rs b/schala-lang/src/parsing/peg_parser.rs index f845ba7..3e07b18 100644 --- a/schala-lang/src/parsing/peg_parser.rs +++ b/schala-lang/src/parsing/peg_parser.rs @@ -37,7 +37,7 @@ peg::parser! { //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(parser: &mut Parser) -> Block = - "{" __ items:block_item(parser)* __ "}" { items.into() } / + "{" __ items:(statement(parser) ** delimiter()) delimiter()? __ "}" { items.into() } / "{" __ stmt:statement(parser) __ "}" { vec![stmt].into() } rule block_item(parser: &mut Parser) -> Statement = @@ -97,7 +97,7 @@ peg::parser! { } rule decl_block(parser: &mut Parser) -> Vec = - "{" __ decls:(func_declaration(parser) ** (delimiter()+)) __ "}" { decls } + "{" __ decls:(func_declaration(parser) ** (delimiter()+)) delimiter()? __ "}" { decls } rule interface(parser: &mut Parser) -> Declaration = "interface" _ name:identifier() _ signatures:signature_block(parser) { Declaration::Interface { name: rc_string(name), signatures } } diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 727e750..6e10f81 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -519,9 +519,8 @@ fn single_param_lambda() { fn complex_lambdas() { use ExpressionKind::*; - //TODO support this without the semicolon after the lambda assert_ast! { - r#"fn wahoo() { let a = 10; \(x) { x + a }; } + r#"fn wahoo() { let a = 10; \(x) { x + a } } wahoo()(3) "#, vec![ fn_decl(Signature { name: rc("wahoo"), operator: false, type_anno: None, params: vec![] }, @@ -991,9 +990,8 @@ fn impls() { vec![decl(Impl { type_name: ty_simple("Heh"), interface_name: None, block: block.clone() })] ); - //TODO `"impl Heh { fn yolo() { }; fn swagg() { }; }"` ought to work assert_ast!( - "impl Heh { fn yolo() { }; fn swagg() { } }", + "impl Heh { fn yolo() { }; fn swagg() { }; }", vec![decl(Impl { type_name: TypeIdentifier::Singleton(TypeSingletonName { name: rc("Heh"),