diff --git a/schala-lang/language/src/parsing/new.rs b/schala-lang/language/src/parsing/new.rs index 5ee24a0..ca10053 100644 --- a/schala-lang/language/src/parsing/new.rs +++ b/schala-lang/language/src/parsing/new.rs @@ -23,8 +23,8 @@ 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() -> Block = "{" _ items:block_item()* _ "}" { items.into() } / - "{" _ stmt:statement() _ "}" { vec![stmt].into() } + pub rule block() -> Block = "{" __ items:block_item()* __ "}" { items.into() } / + "{" __ stmt:statement() __ "}" { vec![stmt].into() } rule block_item() -> Statement = stmt:statement() delimiter()+ { stmt } @@ -63,7 +63,7 @@ peg::parser! { sig:func_signature() { Declaration::FuncSig(sig) } rule func_declaration() -> Declaration = - sig:func_signature() __ body:block() { Declaration::FuncDecl(sig, body) } + _ sig:func_signature() __ body:block() { Declaration::FuncDecl(sig, body) } //TODO handle operators rule func_signature() -> Signature = @@ -82,7 +82,7 @@ peg::parser! { rule annotation() -> Declaration = - "@" name:identifier() args:annotation_args()? delimiter() _ inner:statement() { Declaration::Annotation { + "@" name:identifier() args:annotation_args()? delimiter()+ _ inner:statement() { Declaration::Annotation { name: rc_string(name), arguments: if let Some(args) = args { args } else { vec![] }, inner: Box::new(inner) } } diff --git a/schala-lang/language/src/parsing/test.rs b/schala-lang/language/src/parsing/test.rs index f6594e1..5496f87 100644 --- a/schala-lang/language/src/parsing/test.rs +++ b/schala-lang/language/src/parsing/test.rs @@ -817,6 +817,22 @@ fn functions() { type_anno: Some(TypeIdentifier::Singleton(TypeSingletonName { name: rc("Int"), params: vec![] })), })))] ); + + + let source = r#" + fn some_function() { + + }"#; + + assert_ast2!(source, vec![fn_decl( + Signature { + name: rc("some_function"), + operator: false, + type_anno: None, + params: vec![] + }, + vec![].into() + )]); } #[test] @@ -976,7 +992,7 @@ fn annotations() { vec![].into(), )); - assert_ast! { + assert_ast2! { r#" @test_annotation fn some_function() { @@ -990,7 +1006,7 @@ fn annotations() { ] }; - assert_ast! { + assert_ast2! { r#" @test_annotation(some,value) @another_annotation diff --git a/source_files/schala/syntax_playground.schala b/source_files/schala/syntax_playground.schala index af9cc47..c00e37c 100644 --- a/source_files/schala/syntax_playground.schala +++ b/source_files/schala/syntax_playground.schala @@ -77,7 +77,7 @@ x is Some(t) // type bool if x { is Some(t) => { - }, + } is None => { }