OpenTally/src/parser/blt.pest

37 lines
789 B
Plaintext

main = {
SOI ~ NEWLINE*
~ header ~ NEWLINE*
~ withdrawn ~ NEWLINE*
~ ballot_list
~ zero ~ NEWLINE*
~ (string ~ NEWLINE*)+
~ EOI
}
header = {
integer ~ integer
}
withdrawn = {
(withdrawn_cand ~ NEWLINE*)*
}
withdrawn_cand = @{ "-" ~ integer }
ballot_list = { (ballot ~ NEWLINE*)* }
ballot = {
number ~ ballot_preferences ~ (zero ~ NEWLINE? | NEWLINE)
}
ballot_preferences = { integer* }
zero = { "0" }
integer = @{ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* }
decimal = @{ "0." ~ ASCII_DIGIT+ | integer ~ "." ~ ASCII_DIGIT+ }
number = { decimal | integer }
quoted_string = @{ "\"" ~ (!"\"" ~ !NEWLINE ~ ANY)* ~ "\"" }
raw_string = @{ (!" " ~ !NEWLINE ~ ANY)+ }
string = { quoted_string | raw_string }
WHITESPACE = _{ " " }
COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ (&NEWLINE | &EOI) }