Block syntax fixes

This commit is contained in:
Greg Shuflin 2021-11-11 23:41:51 -08:00
parent 96d12f3659
commit a31735da88
3 changed files with 23 additions and 7 deletions

View File

@ -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) }
}

View File

@ -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

View File

@ -77,7 +77,7 @@ x is Some(t) // type bool
if x {
is Some(t) => {
},
}
is None => {
}