File: toml.pest

package info (click to toggle)
cloc 2.06-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,064 kB
  • sloc: perl: 30,146; cpp: 1,219; python: 623; ansic: 334; asm: 267; makefile: 244; sh: 186; sql: 144; java: 136; ruby: 111; cs: 104; pascal: 52; lisp: 50; haskell: 35; f90: 35; cobol: 35; objc: 25; php: 22; javascript: 15; fortran: 9; ml: 8; xml: 7; tcl: 2
file content (76 lines) | stat: -rw-r--r-- 2,563 bytes parent folder | download | duplicates (3)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// pest. The Elegant Parser
// Copyright (c) 2018 DragoČ™ Tiselice
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.

toml = { SOI ~ (table | array_table | pair)* ~ EOI }

table       = { "[" ~ key ~ ("." ~ key)* ~ "]" ~ pair* }
array_table = { "[[" ~ key ~ ("." ~ key)* ~ "]]" ~ pair* }
pair        = { key ~ "=" ~ value }

key   = @{ identifier | string | literal }
value = _{
    inline_table |
    array |
    multi_line_string |
    string |
    multi_line_literal |
    literal |
    date_time |
    local_date_time |
    full_date |
    partial_time |
    float |
    integer |
    boolean
}

inline_table = { "{" ~ pair ~ ("," ~ pair)* ~ ","? ~ "}" | "{" ~ "}" }

array = { "[" ~ value ~ ("," ~ value)* ~ ","? ~ "]" | "[" ~ "]" }

identifier = { (ASCII_ALPHANUMERIC | "_" | "-")+ }

multi_line_string  = @{ "\"\"\"" ~ inner ~ "\"\"\"" }
string             = @{ "\"" ~ inner ~ "\"" }
inner              = @{ (!("\"" | "\\" | "\u{0000}" | "\u{001F}") ~ ANY)* ~ (escape ~ inner)? }
multi_line_literal = @{ "'''" ~ (!"'''" ~ ANY)* ~ "'''" }
literal            = @{ "'" ~ (!"'" ~ ANY)* ~ "'" }

// another comment

escape  = @{ "\\" ~ ("b" | "t" | "n" | "f" | "r" | "\"" | "\\" | unicode | NEWLINE)? }
unicode = @{ "u" ~ ASCII_HEX_DIGIT{4} | "U" ~ ASCII_HEX_DIGIT{8} }

date_time       = ${ full_date ~ "T" ~ full_time }
local_date_time = ${ full_date ~ "T" ~ partial_time }

partial_time = ${ time_hour ~ ":" ~ time_minute ~ ":" ~ time_second ~ time_secfrac? }
full_date    = ${ date_fullyear ~ "-" ~ date_month ~ "-" ~ date_mday }
full_time    = ${ partial_time ~ time_offset }

date_fullyear = @{ ASCII_DIGIT{4} }
date_month    = @{ ASCII_DIGIT{2} }
date_mday     = @{ ASCII_DIGIT{2} }

time_hour    = @{ ASCII_DIGIT{2} }
time_minute  = @{ ASCII_DIGIT{2} }
time_second  = @{ ASCII_DIGIT{2} }
time_secfrac = @{ "." ~ ASCII_DIGIT+ }
time_offset  = ${ "Z" | ("+" | "-") ~ time_hour ~ ":" ~ time_minute }

integer = @{ ("+" | "-")? ~ int }
float   = @{ ("+" | "-")? ~ int ~ ("." ~ digits ~ exp? | exp)? }
int     = @{ "0" | (ASCII_NONZERO_DIGIT ~ digits?) }
digits  = @{ (ASCII_DIGIT | ("_" ~ ASCII_DIGIT))+ }
exp     = @{ ("E" | "e") ~ ("+" | "-")? ~ int }

boolean = { "true" | "false" }

WHITESPACE = _{ " " | "\t" | NEWLINE }
COMMENT    = _{ "#" ~ (!NEWLINE ~ ANY)* }