// Parsing globs in section content (everything among sqauare brackets) like [*.txt]
// in this case string *.txt will be parsed
grammar;

pub Defines : Vec<String> = {
    <s:Str> => vec![s],
    <l:List> => l,
    <l:Set> => l,
    <p:Str> <l:List> => { let v = l.iter().map(|i| format!("{p}{i}")).collect(); v },
    <p:Str> <l:List> <o:Str> => { let v = l.iter().map(|i| format!("{p}{i}{o}")).collect(); v },
    <l:List> <o:Str> => { let v = l.iter().map(|i| format!("{i}{o}")).collect(); v },
    <p:Str> <l:Set> => { let v = l.iter().map(|i| format!("{p}{i}")).collect(); v },
    <p:Str> <l:Set> <o:Str> => { let v = l.iter().map(|i| format!("{p}{i}{o}")).collect(); v },
    <l:Set> <o:Str> => { let v = l.iter().map(|i| format!("{i}{o}")).collect(); v },
}

List : Vec<String> = {
    "{" <w:ListItems> "}" => w,
}

Set : Vec<String> = {
    "[" <w:Str> "]" => w.chars().map(|c| format!("{c}")).collect(),
}

ListItems : Vec<String> = {
    <w:Defines> => w,
    <w:Defines> "," <ws:ListItems> => { let mut v = w; v.extend(ws); v }
}

#[inline]
Str : String = {
    r"[^{},\]\[ \t]+" => String::from(<>),
}
