line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TOML::Tiny::Grammar; |
2
|
|
|
|
|
|
|
# ABSTRACT: exports regex definitions used to parse TOML source |
3
|
|
|
|
|
|
|
$TOML::Tiny::Grammar::VERSION = '0.16'; |
4
|
286
|
|
|
286
|
|
2237
|
use strict; |
|
286
|
|
|
|
|
716
|
|
|
286
|
|
|
|
|
8973
|
|
5
|
286
|
|
|
286
|
|
1750
|
use warnings; |
|
286
|
|
|
|
|
779
|
|
|
286
|
|
|
|
|
8438
|
|
6
|
286
|
|
|
286
|
|
3976
|
use v5.18; |
|
286
|
|
|
|
|
1098
|
|
7
|
|
|
|
|
|
|
|
8
|
286
|
|
|
286
|
|
133294
|
use parent 'Exporter'; |
|
286
|
|
|
|
|
87874
|
|
|
286
|
|
|
|
|
1984
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw( |
11
|
|
|
|
|
|
|
$WS |
12
|
|
|
|
|
|
|
$CRLF |
13
|
|
|
|
|
|
|
$EOL |
14
|
|
|
|
|
|
|
$Comment |
15
|
|
|
|
|
|
|
$NonASCII |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$BareKey |
18
|
|
|
|
|
|
|
$QuotedKey |
19
|
|
|
|
|
|
|
$SimpleKey |
20
|
|
|
|
|
|
|
$DottedKey |
21
|
|
|
|
|
|
|
$Key |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$Boolean |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$Escape |
26
|
|
|
|
|
|
|
$StringLiteral |
27
|
|
|
|
|
|
|
$MultiLineStringLiteral |
28
|
|
|
|
|
|
|
$BasicString |
29
|
|
|
|
|
|
|
$MultiLineString |
30
|
|
|
|
|
|
|
$String |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$Date |
33
|
|
|
|
|
|
|
$Time |
34
|
|
|
|
|
|
|
$DateTime |
35
|
|
|
|
|
|
|
$TimeOffset |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$Hex |
38
|
|
|
|
|
|
|
$Oct |
39
|
|
|
|
|
|
|
$Bin |
40
|
|
|
|
|
|
|
$Dec |
41
|
|
|
|
|
|
|
$Integer |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$Float |
44
|
|
|
|
|
|
|
$SpecialFloat |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
48
|
|
|
|
|
|
|
# Primitives |
49
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
our $WS = qr/[\x20\x09]/; # space, tab |
51
|
|
|
|
|
|
|
our $CRLF = qr/\x0D?\x0A/; # cr? lf |
52
|
|
|
|
|
|
|
our $CommentChar = qr/(?>[^[:cntrl:]]|\t)/; # non-control chars other than tab |
53
|
|
|
|
|
|
|
our $Comment = qr/\x23$CommentChar*/; # #comment |
54
|
|
|
|
|
|
|
our $EOL = qr/$Comment?$CRLF/; # crlf or comment + crlf |
55
|
|
|
|
|
|
|
our $Boolean = qr/\b(?:true)|(?:false)\b/; |
56
|
|
|
|
|
|
|
our $NonASCII = qr/[\x80-\x{D7FF}\x{E000}-\x{10FFFF}]/; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
59
|
|
|
|
|
|
|
# Strings |
60
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
our $Escape = qr{ |
62
|
|
|
|
|
|
|
\x5C # leading \ |
63
|
|
|
|
|
|
|
(?> |
64
|
|
|
|
|
|
|
[\x5C"btfnr] # escapes: \\ \" \b \t \n \f \r |
65
|
|
|
|
|
|
|
| (?> u [_0-9a-fA-F]{4}) # unicode (4 bytes) |
66
|
|
|
|
|
|
|
| (?> U [_0-9a-fA-F]{8}) # unicode (8 bytes) |
67
|
|
|
|
|
|
|
) |
68
|
|
|
|
|
|
|
}x; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
our $LiteralChar = qr{ [\x09\x20-\x26\x28-\x7E] | $NonASCII }x; |
71
|
|
|
|
|
|
|
our $StringLiteral = qr{ ' (?: $LiteralChar )* ' }x; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
our $MLLChar = qr{ [\x09\x20-\x26\x28-\x7E] | $NonASCII }x; |
74
|
|
|
|
|
|
|
our $MLLContent = qr{ $MLLChar | $CRLF }x; |
75
|
|
|
|
|
|
|
our $MLLQuotes = qr{ '{1,2} }x; |
76
|
|
|
|
|
|
|
our $MLLBody = qr{ $MLLContent* (?: $MLLQuotes | $MLLContent{0,1} )*? $MLLQuotes? }x; |
77
|
|
|
|
|
|
|
our $MultiLineStringLiteral = qr{ ''' (?: $CRLF? $MLLBody ) ''' }x; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
our $BasicChar = qr{ $WS | [\x21\x23-\x5B\x5D-\x7E] | $NonASCII | $Escape }x; |
80
|
|
|
|
|
|
|
our $BasicString = qr{ " (?: $BasicChar )* " }x; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
our $MLBEscapedNL = qr{ \x5c $WS* $CRLF (?: $WS | $CRLF)* }x; |
83
|
|
|
|
|
|
|
our $MLBUnescaped = qr{ $WS | [\x21\x23-\x5B\x5D-\x7E] | $NonASCII }x; |
84
|
|
|
|
|
|
|
our $MLBQuotes = qr{ "{1,2} }x; |
85
|
|
|
|
|
|
|
our $MLBChar = qr{ $MLBUnescaped | $Escape }x; |
86
|
|
|
|
|
|
|
our $MLBContent = qr{ $MLBChar | $CRLF | $MLBEscapedNL }x; |
87
|
|
|
|
|
|
|
our $MLBasicBody = qr{ $MLBContent* (?: $MLBQuotes | $MLBContent{0,1} )*? $MLBQuotes? }x; |
88
|
|
|
|
|
|
|
our $MultiLineString = qr{ """ $CRLF? $MLBasicBody """ }x; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
our $String = qr/$MultiLineString | $BasicString | $MultiLineStringLiteral | $StringLiteral/x; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
93
|
|
|
|
|
|
|
# Keys |
94
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
95
|
|
|
|
|
|
|
our $BareKey = qr/[-_\p{PosixAlnum}]+/; |
96
|
|
|
|
|
|
|
our $QuotedKey = qr/$BasicString|$StringLiteral/; |
97
|
|
|
|
|
|
|
our $SimpleKey = qr/$QuotedKey|$BareKey/; |
98
|
|
|
|
|
|
|
our $DottedKey = qr/$SimpleKey (?: $WS* \. $WS* $SimpleKey)+/x; |
99
|
|
|
|
|
|
|
our $Key = qr{ (?: $DottedKey | $SimpleKey ) }x; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
103
|
|
|
|
|
|
|
# Dates (RFC 3339) |
104
|
|
|
|
|
|
|
# 1985-04-12T23:20:50.52Z |
105
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
106
|
|
|
|
|
|
|
our $DateFullYear = qr{ \d{4} }x; |
107
|
|
|
|
|
|
|
our $DateMonth = qr{ (?: 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 ) }x; |
108
|
|
|
|
|
|
|
our $DateDay = qr{ (?: 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 ) }x; |
109
|
|
|
|
|
|
|
our $TimeDelim = qr{ (?: [tT] | \x20 ) }x; |
110
|
|
|
|
|
|
|
our $TimeHour = qr{ (?: 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 ) }x; |
111
|
|
|
|
|
|
|
our $TimeMinute = qr{ (?: 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 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 ) }x; |
112
|
|
|
|
|
|
|
our $TimeSecond = qr{ (?: 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 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 ) }x; # may be 60 during leap second |
113
|
|
|
|
|
|
|
our $TimeSecFrac = qr{ \. \d+ }x; |
114
|
|
|
|
|
|
|
our $TimeNumOffset = qr{ (?: [-+] $TimeHour : $TimeMinute ) }x; |
115
|
|
|
|
|
|
|
our $TimeOffset = qr{ (?: [zZ] | $TimeNumOffset ) }x; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
our $PartialTime = qr{ (?: $TimeHour : $TimeMinute : $TimeSecond $TimeSecFrac? ) }x; |
118
|
|
|
|
|
|
|
our $FullTime = qr{ (?: $PartialTime $TimeOffset ) }x; |
119
|
|
|
|
|
|
|
our $FullDate = qr{ (?: $DateFullYear - $DateMonth - $DateDay ) }x; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
our $OffsetDateTime = qr{ (?: $FullDate $TimeDelim $FullTime ) }x; |
122
|
|
|
|
|
|
|
our $LocalDateTime = qr{ (?: $FullDate $TimeDelim $PartialTime ) }x; |
123
|
|
|
|
|
|
|
our $LocalDate = qr{ (?: $FullDate ) }x; |
124
|
|
|
|
|
|
|
our $LocalTime = qr{ (?: $PartialTime ) }x; |
125
|
|
|
|
|
|
|
our $DateTime = qr{ (?: $OffsetDateTime | $LocalDateTime | $LocalDate | $LocalTime ) }x; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
128
|
|
|
|
|
|
|
# Integer |
129
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
130
|
|
|
|
|
|
|
our $DecFirstChar = qr/[1-9]/; |
131
|
|
|
|
|
|
|
our $DecChar = qr/[0-9]/; |
132
|
|
|
|
|
|
|
our $HexChar = qr/[0-9a-fA-F]/; |
133
|
|
|
|
|
|
|
our $OctChar = qr/[0-7]/; |
134
|
|
|
|
|
|
|
our $BinChar = qr/[01]/; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
our $Zero = qr/[-+]? 0/x; |
137
|
|
|
|
|
|
|
our $Hex = qr/0x $HexChar (?> _? $HexChar )*/x; |
138
|
|
|
|
|
|
|
our $Oct = qr/0o $OctChar (?> _? $OctChar )*/x; |
139
|
|
|
|
|
|
|
our $Bin = qr/0b $BinChar (?> _? $BinChar )*/x; |
140
|
|
|
|
|
|
|
our $Dec = qr/$Zero | (?> [-+]? $DecFirstChar (?> _? $DecChar )* )/x; |
141
|
|
|
|
|
|
|
our $Integer = qr/$Hex | $Oct | $Bin | $Dec/x; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
144
|
|
|
|
|
|
|
# Float |
145
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
146
|
|
|
|
|
|
|
our $SpecialFloat = qr/[-+]? (?: (?:inf) | (?:nan) | (?:NaN) )/x; |
147
|
|
|
|
|
|
|
our $Fraction = qr/\. $DecChar (?> _? $DecChar)*/x; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
our $Exponent = qr{ |
150
|
|
|
|
|
|
|
[eE] |
151
|
|
|
|
|
|
|
(?> |
152
|
|
|
|
|
|
|
$Zero+ # dec matches only one zero, but toml exponents apparently accept e00 |
153
|
|
|
|
|
|
|
| $Dec |
154
|
|
|
|
|
|
|
) |
155
|
|
|
|
|
|
|
}x; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
our $Float = qr{ |
158
|
|
|
|
|
|
|
(?> $Dec (?> (?> $Fraction $Exponent?) | $Exponent ) ) |
159
|
|
|
|
|
|
|
| $SpecialFloat |
160
|
|
|
|
|
|
|
}x; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=pod |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=encoding UTF-8 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 NAME |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
TOML::Tiny::Grammar - exports regex definitions used to parse TOML source |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 VERSION |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
version 0.16 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 SYNOPSIS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
use TOML::Tiny::Grammar; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
if ($src =~ /$MultiLineString/) { |
184
|
|
|
|
|
|
|
... |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 DESCRIPTION |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Exports various regexex for parsing TOML source. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 PATTERNS |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 White space and ignorables |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head3 $WS |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head3 $CRLF |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head3 $EOL |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head3 $Comment |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 Keys |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head3 $BareKey |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head3 $QuotedKey |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head3 $SimpleKey |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head3 $DottedKey |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head3 $Key |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 Values |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head3 $Boolean |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head3 $Escape |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head3 $StringLiteral |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head3 $MultiLineStringLiteral |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head3 $BasicString |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head3 $MultiLineString |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head3 $String |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head3 $Date |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head3 $Time |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head3 $DateTime |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head3 $Hex |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head3 $Oct |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head3 $Bin |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head3 $Dec |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head3 $Integer |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head3 $Float |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 $SpecialFloat |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 AUTHOR |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Jeff Ober <sysread@fastmail.fm> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Jeff Ober. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
260
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=cut |