| 1 |
ini = { SOI ~ bom? ~ (blank | pair | comment)* ~ section* } |
| 2 |
|
| 3 |
// lines |
| 4 |
blank = _{ "" ~ NEWLINE } |
| 5 |
pair = { key ~ "=" ~ value ~ eol } |
| 6 |
comment = ${ indicator ~ comment_value ~ eol } |
| 7 |
comment_value = ${ char* } |
| 8 |
|
| 9 |
// sections |
| 10 |
section = { header ~ eol ~ body } |
| 11 |
body = { (blank | pair | comment)* } |
| 12 |
|
| 13 |
// tokens |
| 14 |
// a name must end with a closing bracket followed by optional whitespace and EOL |
| 15 |
header = ${ "[" ~ header_text ~ "]" } |
| 16 |
header_text = @{ (!header_end ~ char)+ } |
| 17 |
header_end = !{ "]" ~ eol } |
| 18 |
// a key may not begin with an opening bracket and may not contain an equal sign |
| 19 |
key = @{ (!("=" | "[") ~ char) ~ (!key_end ~ char)* } |
| 20 |
key_end = @{ (WHITESPACE* ~ "=") } // Trim key's trailing whitespace |
| 21 |
value = @{ (!value_end ~ char)* } |
| 22 |
value_end = @{ WHITESPACE+ ~ eol } // Trim value's trailing whitespace |
| 23 |
|
| 24 |
// atomic primitives |
| 25 |
bom = _{ "\u{feff}" } |
| 26 |
indicator = { "#" | ";" } |
| 27 |
char = { !eol ~ ANY } |
| 28 |
eol = _{ NEWLINE | EOI } |
| 29 |
|
| 30 |
WHITESPACE = _{ " " | "\t" } |