/// this is a https://en.wikipedia.org/wiki/Parsing_expression_grammar
/// It is meant for parsing Therion TH2 Files.
/// See https://docs.rs/cave-fmt/latest/cave_fmt/th2/index.html
///
/// Look into the
/// [complete PEG](https://github.com/mdornseif/cave-fmt/blob/main/src/th2.pest)
/// to understand what is actually recognized.
WHITESPACE = _{" "}
NAME = @{(ASCII_ALPHANUMERIC|"_"|".")+}
NUMBER = @{
"-"? ~ ("0"|ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*) ~ ("." ~ ASCII_DIGIT*)?
}
COMMENT = {"#" ~(!NEWLINE ~ANY) *~NEWLINE}
STRING = ${"\"" ~ inner ~"\""}
inner = _{char*}
char = _{ !("\"" | "\\") ~ ANY | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") | "\\" ~("u" ~ASCII_HEX_DIGIT{4})}
DATUM = @{ ASCII_DIGIT{2} ~ "." ~ ASCII_DIGIT{2} ~ "." ~ ASCII_DIGIT{2}}
encoding = {
"encoding" ~"utf-8" ~NEWLINE *}
xtbgimage = {"##XTHERION## xth_me_image_insert {" ~NUMBER ~NUMBER ~NUMBER ~"} {" ~NUMBER ~NUMBER ~"} " ~!WHITESPACE ~"0 {}" ~NEWLINE *}
xtcomment = {"##XTHERION##" ~!NEWLINE}
thscrap = {thscrapstart ~thscrapend}
// ^\s*scrap\s+(\S+)\s*(.*)$
thscrapstart = {"scrap" ~NAME ~thscrapoptions ~NEWLINE *}
// ^\s*endscrap\s*(\S*)\s*$
thscrapend = {"endscrap" ~NAME ? ~NEWLINE *}
thscrapoptions = _{(thscrapoptionplan | thscrapoptionstationnames | thscrapoptionauthor | thscrapoptionscale) *}
thscrapoptionplan = {"-projection" ~ thscrapoptionplanspec}
thscrapoptionplanspec = {"none"|"plan"|("[elevation" ~ NUMBER ~"]")|("[elevation" ~ NUMBER ~"deg" ~ "]")}
thscrapoptionstationnames = {"-station-names" ~ STRING ~ STRING}
thscrapoptionauthor = {"-author" ~ DATUM ~STRING}
thscrapoptionscale = {"-scale [0 0 1600 0 0.0 0.0 40.64 0.0 m]"}
command = _{encoding | xtbgimage | xtcomment | thscrap}
file = {
SOI ~ ("set" ~ command)* ~ EOI
}