forked from ingydotnet/yaml-pgx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml.pgx
134 lines (104 loc) · 2.04 KB
/
yaml.pgx
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# This is the Pegex grammar for YAML 1.2.
# It is currently in a fledgling state. It is only intended to pass the YAML
# TestML Suite. Eventually it will be able to parse any valid YAML 1.2
# document.
# To Do:
# - Comments (maybe as whitespace)
# - Directives
# - Tags
%grammar yaml
%version 1.2
yaml_stream: yaml_document*
yaml_document:
document_header?
(
flow_collection |
block_node |
block_scalar
)
document_footer?
document_header:
/ ( <DASH><DASH><DASH> ) <ws> /
document_footer:
/ <DOT><DOT><DOT> <EOL> /
block_node:
block_seq |
block_map |
block_scalar
block_map:
indent
block_pair+
undent
block_seq:
indent
block_elem+
undent
block_scalar:
double_quoted |
single_quoted |
plain_string |
empty_string
# literal_string |
# folded_string |
block_pair:
indentation block_key /~<COLON>~/ block_value BREAK
block_elem:
indentation /<DASH><SPACE>/ block_value BREAK
block_key:
double_quoted |
single_quoted |
plain_string
block_value:
flow_collection |
block_node
flow_collection:
flow_map |
flow_seq
flow_node:
flow_collection |
flow_scalar
flow_map:
/ ~ <LCURLY> ~ /
flow_pair* % / ~ <COMMA> ~ /
/ ~ <RCURLY> ~ /
flow_seq:
/ ~ <LSQUARE> ~ /
flow_node* % / ~ <COMMA> ~ /
/ ~ <RSQUARE> ~ /
flow_scalar:
double_quoted |
single_quoted |
plain_string
flow_pair:
flow_node / ~ <COLON> ~ / flow_node
double_quoted: /
<DOUBLE>
((:
<BACK><BACK> |
<BACK><DOUBLE> |
[^<DOUBLE><BREAK>]
)*)
<DOUBLE>
/
single_quoted: /
<SINGLE>
((:
<SINGLE><SINGLE> |
[^<SINGLE>]
)*)
<SINGLE>
/
plain_string: / ( [^<non_starters>] [^<non_plain>]* ) /
empty_string: //
literal_string: `literal_string not yet supported`
folded_string: `folded_string not yet supported`
non_starters: /
<PERCENT>
<SINGLE>
<DOUBLE>
<SPACE>
/
non_plain: /
<COLON>
<BREAK>
/