zap/model/src/plan.pest

54 lines
1.6 KiB
Plaintext

// This describes the plan definition grammar for zap
planfile = _{ SOI
~ task+
~ EOI }
task = { "task"
~ string
~ opening_brace
~ kwarg*
~ closing_brace
}
kwarg = { identifier ~ equals ~ arg }
// Right now only string arguments are supported
arg = { string }
// Unfortunately pest doesn't yet support sharing rules between grammars
// so everything below this line is copy/pasted between task.pest and
// plan.pest, when making changes to one, make sure to change the other
// An identifier will be used to refer to the task later
identifier = { ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
opening_brace = _{ "{" }
closing_brace = _{ "}" }
equals = _{ "=" }
quote = _{ "'" }
triple_quote = _{ "'''" }
string = { triple_quoted | single_quoted }
single_quoted = ${ (quote ~ inner_single_str ~ quote) }
inner_single_str = @{ (!(quote | "\\") ~ ANY)* ~ (escape ~ inner_single_str)? }
triple_quoted = ${ (triple_quote ~ inner_triple_str ~ triple_quote) }
inner_triple_str = @{ (!(triple_quote | "\\") ~ ANY)* ~ (escape ~ inner_triple_str)? }
escape = @{ "\\" ~ ("\"" | "\\" | "r" | "n" | "t" | "0" | "'" | code | unicode) }
code = @{ "x" ~ hex_digit{2} }
unicode = @{ "u" ~ opening_brace ~ hex_digit{2, 6} ~ closing_brace }
hex_digit = @{ '0'..'9' | 'a'..'f' | 'A'..'F' }
typedef = { string_type }
string_type = { "string" }
bool = { truthy | falsey }
truthy = { "true" }
falsey = { "false" }
block_comment = _{ "/*" ~ (block_comment | !"*/" ~ ANY)* ~ "*/" }
COMMENT = _{ block_comment | ("//" ~ (!NEWLINE~ ANY)*) }
WHITESPACE = _{ " " | "\t" | NEWLINE }