| 1 |
// pest. The Elegant Parser |
| 2 |
// Copyright (c) 2018 Dragoș Tiselice |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 |
| 5 |
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
| 6 |
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 7 |
// option. All files in the project carrying such notice may not be copied, |
| 8 |
// modified, or distributed except according to those terms. |
| 9 |
|
| 10 |
toml = { SOI ~ (table | array_table | pair)* ~ EOI } |
| 11 |
|
| 12 |
table = { "[" ~ key ~ ("." ~ key)* ~ "]" ~ pair* } |
| 13 |
array_table = { "[[" ~ key ~ ("." ~ key)* ~ "]]" ~ pair* } |
| 14 |
pair = { key ~ "=" ~ value } |
| 15 |
|
| 16 |
key = @{ identifier | string | literal } |
| 17 |
value = _{ |
| 18 |
inline_table | |
| 19 |
array | |
| 20 |
multi_line_string | |
| 21 |
string | |
| 22 |
multi_line_literal | |
| 23 |
literal | |
| 24 |
date_time | |
| 25 |
local_date_time | |
| 26 |
full_date | |
| 27 |
partial_time | |
| 28 |
float | |
| 29 |
integer | |
| 30 |
boolean |
| 31 |
} |
| 32 |
|
| 33 |
inline_table = { "{" ~ pair ~ ("," ~ pair)* ~ ","? ~ "}" | "{" ~ "}" } |
| 34 |
|
| 35 |
array = { "[" ~ value ~ ("," ~ value)* ~ ","? ~ "]" | "[" ~ "]" } |
| 36 |
|
| 37 |
identifier = { (ASCII_ALPHANUMERIC | "_" | "-")+ } |
| 38 |
|
| 39 |
multi_line_string = @{ "\"\"\"" ~ inner ~ "\"\"\"" } |
| 40 |
string = @{ "\"" ~ inner ~ "\"" } |
| 41 |
inner = @{ (!("\"" | "\\" | "\u{0000}" | "\u{001F}") ~ ANY)* ~ (escape ~ inner)? } |
| 42 |
multi_line_literal = @{ "'''" ~ (!"'''" ~ ANY)* ~ "'''" } |
| 43 |
literal = @{ "'" ~ (!"'" ~ ANY)* ~ "'" } |
| 44 |
|
| 45 |
// another comment |
| 46 |
|
| 47 |
escape = @{ "\\" ~ ("b" | "t" | "n" | "f" | "r" | "\"" | "\\" | unicode | NEWLINE)? } |
| 48 |
unicode = @{ "u" ~ ASCII_HEX_DIGIT{4} | "U" ~ ASCII_HEX_DIGIT{8} } |
| 49 |
|
| 50 |
date_time = ${ full_date ~ "T" ~ full_time } |
| 51 |
local_date_time = ${ full_date ~ "T" ~ partial_time } |
| 52 |
|
| 53 |
partial_time = ${ time_hour ~ ":" ~ time_minute ~ ":" ~ time_second ~ time_secfrac? } |
| 54 |
full_date = ${ date_fullyear ~ "-" ~ date_month ~ "-" ~ date_mday } |
| 55 |
full_time = ${ partial_time ~ time_offset } |
| 56 |
|
| 57 |
date_fullyear = @{ ASCII_DIGIT{4} } |
| 58 |
date_month = @{ ASCII_DIGIT{2} } |
| 59 |
date_mday = @{ ASCII_DIGIT{2} } |
| 60 |
|
| 61 |
time_hour = @{ ASCII_DIGIT{2} } |
| 62 |
time_minute = @{ ASCII_DIGIT{2} } |
| 63 |
time_second = @{ ASCII_DIGIT{2} } |
| 64 |
time_secfrac = @{ "." ~ ASCII_DIGIT+ } |
| 65 |
time_offset = ${ "Z" | ("+" | "-") ~ time_hour ~ ":" ~ time_minute } |
| 66 |
|
| 67 |
integer = @{ ("+" | "-")? ~ int } |
| 68 |
float = @{ ("+" | "-")? ~ int ~ ("." ~ digits ~ exp? | exp)? } |
| 69 |
int = @{ "0" | (ASCII_NONZERO_DIGIT ~ digits?) } |
| 70 |
digits = @{ (ASCII_DIGIT | ("_" ~ ASCII_DIGIT))+ } |
| 71 |
exp = @{ ("E" | "e") ~ ("+" | "-")? ~ int } |
| 72 |
|
| 73 |
boolean = { "true" | "false" } |
| 74 |
|
| 75 |
WHITESPACE = _{ " " | "\t" | NEWLINE } |
| 76 |
COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* } |