px_wsdom_ts_parse/parser/
namespace.rs1use winnow::{
2 combinator::{delimited, preceded, repeat},
3 prelude::PResult,
4 Parser,
5};
6
7use super::{
8 comment::WithComment,
9 item::Item,
10 util::{token, token_word, word1, Parsable},
11};
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct Namespace<'a> {
15 name: &'a str,
16 items: Vec<WithComment<'a, Item<'a>>>,
17}
18
19impl<'a> Parsable<'a> for Namespace<'a> {
20 fn parse(input: &mut &'a str) -> PResult<Self> {
21 (
22 preceded((token_word("declare"), token_word("namespace")), word1),
23 delimited(token('{'), repeat(0.., WithComment::<Item>::parse), '}'),
24 )
25 .map(|(name, items)| Self { name, items })
26 .parse_next(input)
27 }
28}