//
// Example Json Policy:
// --------------------
//
// {
//   name: "or", children: [
//     { name: "idsc:BASE_CONNECTOR_SECURITY_PROFILE" },
//     { name: "idsc:USAGE_CONTROL_POLICY_ENFORCEMENT"}
//   ]
// }
//
// Constants
// Constants
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }
NAME = _{ "name" | "NAME" | QUOTE ~ "name" ~ QUOTE | QUOTE ~ "NAME" ~ QUOTE }
QUOTE = _{ "\"" }
CHILDREN = _{ "children" | "CHILDREN" | QUOTE ~ "children" ~ QUOTE | QUOTE ~ "CHILDREN" ~ QUOTE }
andvalue = _{ "and" | "AND" | "&&"  }
orvalue  = _{ "or" | "OR" | "||" }
andinner = _{ andvalue | QUOTE ~ andvalue ~ QUOTE }
orinner  = _{ orvalue | QUOTE ~ orvalue ~ QUOTE }
// Nodes
node = _{
    "{" ~ NAME ~ ":" ~ value ~ "}" |
    "{" ~ NAME ~ ":" ~ and ~ "}" |
    "{" ~ NAME ~ ":" ~ or ~ "}"
}
// Values
value = _{ string | number }
// Value types
and = {
    andinner ~ "," ~ CHILDREN ~ ":" ~ "[" ~ "]" |
    andinner ~ "," ~ CHILDREN ~ ":" ~ "[" ~ node ~ ("," ~ node)* ~ "]"
}
or = {
    orinner ~ "," ~ CHILDREN ~ ":" ~ "[" ~ "]" |
    orinner ~ "," ~ CHILDREN ~ ":" ~ "[" ~ node ~ ("," ~ node)* ~ "]"
}
string = ${QUOTE ~ inner ~ QUOTE}
inner = @{ char* }
char = _{
    !("\"" | "\\") ~ ANY
    | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
    | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
number = @{
    "-"?
    ~ ("0" | ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)
    ~ ("." ~ ASCII_DIGIT*)?
    ~ (^"e" ~ ("+" | "-")? ~ ASCII_DIGIT+)?
}
// complete input
content = _{ SOI ~ node ~ EOI }