aldrin_parser/ast/
attribute.rs1use super::Ident;
2use crate::grammar::Rule;
3use crate::Span;
4use pest::iterators::Pair;
5
6#[derive(Debug, Clone)]
7pub struct Attribute {
8 span: Span,
9 name: Ident,
10 options: Vec<Ident>,
11}
12
13impl Attribute {
14 pub(crate) fn parse(pair: Pair<Rule>) -> Self {
15 assert_eq!(pair.as_rule(), Rule::attribute);
16
17 let span = Span::from_pair(&pair);
18
19 let mut pairs = pair.into_inner();
20 pairs.next().unwrap(); pairs.next().unwrap(); let pair = pairs.next().unwrap();
24 let name = Ident::parse(pair);
25
26 let mut att = Self {
27 span,
28 name,
29 options: Vec::new(),
30 };
31
32 for pair in pairs {
33 match pair.as_rule() {
34 Rule::ident => att.options.push(Ident::parse(pair)),
35 Rule::tok_par_open
36 | Rule::tok_par_close
37 | Rule::tok_comma
38 | Rule::tok_squ_close => {}
39 _ => unreachable!(),
40 }
41 }
42
43 att
44 }
45
46 pub fn span(&self) -> Span {
47 self.span
48 }
49
50 pub fn name(&self) -> &Ident {
51 &self.name
52 }
53
54 pub fn options(&self) -> &[Ident] {
55 &self.options
56 }
57}