Annotations
This commit is contained in:
parent
33573bf268
commit
65c745fb30
@ -129,7 +129,24 @@ fn statement(input: Span) -> ParseResult<Statement> {
|
||||
}
|
||||
|
||||
fn declaration(input: Span) -> ParseResult<Declaration> {
|
||||
alt((binding, type_decl, func, module))(input)
|
||||
alt((binding, type_decl, func, annotation, module))(input)
|
||||
}
|
||||
|
||||
fn annotation(input: Span) -> ParseResult<Declaration> {
|
||||
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<Declaration> {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user