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