diff --git a/schala-lang/src/parsing/combinator.rs b/schala-lang/src/parsing/combinator.rs index bbb993f..0720d44 100644 --- a/schala-lang/src/parsing/combinator.rs +++ b/schala-lang/src/parsing/combinator.rs @@ -129,7 +129,24 @@ fn statement(input: Span) -> ParseResult { } fn declaration(input: Span) -> ParseResult { - alt((binding, type_decl, func, module))(input) + alt((binding, type_decl, func, annotation, module))(input) +} + +fn annotation(input: Span) -> ParseResult { + map( + tuple(( + tok(char('@')), + identifier, + opt(delimited(tok(char('(')), separated_list1(tok(char(',')), expression), tok(char(')')))), + statement_delimiter, + statement, + )), + |(_, name, args, _, inner)| Declaration::Annotation { + name: rc_string(name.fragment()), + arguments: if let Some(args) = args { args } else { vec![] }, + inner: Box::new(inner), + }, + )(input) } fn func(input: Span) -> ParseResult { diff --git a/schala-lang/src/parsing/test.rs b/schala-lang/src/parsing/test.rs index 64ca58c..1059bd3 100644 --- a/schala-lang/src/parsing/test.rs +++ b/schala-lang/src/parsing/test.rs @@ -999,7 +999,7 @@ fn annotations() { vec![].into(), )); - assert_ast! { + assert_ast_comb! { r#" @test_annotation fn some_function() { @@ -1013,7 +1013,7 @@ fn annotations() { ] }; - assert_ast! { + assert_ast_comb! { r#" @test_annotation(some,value) @another_annotation @@ -1033,7 +1033,7 @@ fn annotations() { #[test] fn modules() { - assert_ast! { + assert_ast_comb! { r#" module ephraim { let mut a = 10