-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
toml-v1.0.peg
105 lines (105 loc) · 4.57 KB
/
toml-v1.0.peg
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
toml = start_of_input ~ expression (newline expression)* end_of_input;
start_of_input = &.;
end_of_input = !.;
@lifted expression = ws (keyval / table)? ws comment?;
keyval = key keyval_sep ~ val;
@lifted keyval_sep = ws "=" ws;
@lifted key = dotted_key / simple_key;
@lifted simple_key = quoted_key / unquoted_key;
@squashed unquoted_key = (ALPHA / DIGIT / "-" / "_"){1,};
@squashed quoted_key = basic_string / literal_string;
dotted_key = simple_key (dot_sep simple_key)+;
@lifted dot_sep = ws "." ws;
@lifted val = boolean / datetime / array / inline_table / string / float / integer;
@lifted string = ml_literal_string / ml_basic_string / basic_string / literal_string;
@squashed basic_string = "\"" basic_char* "\"";
@lifted basic_char = basic_unescaped / escaped;
@lifted basic_unescaped = wschar / "!" / [\u0023-\u005B] / [\u005D-\u007E] / non_ascii;
@squashed escaped = "\\" ("\"" / "\\" / "b" / "f" / "n" / "r" / "t" / "u" HEXDIG{4} / "U" HEXDIG{8});
@squashed ml_basic_string = "\x22\x22\x22" ~ newline? ml_basic_body "\x22"{3,5};
ml_basic_body = mlb_content* (mlb_quotes mlb_content+)*;
mlb_content = mlb_char / newline / mlb_escaped_nl;
mlb_char = mlb_unescaped / escaped;
mlb_quotes = "\x22"{1,2};
mlb_unescaped = wschar / "\x21" / [\x23-\x5B] / [\x5D-\x7E] / non_ascii;
mlb_escaped_nl = "\x5C" ws newline (wschar / newline)*;
@squashed literal_string = "'" literal_char* "'";
@lifted literal_char = "\t" / [\u0020-\u0026] / [\u0028-\u007E] / non_ascii;
@squashed ml_literal_string = "'''" ~ newline? ml_literal_body "'"{3,5};
@squashed ml_literal_body = mll_content* (mll_quotes mll_content+)*;
mll_content = mll_char / newline;
mll_char = "\x09" / [\x20-\x26] / [\x28-\x7e] / non_ascii;
mll_quotes = "''" / "'";
boolean = "true" / "false";
minus = "-";
plus = "+";
@lifted underscore = "_";
one_nine = [1-9];
zero_seven = [0-7];
zero_one = [0-1];
zero_two = [0-2];
zero = "0";
one = "1";
@lifted hex_prefix = "0x";
@lifted oct_prefix = "0o";
@lifted bin_prefix = "0b";
dec_int = (minus / plus)? unsigned_dec_int;
unsigned_dec_int = "0" / one_nine (DIGIT / underscore DIGIT)*;
hex_int = hex_prefix HEXDIG (HEXDIG / underscore HEXDIG)*;
oct_int = oct_prefix zero_seven (zero_seven / underscore zero_seven)*;
bin_int = bin_prefix zero_one (zero_one / underscore zero_one)*;
@squashed integer = hex_int / oct_int / bin_int / dec_int;
@squashed float = special_float / dec_int (exp / frac exp?);zero_prefixed_int = DIGIT (underscore DIGIT / DIGIT)*;
frac = "." zero_prefixed_int;
exp = i"e" (minus / plus)? zero_prefixed_int;
special_float = (minus / plus)? (inf / nan);
inf = "inf";
nan = "nan";
@squashed date_fullyear = DIGIT{4};
@squashed date_month = zero one_nine / one zero_two;
@squashed date_mday = zero_two DIGIT / "30" / "31";
@lifted time_delim = i"t" / " ";
@squashed time_hour = DIGIT{2};
@squashed time_minute = DIGIT{2};
@squashed time_second = DIGIT{2};
@squashed time_secfrac = DIGIT+;
time_numoffset = (minus / plus) time_hour ":" time_minute;
@lifted time_offset = time_utc / time_numoffset;
time_utc = i"z";
@lifted partial_time = time_hour ":" ~ time_minute ":" time_second ("." time_secfrac)?;
@lifted full_date = date_fullyear "-" ~ date_month "-" date_mday;
@lifted full_time = partial_time time_offset;
offset_date_time = full_date time_delim full_time;
local_date_time = full_date time_delim partial_time;
local_date = full_date;
local_time = partial_time;
@lifted datetime = offset_date_time / local_date_time / local_date / local_time;
array = array_open ~ array_ws array_values? array_ws array_sep? array_ws array_close;
@lifted array_values = val (array_ws array_sep array_ws val)*;
@lifted array_open = "[";
@lifted array_close = "]";
@lifted array_sep = ",";
@lifted @squashed array_ws = (wschar / comment? newline)*;
inline_table = inline_table_open ~ ws inline_table_values? ws inline_table_close;
@lifted inline_table_values = keyval (ws inline_table_sep ws keyval)*;
@lifted inline_table_open = "{";
@lifted inline_table_close = "}";
@lifted inline_table_sep = ",";
@lifted table = array_table / std_table;
std_table = std_table_open ~ ws key ws std_table_close;
@lifted std_table_open = "[";
@lifted std_table_close = "]";
array_table = array_table_open ~ ws key ws array_table_close;
@lifted array_table_open = "[[";
@lifted array_table_close = "]]";
@lifted @squashed comment = comment_start comment_body;
comment_start = "#";
@squashed comment_body = non_eol*;
non_eol = "\t" / [\u0020-\u007F] / non_ascii;
non_ascii = [\u0080-\uD7FF] / [\uE000-\U0010FFFF];
@squashed @lifted newline = "\n" / "\r\n";
@lifted @squashed ws = wschar*;
wschar = " " / "\t";
ALPHA = [a-z] / [A-Z];
DIGIT = [0-9];
HEXDIG = [a-f] / [A-F] / [0-9];