zap/model/src/task.pest

78 lines
2.2 KiB
Plaintext

/// This describes the task definition grammar for Zap
taskfile = _{ SOI
~ task+
~ EOI }
task = { "task"
~ identifier
~ opening_brace
~ parameters?
~ script
~ closing_brace
}
parameters = { "parameters"
~ opening_brace
~ parameter+
~ closing_brace
}
parameter = { identifier
~ opening_brace
~ required?
~ help
~ ptype
~ closing_brace
}
required = { "required" ~ equals ~ bool }
help = { "help" ~ equals ~ string }
ptype = { "type" ~ equals ~ typedef }
script = { "script"
~ opening_brace
~ (script_inline | script_file)
~ closing_brace
}
script_inline = { "inline" ~ equals ~ string }
script_file = { "file" ~ equals ~ 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 }