1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use super::{
    helpers::{parsing_catch_all, Pair},
    Rule,
};
use crate::{ast::*, parser::parse_arguments::parse_arguments_list};

pub(crate) fn parse_attribute(pair: Pair<'_>, diagnostics: &mut diagnostics::Diagnostics) -> Attribute {
    let span = Span::from(pair.as_span());
    let mut name = None;
    let mut arguments: ArgumentsList = ArgumentsList::default();

    for current in pair.into_inner() {
        match current.as_rule() {
            Rule::path => name = Some(current.into()),
            Rule::arguments_list => parse_arguments_list(current, &mut arguments, diagnostics),
            _ => parsing_catch_all(&current, "attribute"),
        }
    }

    let name = name.unwrap();
    Attribute { name, arguments, span }
}