lib/DMS/Parser.pm

filter: Statementstmt 15.5% 279 / 1796 Branchbran 9.1% 96 / 1050 Conditioncond 7.7% 45 / 579 MC/DCmcdc 1.2% 4 / 325 Subroutinesub 21.3% 28 / 131 Podpod 11.6% 5 / 43 totaltotal 11.6% 457 / 3924 CC 738 SCAR 60.9
CC
738
Cov
12%
_parse_integer
2756.0
_parse_lite_document_fast
1560.0
parse_datetime_value
992.0
CRAP 440.2
« blib/lib/DMS/Parser/Tier1.pm ↑ Summary blib/lib/DMS/Parser/Emitter.pm »
1 package DMS::Parser;
2 # DMS parser — Perl port of the Rust reference.
3 # Public (SPEC v0.14): DMS::Parser::decode($src) -> hashref/arrayref/scalar/blessed-DT.
4 # The legacy spelling DMS::Parser::parse($src) is retained as a deprecated
5 # alias and emits a one-time Carp::carp warning per process. SPEC §Decode/Encode.
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 # Tie::IxHash is loaded lazily (only when non-lite mode actually
12 # constructs a tied table) — saves ~30ms of startup and avoids the
13 # import entirely on the lite/encoder hot path.
14 # Several historical imports (POSIX qw(floor), Math::BigInt, Encode)
15 # have been removed: floor is unused; integer parsing now hand-rolls
16 # i64 on native IVs (no BigInt); UTF-8 work goes through utf8::is_utf8
17 # / utf8::decode core builtins (no Encode). Importing those modules
18 # only at need keeps DMS::Parser load time low — material on small
19 # CLI invocations like the conformance encoder.
20 # Unicode::Normalize is loaded lazily — pure-ASCII source short-circuits
21 # the NFC pass, so most CLI invocations never need the module at all.
22 0 ▶sub _NFC { require Unicode::Normalize; *_NFC = \&Unicode::Normalize::NFC; goto &_NFC }
Subroutine _NFC: not called CC=1 SCAR=6.9
23  
24 3 our $VERSION = '0.5.3';
25  
26 # Capability flag — this port ships lite-mode decode + lite-mode encode_lite.
27 # See SPEC §Parsing modes — full and lite.
28 3 our $SUPPORTS_LITE_MODE = 1;
29  
30 # Capability flag — this port ships unordered-table parse mode.
31 # See SPEC §Unordered tables.
32 3 our $SUPPORTS_IGNORE_ORDER = 1;
33  
34 # Datetime sentinel classes -----------------------------------------------
35 # All typed-scalar sentinels are blessed *scalar refs* rather than blessed
36 # hashrefs. That's one allocation instead of three (HV + hv_entry + RV)
37 # per value — noticeable on wide-flat documents where every leaf is a
38 # typed scalar. Public accessor API (->value, ->bstr, ->is_neg) unchanged.
39 0 ▶package DMS::Parser::LocalDate; sub new { my $v = "$_[1]"; bless \$v, $_[0] } sub value { ${ $_[0] } }
Subroutine new: not called CC=1 SCAR=6.9
Subroutine value: not called CC=1 SCAR=6.9
40 0 ▶package DMS::Parser::LocalTime; sub new { my $v = "$_[1]"; bless \$v, $_[0] } sub value { ${ $_[0] } }
Subroutine new: not called CC=1 SCAR=6.9
Subroutine value: not called CC=1 SCAR=6.9
41 0 ▶package DMS::Parser::LocalDateTime; sub new { my $v = "$_[1]"; bless \$v, $_[0] } sub value { ${ $_[0] } }
Subroutine new: not called CC=1 SCAR=6.9
Subroutine value: not called CC=1 SCAR=6.9
42 0 ▶package DMS::Parser::OffsetDateTime; sub new { my $v = "$_[1]"; bless \$v, $_[0] } sub value { ${ $_[0] } }
Subroutine new: not called CC=1 SCAR=6.9
Subroutine value: not called CC=1 SCAR=6.9
43 0 ▶package DMS::Parser::Float; sub new { my $v = 0 + $_[1]; bless \$v, $_[0] } sub value { ${ $_[0] } }
Subroutine new: not called CC=1 SCAR=6.9
Subroutine value: not called CC=1 SCAR=6.9
44 # DMS::Parser::Integer holds the canonical decimal representation. On 64-bit Perl
45 # it's stored as a native IV so the parser doesn't pay a string-format
46 # cost just to build it. `value()` returns the object itself so callers
47 # can chain `->bstr` / `->is_neg` — the public API matches what was
48 # previously a Math::BigInt instance (`$int->value->bstr` still works).
49 package DMS::Parser::Integer;
50 0 ▶sub new { my $v = 0 + $_[1]; bless \$v, $_[0] }
Subroutine new: not called CC=1 SCAR=6.9
51 0 ▶sub value { $_[0] }
Subroutine value: not called CC=1 SCAR=6.9
52 0 ▶sub bstr { "${ $_[0] }" } # force stringification of the IV
Subroutine bstr: not called CC=1 SCAR=6.9
53 0 ▶sub is_neg { ${ $_[0] } < 0 }
Subroutine is_neg: not called CC=1 SCAR=6.9
54 0 ▶package DMS::Parser::Bool; sub new { my $v = $_[1]?1:0; bless \$v, $_[0] } sub value { ${ $_[0] } }
Subroutine new: not called CC=2 SCAR=17.9
Subroutine value: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 0 0
55  
56 # Path-segment marker class used inside attached-comment paths to
57 # distinguish list-index segments (DMS::Parser::Index) from string-keyed table
58 # segments (plain Perl scalars). Mirrors Rust's BreadcrumbSegment::Index.
59 package DMS::Parser::Index;
60 0 ▶sub new { my $v = 0 + $_[1]; bless \$v, $_[0] }
Subroutine new: not called CC=1 SCAR=6.9
61 0 ▶sub value { ${ $_[0] } }
Subroutine value: not called CC=1 SCAR=6.9
62  
63 # SPEC §"Unordered tables". Marker class for body tables produced by the
64 # *_unordered parser entry points. Underlying storage is a plain Perl
65 # hashref (no Tie::IxHash, no `\0_keys` sidecar) — iteration order is
66 # arbitrary per Perl's hash randomization. Mirrors Rust's
67 # Value::UnorderedTable. `to_dms` (full mode) refuses to round-trip a
68 # Document containing this variant; `to_dms_lite` accepts it.
69 package DMS::Parser::UnorderedTable;
70 # Construct from a plain hashref. Caller hands ownership of the hash.
71 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
72 0 my ($class, $h) = @_;
73 0 ▶ $h = {} unless defined $h;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 0 0 0
74 0 return bless $h, $class;
75 }
76  
77 package DMS::Parser;
78  
79 # UAX #31 §2 default identifier syntax frozen at Unicode 15.1.
80 # Sorted, non-overlapping ranges: XID_Continue \ Default_Ignorable_Code_Point
81 # (per SPEC: every parser must use this same frozen snapshot — relying on
82 # Perl's `\p{XID_Continue}` would track the host's Unicode data and accept
83 # newly-assigned codepoints DMS does not know about). 772 ranges total.
84 3 our @XID_CONTINUE_RANGES = (
85 [0x00AA, 0x00AA],
86 [0x00B5, 0x00B5],
87 [0x00B7, 0x00B7],
88 [0x00BA, 0x00BA],
89 [0x00C0, 0x00D6],
90 [0x00D8, 0x00F6],
91 [0x00F8, 0x02C1],
92 [0x02C6, 0x02D1],
93 [0x02E0, 0x02E4],
94 [0x02EC, 0x02EC],
95 [0x02EE, 0x02EE],
96 [0x0300, 0x034E],
97 [0x0350, 0x0374],
98 [0x0376, 0x0377],
99 [0x037B, 0x037D],
100 [0x037F, 0x037F],
101 [0x0386, 0x038A],
102 [0x038C, 0x038C],
103 [0x038E, 0x03A1],
104 [0x03A3, 0x03F5],
105 [0x03F7, 0x0481],
106 [0x0483, 0x0487],
107 [0x048A, 0x052F],
108 [0x0531, 0x0556],
109 [0x0559, 0x0559],
110 [0x0560, 0x0588],
111 [0x0591, 0x05BD],
112 [0x05BF, 0x05BF],
113 [0x05C1, 0x05C2],
114 [0x05C4, 0x05C5],
115 [0x05C7, 0x05C7],
116 [0x05D0, 0x05EA],
117 [0x05EF, 0x05F2],
118 [0x0610, 0x061A],
119 [0x0620, 0x0669],
120 [0x066E, 0x06D3],
121 [0x06D5, 0x06DC],
122 [0x06DF, 0x06E8],
123 [0x06EA, 0x06FC],
124 [0x06FF, 0x06FF],
125 [0x0710, 0x074A],
126 [0x074D, 0x07B1],
127 [0x07C0, 0x07F5],
128 [0x07FA, 0x07FA],
129 [0x07FD, 0x07FD],
130 [0x0800, 0x082D],
131 [0x0840, 0x085B],
132 [0x0860, 0x086A],
133 [0x0870, 0x0887],
134 [0x0889, 0x088E],
135 [0x0898, 0x08E1],
136 [0x08E3, 0x0963],
137 [0x0966, 0x096F],
138 [0x0971, 0x0983],
139 [0x0985, 0x098C],
140 [0x098F, 0x0990],
141 [0x0993, 0x09A8],
142 [0x09AA, 0x09B0],
143 [0x09B2, 0x09B2],
144 [0x09B6, 0x09B9],
145 [0x09BC, 0x09C4],
146 [0x09C7, 0x09C8],
147 [0x09CB, 0x09CE],
148 [0x09D7, 0x09D7],
149 [0x09DC, 0x09DD],
150 [0x09DF, 0x09E3],
151 [0x09E6, 0x09F1],
152 [0x09FC, 0x09FC],
153 [0x09FE, 0x09FE],
154 [0x0A01, 0x0A03],
155 [0x0A05, 0x0A0A],
156 [0x0A0F, 0x0A10],
157 [0x0A13, 0x0A28],
158 [0x0A2A, 0x0A30],
159 [0x0A32, 0x0A33],
160 [0x0A35, 0x0A36],
161 [0x0A38, 0x0A39],
162 [0x0A3C, 0x0A3C],
163 [0x0A3E, 0x0A42],
164 [0x0A47, 0x0A48],
165 [0x0A4B, 0x0A4D],
166 [0x0A51, 0x0A51],
167 [0x0A59, 0x0A5C],
168 [0x0A5E, 0x0A5E],
169 [0x0A66, 0x0A75],
170 [0x0A81, 0x0A83],
171 [0x0A85, 0x0A8D],
172 [0x0A8F, 0x0A91],
173 [0x0A93, 0x0AA8],
174 [0x0AAA, 0x0AB0],
175 [0x0AB2, 0x0AB3],
176 [0x0AB5, 0x0AB9],
177 [0x0ABC, 0x0AC5],
178 [0x0AC7, 0x0AC9],
179 [0x0ACB, 0x0ACD],
180 [0x0AD0, 0x0AD0],
181 [0x0AE0, 0x0AE3],
182 [0x0AE6, 0x0AEF],
183 [0x0AF9, 0x0AFF],
184 [0x0B01, 0x0B03],
185 [0x0B05, 0x0B0C],
186 [0x0B0F, 0x0B10],
187 [0x0B13, 0x0B28],
188 [0x0B2A, 0x0B30],
189 [0x0B32, 0x0B33],
190 [0x0B35, 0x0B39],
191 [0x0B3C, 0x0B44],
192 [0x0B47, 0x0B48],
193 [0x0B4B, 0x0B4D],
194 [0x0B55, 0x0B57],
195 [0x0B5C, 0x0B5D],
196 [0x0B5F, 0x0B63],
197 [0x0B66, 0x0B6F],
198 [0x0B71, 0x0B71],
199 [0x0B82, 0x0B83],
200 [0x0B85, 0x0B8A],
201 [0x0B8E, 0x0B90],
202 [0x0B92, 0x0B95],
203 [0x0B99, 0x0B9A],
204 [0x0B9C, 0x0B9C],
205 [0x0B9E, 0x0B9F],
206 [0x0BA3, 0x0BA4],
207 [0x0BA8, 0x0BAA],
208 [0x0BAE, 0x0BB9],
209 [0x0BBE, 0x0BC2],
210 [0x0BC6, 0x0BC8],
211 [0x0BCA, 0x0BCD],
212 [0x0BD0, 0x0BD0],
213 [0x0BD7, 0x0BD7],
214 [0x0BE6, 0x0BEF],
215 [0x0C00, 0x0C0C],
216 [0x0C0E, 0x0C10],
217 [0x0C12, 0x0C28],
218 [0x0C2A, 0x0C39],
219 [0x0C3C, 0x0C44],
220 [0x0C46, 0x0C48],
221 [0x0C4A, 0x0C4D],
222 [0x0C55, 0x0C56],
223 [0x0C58, 0x0C5A],
224 [0x0C5D, 0x0C5D],
225 [0x0C60, 0x0C63],
226 [0x0C66, 0x0C6F],
227 [0x0C80, 0x0C83],
228 [0x0C85, 0x0C8C],
229 [0x0C8E, 0x0C90],
230 [0x0C92, 0x0CA8],
231 [0x0CAA, 0x0CB3],
232 [0x0CB5, 0x0CB9],
233 [0x0CBC, 0x0CC4],
234 [0x0CC6, 0x0CC8],
235 [0x0CCA, 0x0CCD],
236 [0x0CD5, 0x0CD6],
237 [0x0CDD, 0x0CDE],
238 [0x0CE0, 0x0CE3],
239 [0x0CE6, 0x0CEF],
240 [0x0CF1, 0x0CF3],
241 [0x0D00, 0x0D0C],
242 [0x0D0E, 0x0D10],
243 [0x0D12, 0x0D44],
244 [0x0D46, 0x0D48],
245 [0x0D4A, 0x0D4E],
246 [0x0D54, 0x0D57],
247 [0x0D5F, 0x0D63],
248 [0x0D66, 0x0D6F],
249 [0x0D7A, 0x0D7F],
250 [0x0D81, 0x0D83],
251 [0x0D85, 0x0D96],
252 [0x0D9A, 0x0DB1],
253 [0x0DB3, 0x0DBB],
254 [0x0DBD, 0x0DBD],
255 [0x0DC0, 0x0DC6],
256 [0x0DCA, 0x0DCA],
257 [0x0DCF, 0x0DD4],
258 [0x0DD6, 0x0DD6],
259 [0x0DD8, 0x0DDF],
260 [0x0DE6, 0x0DEF],
261 [0x0DF2, 0x0DF3],
262 [0x0E01, 0x0E3A],
263 [0x0E40, 0x0E4E],
264 [0x0E50, 0x0E59],
265 [0x0E81, 0x0E82],
266 [0x0E84, 0x0E84],
267 [0x0E86, 0x0E8A],
268 [0x0E8C, 0x0EA3],
269 [0x0EA5, 0x0EA5],
270 [0x0EA7, 0x0EBD],
271 [0x0EC0, 0x0EC4],
272 [0x0EC6, 0x0EC6],
273 [0x0EC8, 0x0ECE],
274 [0x0ED0, 0x0ED9],
275 [0x0EDC, 0x0EDF],
276 [0x0F00, 0x0F00],
277 [0x0F18, 0x0F19],
278 [0x0F20, 0x0F29],
279 [0x0F35, 0x0F35],
280 [0x0F37, 0x0F37],
281 [0x0F39, 0x0F39],
282 [0x0F3E, 0x0F47],
283 [0x0F49, 0x0F6C],
284 [0x0F71, 0x0F84],
285 [0x0F86, 0x0F97],
286 [0x0F99, 0x0FBC],
287 [0x0FC6, 0x0FC6],
288 [0x1000, 0x1049],
289 [0x1050, 0x109D],
290 [0x10A0, 0x10C5],
291 [0x10C7, 0x10C7],
292 [0x10CD, 0x10CD],
293 [0x10D0, 0x10FA],
294 [0x10FC, 0x115E],
295 [0x1161, 0x1248],
296 [0x124A, 0x124D],
297 [0x1250, 0x1256],
298 [0x1258, 0x1258],
299 [0x125A, 0x125D],
300 [0x1260, 0x1288],
301 [0x128A, 0x128D],
302 [0x1290, 0x12B0],
303 [0x12B2, 0x12B5],
304 [0x12B8, 0x12BE],
305 [0x12C0, 0x12C0],
306 [0x12C2, 0x12C5],
307 [0x12C8, 0x12D6],
308 [0x12D8, 0x1310],
309 [0x1312, 0x1315],
310 [0x1318, 0x135A],
311 [0x135D, 0x135F],
312 [0x1369, 0x1371],
313 [0x1380, 0x138F],
314 [0x13A0, 0x13F5],
315 [0x13F8, 0x13FD],
316 [0x1401, 0x166C],
317 [0x166F, 0x167F],
318 [0x1681, 0x169A],
319 [0x16A0, 0x16EA],
320 [0x16EE, 0x16F8],
321 [0x1700, 0x1715],
322 [0x171F, 0x1734],
323 [0x1740, 0x1753],
324 [0x1760, 0x176C],
325 [0x176E, 0x1770],
326 [0x1772, 0x1773],
327 [0x1780, 0x17B3],
328 [0x17B6, 0x17D3],
329 [0x17D7, 0x17D7],
330 [0x17DC, 0x17DD],
331 [0x17E0, 0x17E9],
332 [0x1810, 0x1819],
333 [0x1820, 0x1878],
334 [0x1880, 0x18AA],
335 [0x18B0, 0x18F5],
336 [0x1900, 0x191E],
337 [0x1920, 0x192B],
338 [0x1930, 0x193B],
339 [0x1946, 0x196D],
340 [0x1970, 0x1974],
341 [0x1980, 0x19AB],
342 [0x19B0, 0x19C9],
343 [0x19D0, 0x19DA],
344 [0x1A00, 0x1A1B],
345 [0x1A20, 0x1A5E],
346 [0x1A60, 0x1A7C],
347 [0x1A7F, 0x1A89],
348 [0x1A90, 0x1A99],
349 [0x1AA7, 0x1AA7],
350 [0x1AB0, 0x1ABD],
351 [0x1ABF, 0x1ACE],
352 [0x1B00, 0x1B4C],
353 [0x1B50, 0x1B59],
354 [0x1B6B, 0x1B73],
355 [0x1B80, 0x1BF3],
356 [0x1C00, 0x1C37],
357 [0x1C40, 0x1C49],
358 [0x1C4D, 0x1C7D],
359 [0x1C80, 0x1C88],
360 [0x1C90, 0x1CBA],
361 [0x1CBD, 0x1CBF],
362 [0x1CD0, 0x1CD2],
363 [0x1CD4, 0x1CFA],
364 [0x1D00, 0x1F15],
365 [0x1F18, 0x1F1D],
366 [0x1F20, 0x1F45],
367 [0x1F48, 0x1F4D],
368 [0x1F50, 0x1F57],
369 [0x1F59, 0x1F59],
370 [0x1F5B, 0x1F5B],
371 [0x1F5D, 0x1F5D],
372 [0x1F5F, 0x1F7D],
373 [0x1F80, 0x1FB4],
374 [0x1FB6, 0x1FBC],
375 [0x1FBE, 0x1FBE],
376 [0x1FC2, 0x1FC4],
377 [0x1FC6, 0x1FCC],
378 [0x1FD0, 0x1FD3],
379 [0x1FD6, 0x1FDB],
380 [0x1FE0, 0x1FEC],
381 [0x1FF2, 0x1FF4],
382 [0x1FF6, 0x1FFC],
383 [0x203F, 0x2040],
384 [0x2054, 0x2054],
385 [0x2071, 0x2071],
386 [0x207F, 0x207F],
387 [0x2090, 0x209C],
388 [0x20D0, 0x20DC],
389 [0x20E1, 0x20E1],
390 [0x20E5, 0x20F0],
391 [0x2102, 0x2102],
392 [0x2107, 0x2107],
393 [0x210A, 0x2113],
394 [0x2115, 0x2115],
395 [0x2118, 0x211D],
396 [0x2124, 0x2124],
397 [0x2126, 0x2126],
398 [0x2128, 0x2128],
399 [0x212A, 0x2139],
400 [0x213C, 0x213F],
401 [0x2145, 0x2149],
402 [0x214E, 0x214E],
403 [0x2160, 0x2188],
404 [0x2C00, 0x2CE4],
405 [0x2CEB, 0x2CF3],
406 [0x2D00, 0x2D25],
407 [0x2D27, 0x2D27],
408 [0x2D2D, 0x2D2D],
409 [0x2D30, 0x2D67],
410 [0x2D6F, 0x2D6F],
411 [0x2D7F, 0x2D96],
412 [0x2DA0, 0x2DA6],
413 [0x2DA8, 0x2DAE],
414 [0x2DB0, 0x2DB6],
415 [0x2DB8, 0x2DBE],
416 [0x2DC0, 0x2DC6],
417 [0x2DC8, 0x2DCE],
418 [0x2DD0, 0x2DD6],
419 [0x2DD8, 0x2DDE],
420 [0x2DE0, 0x2DFF],
421 [0x3005, 0x3007],
422 [0x3021, 0x302F],
423 [0x3031, 0x3035],
424 [0x3038, 0x303C],
425 [0x3041, 0x3096],
426 [0x3099, 0x309A],
427 [0x309D, 0x309F],
428 [0x30A1, 0x30FF],
429 [0x3105, 0x312F],
430 [0x3131, 0x3163],
431 [0x3165, 0x318E],
432 [0x31A0, 0x31BF],
433 [0x31F0, 0x31FF],
434 [0x3400, 0x4DBF],
435 [0x4E00, 0xA48C],
436 [0xA4D0, 0xA4FD],
437 [0xA500, 0xA60C],
438 [0xA610, 0xA62B],
439 [0xA640, 0xA66F],
440 [0xA674, 0xA67D],
441 [0xA67F, 0xA6F1],
442 [0xA717, 0xA71F],
443 [0xA722, 0xA788],
444 [0xA78B, 0xA7CA],
445 [0xA7D0, 0xA7D1],
446 [0xA7D3, 0xA7D3],
447 [0xA7D5, 0xA7D9],
448 [0xA7F2, 0xA827],
449 [0xA82C, 0xA82C],
450 [0xA840, 0xA873],
451 [0xA880, 0xA8C5],
452 [0xA8D0, 0xA8D9],
453 [0xA8E0, 0xA8F7],
454 [0xA8FB, 0xA8FB],
455 [0xA8FD, 0xA92D],
456 [0xA930, 0xA953],
457 [0xA960, 0xA97C],
458 [0xA980, 0xA9C0],
459 [0xA9CF, 0xA9D9],
460 [0xA9E0, 0xA9FE],
461 [0xAA00, 0xAA36],
462 [0xAA40, 0xAA4D],
463 [0xAA50, 0xAA59],
464 [0xAA60, 0xAA76],
465 [0xAA7A, 0xAAC2],
466 [0xAADB, 0xAADD],
467 [0xAAE0, 0xAAEF],
468 [0xAAF2, 0xAAF6],
469 [0xAB01, 0xAB06],
470 [0xAB09, 0xAB0E],
471 [0xAB11, 0xAB16],
472 [0xAB20, 0xAB26],
473 [0xAB28, 0xAB2E],
474 [0xAB30, 0xAB5A],
475 [0xAB5C, 0xAB69],
476 [0xAB70, 0xABEA],
477 [0xABEC, 0xABED],
478 [0xABF0, 0xABF9],
479 [0xAC00, 0xD7A3],
480 [0xD7B0, 0xD7C6],
481 [0xD7CB, 0xD7FB],
482 [0xF900, 0xFA6D],
483 [0xFA70, 0xFAD9],
484 [0xFB00, 0xFB06],
485 [0xFB13, 0xFB17],
486 [0xFB1D, 0xFB28],
487 [0xFB2A, 0xFB36],
488 [0xFB38, 0xFB3C],
489 [0xFB3E, 0xFB3E],
490 [0xFB40, 0xFB41],
491 [0xFB43, 0xFB44],
492 [0xFB46, 0xFBB1],
493 [0xFBD3, 0xFC5D],
494 [0xFC64, 0xFD3D],
495 [0xFD50, 0xFD8F],
496 [0xFD92, 0xFDC7],
497 [0xFDF0, 0xFDF9],
498 [0xFE20, 0xFE2F],
499 [0xFE33, 0xFE34],
500 [0xFE4D, 0xFE4F],
501 [0xFE71, 0xFE71],
502 [0xFE73, 0xFE73],
503 [0xFE77, 0xFE77],
504 [0xFE79, 0xFE79],
505 [0xFE7B, 0xFE7B],
506 [0xFE7D, 0xFE7D],
507 [0xFE7F, 0xFEFC],
508 [0xFF10, 0xFF19],
509 [0xFF21, 0xFF3A],
510 [0xFF3F, 0xFF3F],
511 [0xFF41, 0xFF5A],
512 [0xFF65, 0xFF9F],
513 [0xFFA1, 0xFFBE],
514 [0xFFC2, 0xFFC7],
515 [0xFFCA, 0xFFCF],
516 [0xFFD2, 0xFFD7],
517 [0xFFDA, 0xFFDC],
518 [0x10000, 0x1000B],
519 [0x1000D, 0x10026],
520 [0x10028, 0x1003A],
521 [0x1003C, 0x1003D],
522 [0x1003F, 0x1004D],
523 [0x10050, 0x1005D],
524 [0x10080, 0x100FA],
525 [0x10140, 0x10174],
526 [0x101FD, 0x101FD],
527 [0x10280, 0x1029C],
528 [0x102A0, 0x102D0],
529 [0x102E0, 0x102E0],
530 [0x10300, 0x1031F],
531 [0x1032D, 0x1034A],
532 [0x10350, 0x1037A],
533 [0x10380, 0x1039D],
534 [0x103A0, 0x103C3],
535 [0x103C8, 0x103CF],
536 [0x103D1, 0x103D5],
537 [0x10400, 0x1049D],
538 [0x104A0, 0x104A9],
539 [0x104B0, 0x104D3],
540 [0x104D8, 0x104FB],
541 [0x10500, 0x10527],
542 [0x10530, 0x10563],
543 [0x10570, 0x1057A],
544 [0x1057C, 0x1058A],
545 [0x1058C, 0x10592],
546 [0x10594, 0x10595],
547 [0x10597, 0x105A1],
548 [0x105A3, 0x105B1],
549 [0x105B3, 0x105B9],
550 [0x105BB, 0x105BC],
551 [0x10600, 0x10736],
552 [0x10740, 0x10755],
553 [0x10760, 0x10767],
554 [0x10780, 0x10785],
555 [0x10787, 0x107B0],
556 [0x107B2, 0x107BA],
557 [0x10800, 0x10805],
558 [0x10808, 0x10808],
559 [0x1080A, 0x10835],
560 [0x10837, 0x10838],
561 [0x1083C, 0x1083C],
562 [0x1083F, 0x10855],
563 [0x10860, 0x10876],
564 [0x10880, 0x1089E],
565 [0x108E0, 0x108F2],
566 [0x108F4, 0x108F5],
567 [0x10900, 0x10915],
568 [0x10920, 0x10939],
569 [0x10980, 0x109B7],
570 [0x109BE, 0x109BF],
571 [0x10A00, 0x10A03],
572 [0x10A05, 0x10A06],
573 [0x10A0C, 0x10A13],
574 [0x10A15, 0x10A17],
575 [0x10A19, 0x10A35],
576 [0x10A38, 0x10A3A],
577 [0x10A3F, 0x10A3F],
578 [0x10A60, 0x10A7C],
579 [0x10A80, 0x10A9C],
580 [0x10AC0, 0x10AC7],
581 [0x10AC9, 0x10AE6],
582 [0x10B00, 0x10B35],
583 [0x10B40, 0x10B55],
584 [0x10B60, 0x10B72],
585 [0x10B80, 0x10B91],
586 [0x10C00, 0x10C48],
587 [0x10C80, 0x10CB2],
588 [0x10CC0, 0x10CF2],
589 [0x10D00, 0x10D27],
590 [0x10D30, 0x10D39],
591 [0x10E80, 0x10EA9],
592 [0x10EAB, 0x10EAC],
593 [0x10EB0, 0x10EB1],
594 [0x10EFD, 0x10F1C],
595 [0x10F27, 0x10F27],
596 [0x10F30, 0x10F50],
597 [0x10F70, 0x10F85],
598 [0x10FB0, 0x10FC4],
599 [0x10FE0, 0x10FF6],
600 [0x11000, 0x11046],
601 [0x11066, 0x11075],
602 [0x1107F, 0x110BA],
603 [0x110C2, 0x110C2],
604 [0x110D0, 0x110E8],
605 [0x110F0, 0x110F9],
606 [0x11100, 0x11134],
607 [0x11136, 0x1113F],
608 [0x11144, 0x11147],
609 [0x11150, 0x11173],
610 [0x11176, 0x11176],
611 [0x11180, 0x111C4],
612 [0x111C9, 0x111CC],
613 [0x111CE, 0x111DA],
614 [0x111DC, 0x111DC],
615 [0x11200, 0x11211],
616 [0x11213, 0x11237],
617 [0x1123E, 0x11241],
618 [0x11280, 0x11286],
619 [0x11288, 0x11288],
620 [0x1128A, 0x1128D],
621 [0x1128F, 0x1129D],
622 [0x1129F, 0x112A8],
623 [0x112B0, 0x112EA],
624 [0x112F0, 0x112F9],
625 [0x11300, 0x11303],
626 [0x11305, 0x1130C],
627 [0x1130F, 0x11310],
628 [0x11313, 0x11328],
629 [0x1132A, 0x11330],
630 [0x11332, 0x11333],
631 [0x11335, 0x11339],
632 [0x1133B, 0x11344],
633 [0x11347, 0x11348],
634 [0x1134B, 0x1134D],
635 [0x11350, 0x11350],
636 [0x11357, 0x11357],
637 [0x1135D, 0x11363],
638 [0x11366, 0x1136C],
639 [0x11370, 0x11374],
640 [0x11400, 0x1144A],
641 [0x11450, 0x11459],
642 [0x1145E, 0x11461],
643 [0x11480, 0x114C5],
644 [0x114C7, 0x114C7],
645 [0x114D0, 0x114D9],
646 [0x11580, 0x115B5],
647 [0x115B8, 0x115C0],
648 [0x115D8, 0x115DD],
649 [0x11600, 0x11640],
650 [0x11644, 0x11644],
651 [0x11650, 0x11659],
652 [0x11680, 0x116B8],
653 [0x116C0, 0x116C9],
654 [0x11700, 0x1171A],
655 [0x1171D, 0x1172B],
656 [0x11730, 0x11739],
657 [0x11740, 0x11746],
658 [0x11800, 0x1183A],
659 [0x118A0, 0x118E9],
660 [0x118FF, 0x11906],
661 [0x11909, 0x11909],
662 [0x1190C, 0x11913],
663 [0x11915, 0x11916],
664 [0x11918, 0x11935],
665 [0x11937, 0x11938],
666 [0x1193B, 0x11943],
667 [0x11950, 0x11959],
668 [0x119A0, 0x119A7],
669 [0x119AA, 0x119D7],
670 [0x119DA, 0x119E1],
671 [0x119E3, 0x119E4],
672 [0x11A00, 0x11A3E],
673 [0x11A47, 0x11A47],
674 [0x11A50, 0x11A99],
675 [0x11A9D, 0x11A9D],
676 [0x11AB0, 0x11AF8],
677 [0x11C00, 0x11C08],
678 [0x11C0A, 0x11C36],
679 [0x11C38, 0x11C40],
680 [0x11C50, 0x11C59],
681 [0x11C72, 0x11C8F],
682 [0x11C92, 0x11CA7],
683 [0x11CA9, 0x11CB6],
684 [0x11D00, 0x11D06],
685 [0x11D08, 0x11D09],
686 [0x11D0B, 0x11D36],
687 [0x11D3A, 0x11D3A],
688 [0x11D3C, 0x11D3D],
689 [0x11D3F, 0x11D47],
690 [0x11D50, 0x11D59],
691 [0x11D60, 0x11D65],
692 [0x11D67, 0x11D68],
693 [0x11D6A, 0x11D8E],
694 [0x11D90, 0x11D91],
695 [0x11D93, 0x11D98],
696 [0x11DA0, 0x11DA9],
697 [0x11EE0, 0x11EF6],
698 [0x11F00, 0x11F10],
699 [0x11F12, 0x11F3A],
700 [0x11F3E, 0x11F42],
701 [0x11F50, 0x11F59],
702 [0x11FB0, 0x11FB0],
703 [0x12000, 0x12399],
704 [0x12400, 0x1246E],
705 [0x12480, 0x12543],
706 [0x12F90, 0x12FF0],
707 [0x13000, 0x1342F],
708 [0x13440, 0x13455],
709 [0x14400, 0x14646],
710 [0x16800, 0x16A38],
711 [0x16A40, 0x16A5E],
712 [0x16A60, 0x16A69],
713 [0x16A70, 0x16ABE],
714 [0x16AC0, 0x16AC9],
715 [0x16AD0, 0x16AED],
716 [0x16AF0, 0x16AF4],
717 [0x16B00, 0x16B36],
718 [0x16B40, 0x16B43],
719 [0x16B50, 0x16B59],
720 [0x16B63, 0x16B77],
721 [0x16B7D, 0x16B8F],
722 [0x16E40, 0x16E7F],
723 [0x16F00, 0x16F4A],
724 [0x16F4F, 0x16F87],
725 [0x16F8F, 0x16F9F],
726 [0x16FE0, 0x16FE1],
727 [0x16FE3, 0x16FE4],
728 [0x16FF0, 0x16FF1],
729 [0x17000, 0x187F7],
730 [0x18800, 0x18CD5],
731 [0x18D00, 0x18D08],
732 [0x1AFF0, 0x1AFF3],
733 [0x1AFF5, 0x1AFFB],
734 [0x1AFFD, 0x1AFFE],
735 [0x1B000, 0x1B122],
736 [0x1B132, 0x1B132],
737 [0x1B150, 0x1B152],
738 [0x1B155, 0x1B155],
739 [0x1B164, 0x1B167],
740 [0x1B170, 0x1B2FB],
741 [0x1BC00, 0x1BC6A],
742 [0x1BC70, 0x1BC7C],
743 [0x1BC80, 0x1BC88],
744 [0x1BC90, 0x1BC99],
745 [0x1BC9D, 0x1BC9E],
746 [0x1CF00, 0x1CF2D],
747 [0x1CF30, 0x1CF46],
748 [0x1D165, 0x1D169],
749 [0x1D16D, 0x1D172],
750 [0x1D17B, 0x1D182],
751 [0x1D185, 0x1D18B],
752 [0x1D1AA, 0x1D1AD],
753 [0x1D242, 0x1D244],
754 [0x1D400, 0x1D454],
755 [0x1D456, 0x1D49C],
756 [0x1D49E, 0x1D49F],
757 [0x1D4A2, 0x1D4A2],
758 [0x1D4A5, 0x1D4A6],
759 [0x1D4A9, 0x1D4AC],
760 [0x1D4AE, 0x1D4B9],
761 [0x1D4BB, 0x1D4BB],
762 [0x1D4BD, 0x1D4C3],
763 [0x1D4C5, 0x1D505],
764 [0x1D507, 0x1D50A],
765 [0x1D50D, 0x1D514],
766 [0x1D516, 0x1D51C],
767 [0x1D51E, 0x1D539],
768 [0x1D53B, 0x1D53E],
769 [0x1D540, 0x1D544],
770 [0x1D546, 0x1D546],
771 [0x1D54A, 0x1D550],
772 [0x1D552, 0x1D6A5],
773 [0x1D6A8, 0x1D6C0],
774 [0x1D6C2, 0x1D6DA],
775 [0x1D6DC, 0x1D6FA],
776 [0x1D6FC, 0x1D714],
777 [0x1D716, 0x1D734],
778 [0x1D736, 0x1D74E],
779 [0x1D750, 0x1D76E],
780 [0x1D770, 0x1D788],
781 [0x1D78A, 0x1D7A8],
782 [0x1D7AA, 0x1D7C2],
783 [0x1D7C4, 0x1D7CB],
784 [0x1D7CE, 0x1D7FF],
785 [0x1DA00, 0x1DA36],
786 [0x1DA3B, 0x1DA6C],
787 [0x1DA75, 0x1DA75],
788 [0x1DA84, 0x1DA84],
789 [0x1DA9B, 0x1DA9F],
790 [0x1DAA1, 0x1DAAF],
791 [0x1DF00, 0x1DF1E],
792 [0x1DF25, 0x1DF2A],
793 [0x1E000, 0x1E006],
794 [0x1E008, 0x1E018],
795 [0x1E01B, 0x1E021],
796 [0x1E023, 0x1E024],
797 [0x1E026, 0x1E02A],
798 [0x1E030, 0x1E06D],
799 [0x1E08F, 0x1E08F],
800 [0x1E100, 0x1E12C],
801 [0x1E130, 0x1E13D],
802 [0x1E140, 0x1E149],
803 [0x1E14E, 0x1E14E],
804 [0x1E290, 0x1E2AE],
805 [0x1E2C0, 0x1E2F9],
806 [0x1E4D0, 0x1E4F9],
807 [0x1E7E0, 0x1E7E6],
808 [0x1E7E8, 0x1E7EB],
809 [0x1E7ED, 0x1E7EE],
810 [0x1E7F0, 0x1E7FE],
811 [0x1E800, 0x1E8C4],
812 [0x1E8D0, 0x1E8D6],
813 [0x1E900, 0x1E94B],
814 [0x1E950, 0x1E959],
815 [0x1EE00, 0x1EE03],
816 [0x1EE05, 0x1EE1F],
817 [0x1EE21, 0x1EE22],
818 [0x1EE24, 0x1EE24],
819 [0x1EE27, 0x1EE27],
820 [0x1EE29, 0x1EE32],
821 [0x1EE34, 0x1EE37],
822 [0x1EE39, 0x1EE39],
823 [0x1EE3B, 0x1EE3B],
824 [0x1EE42, 0x1EE42],
825 [0x1EE47, 0x1EE47],
826 [0x1EE49, 0x1EE49],
827 [0x1EE4B, 0x1EE4B],
828 [0x1EE4D, 0x1EE4F],
829 [0x1EE51, 0x1EE52],
830 [0x1EE54, 0x1EE54],
831 [0x1EE57, 0x1EE57],
832 [0x1EE59, 0x1EE59],
833 [0x1EE5B, 0x1EE5B],
834 [0x1EE5D, 0x1EE5D],
835 [0x1EE5F, 0x1EE5F],
836 [0x1EE61, 0x1EE62],
837 [0x1EE64, 0x1EE64],
838 [0x1EE67, 0x1EE6A],
839 [0x1EE6C, 0x1EE72],
840 [0x1EE74, 0x1EE77],
841 [0x1EE79, 0x1EE7C],
842 [0x1EE7E, 0x1EE7E],
843 [0x1EE80, 0x1EE89],
844 [0x1EE8B, 0x1EE9B],
845 [0x1EEA1, 0x1EEA3],
846 [0x1EEA5, 0x1EEA9],
847 [0x1EEAB, 0x1EEBB],
848 [0x1FBF0, 0x1FBF9],
849 [0x20000, 0x2A6DF],
850 [0x2A700, 0x2B739],
851 [0x2B740, 0x2B81D],
852 [0x2B820, 0x2CEA1],
853 [0x2CEB0, 0x2EBE0],
854 [0x2EBF0, 0x2EE5D],
855 [0x2F800, 0x2FA1D],
856 [0x30000, 0x3134A],
857 [0x31350, 0x323AF],);
858  
859 # Binary-search the frozen XID_Continue range table.
860 # Caller is responsible for the ASCII fast path; this is the slow path
861 # for non-ASCII codepoints in identifier-character checks.
862 0 ▶sub _is_xid_continue {
Subroutine _is_xid_continue: not called CC=4 SCAR=30.0
863 0 my ($cp) = @_;
864 0 my $lo = 0;
865 0 my $hi = $#XID_CONTINUE_RANGES;
866 0 ▶ while ($lo <= $hi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lo <= $hi) 0 0 0
867 0 my $mid = ($lo + $hi) >> 1;
868 0 my $r = $XID_CONTINUE_RANGES[$mid];
869 0 ▶ if ($cp < $r->[0]) { $hi = $mid - 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($cp < $r->[0]) { } 0 0 0
elsif ($cp > $r->[1]) { } 0 0 0
870 0 elsif ($cp > $r->[1]) { $lo = $mid + 1 }
871 0 else { return 1 }
872 }
873 0 return 0;
874 }
875  
876 2 ▶sub new_table {
Subroutine new_table: called CC=1 SCAR=2.6
Pod undocumented
877 2 require Tie::IxHash;
878 0 tie my %h, 'Tie::IxHash';
879 0 return \%h;
880 }
881  
882 # SPEC §"Unordered tables". Plain hashref blessed into DMS::Parser::UnorderedTable.
883 # Used by parse_table_block / parse_flow_table / parse_list_item_value when
884 # the parser was constructed with ignore_order=true. Iteration order over
885 # the resulting table is arbitrary (Perl hash randomization).
886 0 ▶sub new_unordered_table {
Subroutine new_unordered_table: not called CC=1 SCAR=6.9
Pod undocumented
887 0 my %h;
888 0 return bless \%h, 'DMS::Parser::UnorderedTable';
889 }
890  
891 # Like new_table, but returns a plain (non-tied) hashref plus an
892 # external "insertion-order keys" arrayref. Used in the lite/encoder
893 # fast path where we don't need the round-trip Document tree — just
894 # enough structure for JSON emission. The encoder special-cases this
895 # shape (HASH refs accompanied by an "$order" arrayref).
896 #
897 # We tag the plain hashref with a hidden key holding the keys arrayref
898 # so it round-trips through `$t->{$k} = $v` access patterns: the
899 # encoder extracts the order list from `$t->{"\0_keys"}` if present and
900 # falls back to `keys %$t` otherwise.
901 3 our $ORDER_KEY = "\0_keys";
902 0 ▶sub new_ordered_table {
Subroutine new_ordered_table: not called CC=1 SCAR=6.9
Pod undocumented
903 0 return { $ORDER_KEY => [] };
904 }
905  
906 # Per-indent compiled bulk regex cache for parse_table_block's fast
907 # path. Common indent levels (0, 2, 4, 6, ...) compile once globally;
908 # subsequent encounters reuse the qr// from this cache instead of
909 # recompiling per parse_table_block call.
910 3 our %BULK_RE_CACHE;
911  
912 0 ▶sub _err {
Subroutine _err: not called CC=1 SCAR=6.9
913 0 my ($self, $msg) = @_;
914 0 return "$self->{line}:" . ($self->{pos} - $self->{line_start} + 1) . ": $msg\n";
915 }
916  
917 4 ▶sub _err_at {
Subroutine _err_at: called CC=1 SCAR=0.0
918 4 my ($self, $line, $line_start, $pos, $msg) = @_;
919 4 my $col = $pos - $line_start + 1;
920 4 return "$line:$col: $msg\n";
921 }
922  
923 0 ▶sub _die_at {
Subroutine _die_at: not called CC=1 SCAR=6.9
924 0 my ($self, $line, $line_start, $pos, $msg) = @_;
925 0 die "$line:" . ($pos - $line_start + 1) . ": $msg\n";
926 }
927  
928 0 ▶sub _die {
Subroutine _die: not called CC=1 SCAR=6.9
929 0 my ($self, $msg) = @_;
930 0 die _err($self, $msg);
931 }
932  
933 # SPEC §Decode/Encode (v0.14): canonical entry point. Returns the body
934 # only — meta and comments are dropped. Use decode_document() to keep
935 # them.
936 0 ▶sub decode {
Subroutine decode: not called CC=1 SCAR=6.9
Pod documented
937 0 my ($src) = @_;
938 0 my $doc = decode_document($src);
939 0 return $doc->{body};
940 }
941  
942 # Deprecated alias for decode(). Removed in the next release.
943 # SPEC §Decode/Encode — Migration from the parse/to_dms era.
944 3 { my $warned;
945 0 ▶ sub parse {
Subroutine parse: not called CC=2 SCAR=17.9
Pod undocumented
946 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
947 0 Carp::carp(
948 'DMS::Parser::parse() is deprecated; use decode() instead. '
949 . 'SPEC v0.14 renamed parse() to decode().');
950 }
951 0 goto &decode;
952 }
953 }
954  
955 # SPEC §Parsing modes — full and lite. Lite-mode equivalents return
956 # a Document with empty comments + original_forms.
957 3 ▶sub decode_lite {
Subroutine decode_lite: not called CC=1 SCAR=2.6
Pod documented
958 0 my ($src) = @_;
959 0 return decode_lite_document($src)->{body};
960 }
961  
962 # Deprecated alias for decode_lite(). Removed in the next release.
963 3 { my $warned;
964 0 ▶ sub parse_lite {
Subroutine parse_lite: not called CC=2 SCAR=17.9
Pod undocumented
965 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
966 0 Carp::carp(
967 'DMS::Parser::parse_lite() is deprecated; use decode_lite() instead. '
968 . 'SPEC v0.14 renamed parse_lite() to decode_lite().');
969 }
970 0 goto &decode_lite;
971 }
972 }
973  
974 3 ▶sub decode_lite_document {
Subroutine decode_lite_document: not called CC=2 SCAR=15.1
Pod documented
975 0 my ($src) = @_;
976 # Fast path: try the iterative mega-regex tokenizer for the simple
977 # subset (bareword keys, simple scalar values, nested-table headers,
978 # blank lines, single-line `#` / `//` comments, ASCII-only). Returns
979 # undef on anything it can't handle; we fall back to the full
980 # recursive-descent parser below. The fast path avoids the
981 # parse_table_block recursion and the parse_kvpair / _skip_trivia
982 # method-dispatch frames — pure-Perl method calls are the main
983 # cost on flat configs (kube values.yaml-shaped).
984 0 my $fast = _parse_lite_document_fast(\$src);
985 0 ▶ return $fast if defined $fast;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fast 0 0 0
986 0 return _parse_document_with_mode($src, 1);
987 }
988  
989 # Iterative mega-regex tokenizer + manual stack assembly for the lite
990 # subset. Returns a Document hashref { meta, body, comments,
991 # original_forms } on success, or undef on any pattern the fast path
992 # can't handle (front matter, heredocs, list items, escaped strings,
993 # block comments, complex-key flow forms, non-ASCII strings).
994 # Caller's $src isn't modified; we do a pos() scan via a scalar ref.
995 0 ▶sub _parse_lite_document_fast {
Subroutine _parse_lite_document_fast: not called CC=39 SCAR=73.5
996 0 my ($src_ref) = @_;
997 0 my $len = length($$src_ref);
998  
999 # Pre-flight rejection: a single regex over the whole src checks
1000 # for any opener of a construct the fast path doesn't handle. If
1001 # any are present, return undef immediately so the slow parser
1002 # gets the (correct) full-spec implementation. This costs one
1003 # linear scan but it's bounded by the C regex engine and faster
1004 # than discovering mid-parse that we can't handle something. The
1005 # negative lookaheads for `(?!##)` exclude `### LABEL` block
1006 # comment openers. We deliberately allow `\u`/`\U` Unicode escapes
1007 # but reject other backslash escapes (would need decoding).
1008 0 ▶ return undef if $$src_ref =~ /"""|'''/; # heredocs
Branch: 1 branch
BranchTrueFalseTotal
if $$src_ref =~ /"""|'''/ 0 0 0
1009 0 ▶ return undef if $$src_ref =~ /^[ \t]*\+/m; # list items / front matter
Branch: 1 branch
BranchTrueFalseTotal
if $$src_ref =~ /^[ \t]*\+/m 0 0 0
1010 0 ▶ return undef if $$src_ref =~ /^[ \t]*###/m; # block comment opener
Branch: 1 branch
BranchTrueFalseTotal
if $$src_ref =~ /^[ \t]*###/m 0 0 0
1011 # Note: we don't pre-reject `/*` because real configs sometimes
1012 # have it inside string literals (e.g., `path: "/etc/foo/*.tmpl"`).
1013 # The mega-regex handles strings as a unit so `/*` is consumed
1014 # inside the string capture; the inner loop will only fail on a
1015 # `/*` that appears at line-start as an actual block comment, in
1016 # which case it correctly bails to the slow parser.
1017 # Backslash escapes ARE handled in the string regex below — the
1018 # decode pass after match handles \", \\, \n, \r, \t, \b, \f, \uXXXX,
1019 # \UXXXXXXXX. Anything else with `\` is still rejected.
1020 # Quoted keys, inline tables/lists with content, dates, hex/oct/bin
1021 # numbers — all opt out by being matched as "didn't match the
1022 # mega-regex" inside the loop; the loop returns undef on the
1023 # first non-match.
1024  
1025 # Manual stack of containers, with the indent at which their
1026 # children live. The root has child_indent 0. When a header
1027 # (`key:\n`) arrives, we push the new child table with
1028 # child_indent=undef ("TBD — set by first child"). The pop rule
1029 # is "while top's child_indent > current indent, pop"; this
1030 # closes nested blocks as the indent decreases.
1031 0 my $root = { $ORDER_KEY => [] };
1032 0 my @stack = ({ c => $root, ci => 0 });
1033  
1034 0 pos($$src_ref) = 0;
1035 0 ▶ LINE: while (pos($$src_ref) < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $$src_ref < $len) 0 0 0
1036 # Blank line — most common after kvpairs.
1037 0 ▶ if ($$src_ref =~ /\G[ \t]*\r?\n/gc) { next LINE; }
Branch: 1 branch
BranchTrueFalseTotal
if ($$src_ref =~ /\G[ \t]*\r?\n/cg) 0 0 0
1038 # Single-line `#` or `//` comment (block forms `###` / `/*`
1039 # already pre-rejected).
1040 0 ▶ if ($$src_ref =~ /\G[ \t]*(?:#|\/\/)[^\n\r]*\r?\n/gc) { next LINE; }
Branch: 1 branch
BranchTrueFalseTotal
if ($$src_ref =~ m[\G[ \t]*(?:#|//)[^\n\r]*\r?\n]cg) 0 0 0
1041  
1042 # Mega-match: kvpair with simple value OR nested-block header.
1043 # Group layout (capturing only — non-capturing alternations
1044 # don't shift indices):
1045 # $1 = indent (spaces)
1046 # $2 = bareword key
1047 # $3 = positive integer
1048 # $4 = negative integer
1049 # $5 = bool ('true'/'false')
1050 # $6 = basic-string content (escapes allowed; decoded after)
1051 # $7 = empty list / empty table literal ('[]' or '{}')
1052 # $8 = decimal float (no exponent)
1053 # $9 = flow-list-of-simple-values content (between [ and ],
1054 # no nested brackets, no embedded newlines)
1055 # $10 = flow-table-of-simple-kvpairs content
1056 # $11 = trailing '\r?\n' for the no-value (header) form
1057 0 ▶ if ($$src_ref =~ /\G([ ]*)([A-Za-z_][A-Za-z0-9_-]*):(?:[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"((?:[\x20\x21\x23-\x5b\x5d-\x7e]|\\(?:["\\nrtbf]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}))*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+)|\[([^\[\]\n\r]+)\]|\{([^\{\}\n\r]+)\})\r?\n|(\r?\n))/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$src_ref =~ /\G([ ]*)([A-Za-z_][A-Za-z0-9_-]*):(?:[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"((?:[\x20\x21\x23-\x5b\x5d-\x7e]|\\(?:["\\nrtbf]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}))*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+)|\[([^\[\]\n\r]+)\]|\{([^\{\}\n\r]+)\})\r?\n|(\r?\n))/cg) 0 0 0
1058 0 my $ind = length($1);
1059 0 my $key = $2;
1060 # Pop closed levels (top's children no longer reachable).
1061 0 ▶ while (@stack > 1 && defined($stack[-1]{ci}) && $stack[-1]{ci} > $ind) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack > 1 and defined $stack[-1]{"ci"} and $stack[-1]{"ci"} > $ind) 0 0 0
Condition0%0/6
@stack > 1 and defined $stack[-1]{"ci"} and $stack[-1]{"ci"} > $ind
!ll&&!rl&&r
000
@stack > 1 and defined $stack[-1]{"ci"}
!ll&&!rl&&r
000
MC/DC0%0/3
@stack > 1 and defined $stack[-1]{"ci"} and $stack[-1]{"ci"} > $ind
@stack > 1 defined $stack[-1]{"ci"} $stack[-1]{"ci"} > $ind
Truth table0%0/4
A and B and C
A= @stack > 1B= defined $stack[-1]{"ci"}C= $stack[-1]{"ci"} > $ind
ABCresult
0XX0
10X0
1100
1111
1062 0 pop @stack;
1063 }
1064 # First child of a header? Its indent fixes the parent's
1065 # child_indent.
1066 0 ▶ if (!defined $stack[-1]{ci}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stack[-1]{"ci"}) 0 0 0
1067 # The new indent must be strictly greater than the
1068 # header's parent's child_indent (i.e., we descended).
1069 0 ▶ if (@stack >= 2 && $stack[-2]{ci} >= $ind) { return undef; }
Branch: 1 branch
BranchTrueFalseTotal
if (@stack >= 2 and $stack[-2]{"ci"} >= $ind) 0 0 0
Condition0%0/3
@stack >= 2 and $stack[-2]{"ci"} >= $ind
!ll&&!rl&&r
000
MC/DC0%0/2
@stack >= 2 and $stack[-2]{"ci"} >= $ind
@stack >= 2 $stack[-2]{"ci"} >= $ind
Truth table0%0/3
A and B
A= @stack >= 2B= $stack[-2]{"ci"} >= $ind
ABresult
0X0
100
111
1070 0 $stack[-1]{ci} = $ind;
1071 }
1072 # Indent must match the current container's expected level.
1073 0 ▶ return undef if $stack[-1]{ci} != $ind;
Branch: 1 branch
BranchTrueFalseTotal
if $stack[-1]{"ci"} != $ind 0 0 0
1074 0 my $container = $stack[-1]{c};
1075 0 ▶ return undef if exists $container->{$key}; # duplicate key
Branch: 1 branch
BranchTrueFalseTotal
if exists $container->{$key} 0 0 0
1076  
1077 0 ▶ if (defined $11) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $11) { } 0 0 0
1078 # Nested-block header: child is a table (the fast path
1079 # doesn't handle child-as-list; pre-flight rejects any
1080 # `+` so this is safe).
1081 0 my $child = { $ORDER_KEY => [] };
1082 0 push @{$container->{$ORDER_KEY}}, $key;
1083 0 $container->{$key} = $child;
1084 0 push @stack, { c => $child, ci => undef };
1085 } else {
1086 0 my $val;
1087 0 ▶ if (defined $3) { my $iv = 0+$3; $val = bless \$iv, 'DMS::Parser::Integer'; }
Branch: 7 branches
BranchTrueFalseTotal
if (defined $3) { } 0 0 0
elsif (defined $4) { } 0 0 0
elsif (defined $5) { } 0 0 0
elsif (defined $6) { } 0 0 0
elsif (defined $7) { } 0 0 0
elsif (defined $8) { } 0 0 0
elsif (defined $9) { } 0 0 0
1088 0 elsif (defined $4) { my $iv = 0+$4; $val = bless \$iv, 'DMS::Parser::Integer'; }
1089 0 ▶ elsif (defined $5) { my $bv = $5 eq 'true' ? 1 : 0; $val = bless \$bv, 'DMS::Parser::Bool'; }
Branch: 1 branch
BranchTrueFalseTotal
$5 eq 'true' ? : 0 0 0
1090 elsif (defined $6) {
1091 0 $val = $6;
1092 # Decode escapes only if any backslash present (the
1093 # common case is clean ASCII strings — skip the
1094 # substitution then).
1095 0 ▶ if (index($val, '\\') >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($val, "\\") != -1) 0 0 0
1096 0 $val =~ s{\\(["\\nrtbf])}{
1097 0 ▶ $1 eq 'n' ? "\n"
Branch: 5 branches
BranchTrueFalseTotal
$1 eq 'n' ? : 0 0 0
$1 eq 't' ? : 0 0 0
$1 eq 'r' ? : 0 0 0
$1 eq 'b' ? : 0 0 0
$1 eq 'f' ? : 0 0 0
1098 : $1 eq 't' ? "\t"
1099 : $1 eq 'r' ? "\r"
1100 : $1 eq 'b' ? "\b"
1101 : $1 eq 'f' ? "\f"
1102 : $1
1103 }ge;
1104 0 $val =~ s{\\u([0-9A-Fa-f]{4})}{chr(hex($1))}ge;
1105 0 $val =~ s{\\U([0-9A-Fa-f]{8})}{chr(hex($1))}ge;
1106 }
1107 }
1108 0 ▶ elsif (defined $7) { $val = $7 eq '[]' ? [] : { $ORDER_KEY => [] }; }
Branch: 1 branch
BranchTrueFalseTotal
$7 eq '[]' ? : 0 0 0
1109 0 elsif (defined $8) { my $fv = 0+$8; $val = bless \$fv, 'DMS::Parser::Float'; }
1110 elsif (defined $9) {
1111 # Flow-list with content (no nested brackets / newlines).
1112 # Try to parse inner content as a comma-separated
1113 # list of simple values. Bail to slow path if any
1114 # value isn't a clean leaf.
1115 0 my $inner = $9;
1116 0 my @items;
1117 # Split by ',' but allow whitespace.
1118 0 for my $raw (split /\s*,\s*/, $inner) {
1119 0 ▶ next if $raw eq ''; # trailing comma → empty trailing field
Branch: 1 branch
BranchTrueFalseTotal
if $raw eq "" 0 0 0
1120 0 ▶ if ($raw =~ /^(0|[1-9][0-9]{0,17})$/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($raw =~ /^(0|[1-9][0-9]{0,17})$/) { } 0 0 0
elsif ($raw =~ /^-[1-9][0-9]{0,17}$/) { } 0 0 0
elsif ($raw eq 'true') { } 0 0 0
elsif ($raw eq 'false') { } 0 0 0
elsif ($raw =~ /^"([\x20\x21\x23-\x5b\x5d-\x7e]*)"$/) { } 0 0 0
1121 0 my $iv = 0+$raw; push @items, bless \$iv, 'DMS::Parser::Integer';
1122 } elsif ($raw =~ /^-[1-9][0-9]{0,17}$/) {
1123 0 my $iv = 0+$raw; push @items, bless \$iv, 'DMS::Parser::Integer';
1124 } elsif ($raw eq 'true') {
1125 0 my $bv = 1; push @items, bless \$bv, 'DMS::Parser::Bool';
1126 } elsif ($raw eq 'false') {
1127 0 my $bv = 0; push @items, bless \$bv, 'DMS::Parser::Bool';
1128 } elsif ($raw =~ /^"([\x20\x21\x23-\x5b\x5d-\x7e]*)"$/) {
1129 0 push @items, $1; # ASCII-clean string, no escapes
1130 } else {
1131 0 return undef; # complex flow content — fall back
1132 }
1133 }
1134 0 $val = \@items;
1135 }
1136 else {
1137 # $10: flow-table — fall back for now (rare; would
1138 # need split on `,` and inner `key: value` parsing).
1139 0 return undef;
1140 }
1141 0 push @{$container->{$ORDER_KEY}}, $key;
1142 0 $container->{$key} = $val;
1143 }
1144 0 next LINE;
1145 }
1146  
1147 # Anything else: bail out, slow parser owns it.
1148 0 return undef;
1149 }
1150  
1151 # Successful walk — return Document shape. comments/original_forms
1152 # are empty by definition (we rejected anything that could carry
1153 # them).
1154 return {
1155 0 meta => undef,
1156 body => $root,
1157 comments => [],
1158 original_forms => [],
1159 };
1160 }
1161  
1162 # SPEC §"Unordered tables" — opt-in. Body tables are produced as
1163 # DMS::Parser::UnorderedTable (plain Perl hashes, no insertion-order tracking).
1164 # Front matter remains ordered (per spec — meta is small and used by
1165 # tooling that benefits from stable order). Documents from these entry
1166 # points cannot round-trip via `encode` (full mode); use `encode_lite`
1167 # instead. `decode_document_unordered` is full-mode (comments AST +
1168 # original_forms still recorded); `decode_lite_document_unordered` is
1169 # the (unordered, lite) combo — fastest read-only path.
1170 0 ▶sub decode_document_unordered {
Subroutine decode_document_unordered: not called CC=1 SCAR=6.9
Pod undocumented
1171 0 my ($src) = @_;
1172 0 return _parse_document_with_mode($src, 0, 1);
1173 }
1174 0 ▶sub decode_lite_document_unordered {
Subroutine decode_lite_document_unordered: not called CC=1 SCAR=6.9
Pod undocumented
1175 0 my ($src) = @_;
1176 0 return _parse_document_with_mode($src, 1, 1);
1177 }
1178  
1179 # Deprecated aliases. Removed in the next release.
1180 3 { my $warned;
1181 0 ▶ sub parse_document_unordered {
Subroutine parse_document_unordered: not called CC=2 SCAR=17.9
Pod undocumented
1182 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
1183 0 Carp::carp(
1184 'DMS::Parser::parse_document_unordered() is deprecated; '
1185 . 'use decode_document_unordered() instead. '
1186 . 'SPEC v0.14 renamed parse_*() to decode_*().');
1187 }
1188 0 goto &decode_document_unordered;
1189 }
1190 }
1191 3 { my $warned;
1192 0 ▶ sub parse_lite_document_unordered {
Subroutine parse_lite_document_unordered: not called CC=2 SCAR=17.9
Pod undocumented
1193 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
1194 0 Carp::carp(
1195 'DMS::Parser::parse_lite_document_unordered() is deprecated; '
1196 . 'use decode_lite_document_unordered() instead. '
1197 . 'SPEC v0.14 renamed parse_*() to decode_*().');
1198 }
1199 0 goto &decode_lite_document_unordered;
1200 }
1201 }
1202  
1203 # Re-emit a parsed Document as DMS source. See SPEC §encode.
1204 3 ▶sub encode {
Subroutine encode: not called CC=1 SCAR=3.5
Pod undocumented
1205 0 my ($doc) = @_;
1206 0 require DMS::Parser::Emitter;
1207 0 return DMS::Parser::Emitter::encode($doc);
1208 }
1209  
1210 # Lite-mode emit: canonical DMS source — no comments, decimal integers,
1211 # basic-quoted strings — ignoring any comments / original_forms in $doc.
1212 # `decode(encode_lite($doc))` is data-equivalent to $doc; round-trip of
1213 # comment + literal-form is *not* preserved. SPEC §encode.
1214 0 ▶sub encode_lite {
Subroutine encode_lite: not called CC=1 SCAR=6.9
Pod undocumented
1215 0 my ($doc) = @_;
1216 0 require DMS::Parser::Emitter;
1217 0 return DMS::Parser::Emitter::encode_lite($doc);
1218 }
1219  
1220 # Deprecated aliases for encode/encode_lite. Removed in the next release.
1221 3 { my $warned;
1222 0 ▶ sub to_dms {
Subroutine to_dms: not called CC=2 SCAR=17.9
Pod undocumented
1223 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
1224 0 Carp::carp(
1225 'DMS::Parser::to_dms() is deprecated; use encode() instead. '
1226 . 'SPEC v0.14 renamed to_dms() to encode().');
1227 }
1228 0 goto &encode;
1229 }
1230 }
1231 3 { my $warned;
1232 0 ▶ sub to_dms_lite {
Subroutine to_dms_lite: not called CC=2 SCAR=17.9
Pod undocumented
1233 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
1234 0 Carp::carp(
1235 'DMS::Parser::to_dms_lite() is deprecated; use encode_lite() instead. '
1236 . 'SPEC v0.14 renamed to_dms_lite() to encode_lite().');
1237 }
1238 0 goto &encode_lite;
1239 }
1240 }
1241  
1242 3 ▶sub decode_document {
Subroutine decode_document: called CC=1 SCAR=0.0
Pod documented
1243 2 my ($src) = @_;
1244 2 return _parse_document_with_mode($src, 0, 0);
1245 }
1246  
1247 # Deprecated alias for decode_document(). Removed in the next release.
1248 3 { my $warned;
1249 0 ▶ sub parse_document {
Subroutine parse_document: not called CC=2 SCAR=17.9
Pod undocumented
1250 0 ▶ unless ($warned++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($warned++) 0 0 0
1251 0 Carp::carp(
1252 'DMS::Parser::parse_document() is deprecated; use decode_document() instead. '
1253 . 'SPEC v0.14 renamed parse_document() to decode_document().');
1254 }
1255 0 goto &decode_document;
1256 }
1257 }
1258  
1259 # SPEC §"UTF-8 only": reject any non-strict UTF-8 byte sequence —
1260 # overlongs, lone continuation bytes, 5/6-byte forms, codepoints above
1261 # U+10FFFF, and surrogates encoded as 3-byte UTF-8. Perl's built-in
1262 # `utf8::decode` is too lax (it accepts the legacy "extended UTF-8"
1263 # encoding for code points up to 2^31), so we walk the bytes ourselves
1264 # before any decoding.
1265 3 ▶sub _validate_strict_utf8 {
Subroutine _validate_strict_utf8: called CC=16 SCAR=54.3
1266 13 my ($s) = @_;
1267 # Fast path: pure-ASCII source has no UTF-8 work to do. A single
1268 # regex hit returns immediately on flat-ASCII data — saves ~150ms.
1269 13 ▶ return if $s !~ /[\x80-\xFF]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /[\x80-\xFF]/ 13 0 13
1270 0 my $n = length($s);
1271 0 my $i = 0;
1272 0 ▶ while ($i < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 0 0 0
1273 0 my $b0 = ord(substr($s, $i, 1));
1274 0 ▶ if ($b0 < 0x80) { $i++; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($b0 < 128) 0 0 0
1275 0 my ($expect, $cp_lo, $cp_hi);
1276 0 ▶ if (($b0 & 0xE0) == 0xC0) {
Branch: 3 branches
BranchTrueFalseTotal
if (($b0 & 224) == 192) { } 0 0 0
elsif (($b0 & 240) == 224) { } 0 0 0
elsif (($b0 & 248) == 240) { } 0 0 0
1277 0 ▶ return _utf8_die($s, $i) if $b0 < 0xC2; # overlong
Branch: 1 branch
BranchTrueFalseTotal
if $b0 < 194 0 0 0
1278 0 $expect = 2; $cp_lo = 0x80; $cp_hi = 0x7FF;
1279 } elsif (($b0 & 0xF0) == 0xE0) {
1280 0 $expect = 3; $cp_lo = 0x800; $cp_hi = 0xFFFF;
1281 } elsif (($b0 & 0xF8) == 0xF0) {
1282 0 ▶ return _utf8_die($s, $i) if $b0 > 0xF4; # > U+10FFFF
Branch: 1 branch
BranchTrueFalseTotal
if $b0 > 244 0 0 0
1283 0 $expect = 4; $cp_lo = 0x10000; $cp_hi = 0x10FFFF;
1284 } else {
1285 0 return _utf8_die($s, $i); # bare cont / 5-6 byte
1286 }
1287 0 ▶ return _utf8_die($s, $i) if $i + $expect > $n;
Branch: 1 branch
BranchTrueFalseTotal
if $i + $expect > $n 0 0 0
1288 0 my $cp = ($b0 & ((1 << (7 - $expect)) - 1));
1289 0 ▶ for (my $k = 1; $k < $expect; $k++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $expect) 0 0 0
1290 0 my $bk = ord(substr($s, $i + $k, 1));
1291 0 ▶ return _utf8_die($s, $i) if ($bk & 0xC0) != 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if ($bk & 192) != 128 0 0 0
1292 0 $cp = ($cp << 6) | ($bk & 0x3F);
1293 }
1294 0 ▶ return _utf8_die($s, $i) if $cp < $cp_lo || $cp > $cp_hi;
Branch: 1 branch
BranchTrueFalseTotal
if $cp < $cp_lo or $cp > $cp_hi 0 0 0
Condition0%0/3
$cp < $cp_lo or $cp > $cp_hi
l!l&&r!l&&!r
000
MC/DC0%0/2
$cp < $cp_lo or $cp > $cp_hi
$cp < $cp_lo $cp > $cp_hi
Truth table0%0/3
A or B
A= $cp < $cp_loB= $cp > $cp_hi
ABresult
1X1
011
000
1295 0 ▶ return _utf8_die($s, $i) if $cp >= 0xD800 && $cp <= 0xDFFF;
Branch: 1 branch
BranchTrueFalseTotal
if $cp >= 55296 and $cp <= 57343 0 0 0
Condition0%0/3
$cp >= 55296 and $cp <= 57343
!ll&&!rl&&r
000
MC/DC0%0/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296 $cp <= 57343
Truth table0%0/3
A and B
A= $cp >= 55296B= $cp <= 57343
ABresult
0X0
100
111
1296 0 $i += $expect;
1297 }
1298 }
1299  
1300 0 ▶sub _utf8_die {
Subroutine _utf8_die: not called CC=1 SCAR=6.9
1301 0 my ($s, $i) = @_;
1302 0 my $prefix = substr($s, 0, $i);
1303 0 my $line = 1 + ($prefix =~ tr/\n//);
1304 0 my $last_nl = rindex($prefix, "\n");
1305 0 my $col = $i - ($last_nl + 1) + 1;
1306 0 die "$line:$col: input is not valid UTF-8\n";
1307 }
1308  
1309 # Shared input-normalization for every public decode entry point.
1310 # SPEC §"UTF-8 only, NFC-normalized": reject BOM at offset 0, reject
1311 # malformed UTF-8 bytes (5/6-byte forms, > U+10FFFF, lone continuation
1312 # bytes, overlongs, surrogates), reject U+0000 anywhere, then NFC the
1313 # source. Returns the (possibly NFC'd) Perl-internal-encoded string.
1314 13 ▶sub _normalize_source {
Subroutine _normalize_source: called CC=10 SCAR=28.7
1315 13 my ($src) = @_;
1316 # SPEC §"UTF-8 only, NFC-normalized": DMS source is plain UTF-8 with
1317 # no byte-order mark. A leading U+FEFF is not silently consumed —
1318 # reject it explicitly so encoding mistakes surface loudly. (BOMs
1319 # *inside* string/heredoc bodies are fine; this only fires at offset 0.)
1320 # We check for the raw UTF-8 BOM bytes (EF BB BF) before any decoding,
1321 # so the rejection is independent of how the caller passed `$src`.
1322 13 ▶ if (!utf8::is_utf8($src) && length($src) >= 3
Branch: 1 branch
BranchTrueFalseTotal
if (not utf8::is_utf8($src) and length $src >= 3 and substr($src, 0, 3) eq "\357\273\277") 0 13 13
Condition66%4/6
not utf8::is_utf8($src) and length $src >= 3 and substr($src, 0, 3) eq "\357\273\277"
!ll&&!rl&&r
1120
not utf8::is_utf8($src) and length $src >= 3
!ll&&!rl&&r
0112
MC/DC0%0/3
not utf8::is_utf8($src) and length $src >= 3 and substr($src, 0, 3) eq "\357\273\277"
not utf8::is_utf8($src) length $src >= 3 substr($src, 0, 3) eq "\357\273\277"
Truth table50%2/4
not(A) and B and C
A= not utf8::is_utf8($src)B= length $src >= 3C= substr($src, 0, 3) eq "\357\273\277"
ABCresult
0XX0
10X0
1100
1111
1323 && substr($src, 0, 3) eq "\xEF\xBB\xBF") {
1324 0 die "1:1: BOM (U+FEFF) at file start is not allowed; DMS source is plain UTF-8\n";
1325 }
1326 # SPEC §"UTF-8 only": reject malformed UTF-8 bytes (codepoints
1327 # > U+10FFFF, lone continuation bytes, overlongs, surrogates encoded
1328 # as bytes). Perl's `utf8::decode` is permissive about 5/6-byte
1329 # forms and codepoints above U+10FFFF, so we additionally walk the
1330 # raw bytes to confirm strict UTF-8 conformance.
1331 13 ▶ if (!utf8::is_utf8($src)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (utf8::is_utf8($src)) 13 0 13
1332 13 _validate_strict_utf8($src);
1333 13 my $copy = $src;
1334 13 ▶ if (!utf8::decode($copy)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (utf8::decode($copy)) 0 13 13
1335 0 die "1:1: input is not valid UTF-8\n";
1336 }
1337 13 $src = $copy;
1338 }
1339 13 ▶ if (length($src) >= 1 && substr($src, 0, 1) eq "\x{FEFF}") {
Branch: 1 branch
BranchTrueFalseTotal
if (length $src >= 1 and substr($src, 0, 1) eq "\x{feff}") 0 13 13
Condition66%2/3
length $src >= 1 and substr($src, 0, 1) eq "\x{feff}"
!ll&&!rl&&r
1120
MC/DC0%0/2
length $src >= 1 and substr($src, 0, 1) eq "\x{feff}"
length $src >= 1 substr($src, 0, 1) eq "\x{feff}"
Truth table66%2/3
A and B
A= length $src >= 1B= substr($src, 0, 1) eq "\x{feff}"
ABresult
0X0
100
111
1340 0 die "1:1: BOM (U+FEFF) at file start is not allowed; DMS source is plain UTF-8\n";
1341 }
1342 # U+0000 is not allowed anywhere in DMS source (see SPEC §Strings).
1343 13 ▶ if ((my $nul = index($src, "\0")) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $nul = index($src, "\0")) >= 0) 0 13 13
1344 0 my $prefix = substr($src, 0, $nul);
1345 0 my $line = 1 + ($prefix =~ tr/\n//);
1346 0 my $last_nl = rindex($prefix, "\n");
1347 0 my $col = $nul - ($last_nl + 1) + 1;
1348 0 die "$line:$col: U+0000 (NUL) is not allowed in DMS source\n";
1349 }
1350 # SPEC §Unicode normalization: NFC the source before tokenization.
1351 # Fast path: pure-ASCII source is already in NFC; skip the (linear,
1352 # codepoint-walking) NFC pass entirely. The check itself is a single
1353 # regex that finds the first non-ASCII byte if any.
1354 13 ▶ $src = _NFC($src) if $src =~ /[^\x00-\x7F]/;
Branch: 1 branch
BranchTrueFalseTotal
if $src =~ /[^\x00-\x7F]/ 0 13 13
1355 13 return $src;
1356 }
1357  
1358 # SPEC §Front-matter-only decode. Decodes the leading `+++ ... +++`
1359 # block (if any) and returns it as a hashref, then stops without
1360 # tokenizing the body. Returns undef when the document has no front
1361 # matter at all (no opening `+++` after trivia). An empty front matter
1362 # (`+++\n+++\n`) returns a defined-but-empty hashref, distinguishable
1363 # from undef.
1364 #
1365 # Operates in lite mode (no comment AST, no original_forms recorded
1366 # inside the FM). Diagnostics inside the `+++ ... +++` block are
1367 # byte-identical to a full decode.
1368 11 ▶sub decode_front_matter {
Subroutine decode_front_matter: called CC=1 SCAR=0.0
Pod documented
1369 11 my ($src) = @_;
1370 11 $src = _normalize_source($src);
1371 11 my $self = bless {
1372 src => $src,
1373 len => length($src),
1374 pos => 0,
1375 line => 1,
1376 line_start => 0,
1377 pending_leading => [],
1378 path => [],
1379 comments => [],
1380 original_forms => [],
1381 record_forms => 1,
1382 # SPEC §Front-matter-only decode: "Mode: front-matter-only
1383 # decode runs in lite mode."
1384 lite => 1,
1385 # FM is always ordered (SPEC §"Unordered tables"); ignore_order
1386 # only affects body tables, which we never reach.
1387 ignore_order => 0,
1388 }, __PACKAGE__;
1389 11 return $self->parse_front_matter;
1390 }
1391  
1392 2 ▶sub _parse_document_with_mode {
Subroutine _parse_document_with_mode: called CC=2 SCAR=7.1
1393 2 my ($src, $lite, $ignore_order) = @_;
1394 2 ▶ $ignore_order = 0 unless $ignore_order;
Branch: 1 branch
BranchTrueFalseTotal
unless $ignore_order 2 0 2
1395 2 $src = _normalize_source($src);
1396 2 my $self = bless {
1397 src => $src,
1398 len => length($src),
1399 pos => 0,
1400 line => 1,
1401 line_start => 0,
1402 # Comment-AST state. `pending_leading` accumulates full-line
1403 # comments seen by `_skip_trivia`; on the next sibling-entry
1404 # they're flushed as Leading on its breadcrumb, on a blank line
1405 # gap or end-of-block they're flushed as Floating on the current
1406 # path. `path` is the breadcrumb stack for the value currently
1407 # being parsed (strings for table keys; DMS::Parser::Index for list
1408 # indices). `comments` is the accumulator returned to the caller.
1409 pending_leading => [],
1410 path => [],
1411 comments => [],
1412 # Original-literal records for to_dms round-trip. Sparse: only
1413 # nodes whose surface form differs from the emitter's default
1414 # (decimal-no-underscores for ints, basic-quoted for strings)
1415 # get an entry. See SPEC §to_dms.
1416 original_forms => [],
1417 # When false, integer/string lexeme recording is suppressed.
1418 # Used inside key parses and inside heredoc modifier args.
1419 record_forms => 1,
1420 # Lite mode: skip comment-AST + original_forms bookkeeping.
1421 # Same grammar, same errors.
1422 lite => $lite,
1423 # Unordered mode: when true, body tables are produced as
1424 # DMS::Parser::UnorderedTable (plain Perl hashes) instead of Tie::IxHash
1425 # tied tables. Front-matter parsing ignores this flag — meta
1426 # stays ordered. See SPEC §"Unordered tables".
1427 ignore_order => $ignore_order,
1428 }, __PACKAGE__;
1429 2 my $meta = $self->parse_front_matter;
1430 2 my $body = $self->parse_body;
1431 return {
1432 meta => $meta,
1433 body => $body,
1434 comments => $self->{comments},
1435 original_forms => $self->{original_forms},
1436 0 };
1437 }
1438  
1439 # Append an OriginalLiteral record at the current path. Skipped when
1440 # record_forms is false or when in lite mode.
1441 0 ▶sub _record_form {
Subroutine _record_form: not called CC=3 SCAR=24.8
1442 0 my ($self, $lit) = @_;
1443 0 ▶ return if $self->{lite} || !$self->{record_forms};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lite"} or not $self->{"record_forms"} 0 0 0
Condition0%0/3
$self->{"lite"} or not $self->{"record_forms"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"lite"} or not $self->{"record_forms"}
$self->{"lite"} not $self->{"record_forms"}
Truth table0%0/3
A or not(B)
A= $self->{"lite"}B= not $self->{"record_forms"}
ABresult
1X1
011
000
1444 0 push @{$self->{original_forms}}, [ [@{$self->{path}}], $lit ];
1445 }
1446  
1447 213 ▶sub _peek {
Subroutine _peek: called CC=2 SCAR=7.1
1448 213 my $self = shift;
1449 213 ▶ return undef if $self->{pos} >= $self->{len};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} >= $self->{"len"} 0 213 213
1450 213 return substr($self->{src}, $self->{pos}, 1);
1451 }
1452  
1453 0 ▶sub _peek_at {
Subroutine _peek_at: not called CC=2 SCAR=17.9
1454 0 my ($self, $off) = @_;
1455 0 my $p = $self->{pos} + $off;
1456 0 ▶ return undef if $p >= $self->{len};
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $self->{"len"} 0 0 0
1457 0 return substr($self->{src}, $p, 1);
1458 }
1459  
1460 3 ▶sub _starts_with {
Subroutine _starts_with: called CC=1 SCAR=0.0
1461 3 my ($self, $s) = @_;
1462 3 return substr($self->{src}, $self->{pos}, length($s)) eq $s;
1463 }
1464  
1465 0 ▶sub _bump {
Subroutine _bump: not called CC=2 SCAR=17.9
1466 0 my $self = shift;
1467 0 ▶ return undef if $self->{pos} >= $self->{len};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} >= $self->{"len"} 0 0 0
1468 0 my $c = substr($self->{src}, $self->{pos}, 1);
1469 0 $self->{pos}++;
1470 0 return $c;
1471 }
1472  
1473 36 ▶sub _eof { return $_[0]{pos} >= $_[0]{len} }
Subroutine _eof: called CC=1 SCAR=0.0
1474  
1475 28 ▶sub _advance_line {
Subroutine _advance_line: called CC=1 SCAR=0.0
1476 28 my $self = shift;
1477 28 $self->{line}++;
1478 28 $self->{line_start} = $self->{pos};
1479 }
1480  
1481 69 ▶sub _is_bare_key_char {
Subroutine _is_bare_key_char: called CC=3 SCAR=11.8
1482 69 my ($c) = @_;
1483 69 ▶ return 1 if $c eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "-" 0 69 69
1484 69 my $o = ord($c);
1485 69 ▶ if ($o < 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o < 128) 69 0 69
1486 69 return $c =~ /[A-Za-z0-9_]/;
1487 }
1488 # Frozen Unicode 15.1 XID_Continue snapshot - see @XID_CONTINUE_RANGES.
1489 0 return _is_xid_continue($o);
1490 }
1491  
1492 0 ▶sub _is_label_start {
Subroutine _is_label_start: not called CC=3 SCAR=24.8
1493 0 my ($c) = @_;
1494 0 ▶ return defined($c) && ($c eq '_' || $c =~ /[A-Za-z]/);
Condition0%0/6
defined $c && ($c eq '_' || $c =~ /[A-Za-z]/)
!ll&&!rl&&r
000
$c eq "_" or $c =~ /[A-Za-z]/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c && ($c eq '_' || $c =~ /[A-Za-z]/)
defined $c $c eq "_" $c =~ /[A-Za-z]/
Truth table0%0/4
A && B or C
A= defined $cB= $c eq "_"C= $c =~ /[A-Za-z]/
ABCresult
0XX0
1000
11X1
1011
1495 }
1496  
1497 0 ▶sub _is_label_cont {
Subroutine _is_label_cont: not called CC=3 SCAR=24.8
1498 0 my ($c) = @_;
1499 0 ▶ return defined($c) && ($c eq '_' || $c =~ /[A-Za-z0-9]/);
Condition0%0/6
defined $c && ($c eq '_' || $c =~ /[A-Za-z0-9]/)
!ll&&!rl&&r
000
$c eq "_" or $c =~ /[A-Za-z0-9]/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c && ($c eq '_' || $c =~ /[A-Za-z0-9]/)
defined $c $c eq "_" $c =~ /[A-Za-z0-9]/
Truth table0%0/4
A && B or C
A= defined $cB= $c eq "_"C= $c =~ /[A-Za-z0-9]/
ABCresult
0XX0
1000
11X1
1011
1500 }
1501  
1502 0 ▶sub _looks_like_date_prefix {
Subroutine _looks_like_date_prefix: not called CC=2 SCAR=17.9
1503 0 my ($s) = @_;
1504 0 ▶ return 0 if length($s) < 10;
Branch: 1 branch
BranchTrueFalseTotal
if length $s < 10 0 0 0
1505 0 return $s =~ /^\d\d\d\d-\d\d-\d\d/;
1506 }
1507  
1508 0 ▶sub _looks_like_time_prefix {
Subroutine _looks_like_time_prefix: not called CC=2 SCAR=17.9
1509 0 my ($s) = @_;
1510 0 ▶ return 0 if length($s) < 8;
Branch: 1 branch
BranchTrueFalseTotal
if length $s < 8 0 0 0
1511 0 return $s =~ /^\d\d:\d\d:\d\d/;
1512 }
1513  
1514 3 my %TERMINATORS = map { $_ => 1 } (' ', "\t", "\n", "\r", '#', '/', ',', ']', '}');
1515 0 ▶sub _is_value_terminator {
Subroutine _is_value_terminator: not called CC=2 SCAR=17.9
1516 0 my ($c) = @_;
1517 0 ▶ return 1 if !defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
1518 0 return exists $TERMINATORS{$c};
1519 }
1520  
1521 # SPEC §Lexical "Reserved decorator sigils": the seventeen characters
1522 # below are reserved as decorator sigils at line-start position. A body
1523 # line whose first non-whitespace character is one of these is a tier-0
1524 # parse error. Underscore is *not* in this set — it has its own role
1525 # for core / built-in decorators (e.g. heredoc modifiers `_trim`).
1526 # The reservation only applies to structural body positions; sigils
1527 # appearing inside strings, comments, or heredoc bodies are ordinary
1528 # content and remain valid.
1529 3 my %RESERVED_DECORATOR_SIGIL = map { $_ => 1 }
1530 ('!', '@', '$', '%', '^', '&', '*', '|', '~', '`',
1531 '.', ',', '>', '<', '?', ';', '=');
1532  
1533 6 ▶sub _check_reserved_sigil {
Subroutine _check_reserved_sigil: called CC=3 SCAR=11.8
1534 6 my $self = shift;
1535 6 my $p = $self->{pos};
1536 6 ▶ return if $p >= $self->{len};
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $self->{"len"} 0 6 6
1537 6 my $c = substr($self->{src}, $p, 1);
1538 6 ▶ return unless exists $RESERVED_DECORATOR_SIGIL{$c};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $RESERVED_DECORATOR_SIGIL{$c} 6 0 6
1539 0 $self->_die(
1540 "'$c' is a reserved decorator sigil at line-start (tier 0)"
1541 );
1542 }
1543  
1544 8 ▶sub _skip_inline_ws {
Subroutine _skip_inline_ws: called CC=2 SCAR=7.6
1545 8 my $self = shift;
1546 8 pos($self->{src}) = $self->{pos};
1547 8 ▶ if ($self->{src} =~ /\G[ \t]+/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G[ \t]+/cg) 0 8 8
1548 0 $self->{pos} = pos($self->{src});
1549 }
1550 }
1551  
1552 28 ▶sub _consume_eol {
Subroutine _consume_eol: called CC=4 SCAR=19.1
1553 28 my $self = shift;
1554 28 my $c = $self->_peek;
1555 28 ▶ if (defined($c) && $c eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq "\n") 28 0 28
Condition33%1/3
defined $c and $c eq "\n"
!ll&&!rl&&r
0028
MC/DC0%0/2
defined $c and $c eq "\n"
defined $c $c eq "\n"
Truth table33%1/3
A and B
A= defined $cB= $c eq "\n"
ABresult
0X0
100
111
1556 28 $self->{pos}++;
1557 28 $self->_advance_line;
1558 28 return 1;
1559 }
1560 0 ▶ if ($self->_starts_with("\r\n")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_starts_with("\r\n")) 0 0 0
1561 0 $self->{pos} += 2;
1562 0 $self->_advance_line;
1563 0 return 1;
1564 }
1565 0 return 0;
1566 }
1567  
1568 34 ▶sub _skip_trivia {
Subroutine _skip_trivia: called CC=29 SCAR=45.6
1569 34 my $self = shift;
1570 # Hot path: the next byte is something other than ws/EOL/comment.
1571 # Skip the whole loop. parse_table_block hits this between every
1572 # 50k keys.
1573 34 my $p = $self->{pos};
1574 34 ▶ if ($p < $self->{len}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $self->{'len'}) { } 20 14 34
1575 20 my $c0 = substr($self->{src}, $p, 1);
1576 20 ▶ return if $c0 ne ' ' && $c0 ne "\t" && $c0 ne "\n" && $c0 ne "\r"
Branch: 1 branch
BranchTrueFalseTotal
if $c0 ne " " and $c0 ne "\t" and $c0 ne "\n" and $c0 ne "\r" and $c0 ne "#" and $c0 ne "/" 17 3 20
Condition46%7/15
$c0 ne " " and $c0 ne "\t" and $c0 ne "\n" and $c0 ne "\r" and $c0 ne "#" and $c0 ne "/"
!ll&&!rl&&r
3017
$c0 ne " " and $c0 ne "\t" and $c0 ne "\n" and $c0 ne "\r" and $c0 ne "#"
!ll&&!rl&&r
0317
$c0 ne " " and $c0 ne "\t" and $c0 ne "\n" and $c0 ne "\r"
!ll&&!rl&&r
0020
$c0 ne " " and $c0 ne "\t" and $c0 ne "\n"
!ll&&!rl&&r
0020
$c0 ne " " and $c0 ne "\t"
!ll&&!rl&&r
0020
MC/DC16%1/6
$c0 ne " " and $c0 ne "\t" and $c0 ne "\n" and $c0 ne "\r" and $c0 ne "#" and $c0 ne "/"
$c0 ne " " $c0 ne "\t" $c0 ne "\n" $c0 ne "\r" $c0 ne "#" $c0 ne "/"
Truth table28%2/7
A and B and C and D and E and F
A= $c0 ne " "B= $c0 ne "\t"C= $c0 ne "\n"D= $c0 ne "\r"E= $c0 ne "#"F= $c0 ne "/"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1577 && $c0 ne '#' && $c0 ne '/';
1578 } else {
1579 14 return;
1580 }
1581 3 while (1) {
1582 6 my $start = $self->{pos};
1583 # Inline _skip_inline_ws + _peek in one regex hit.
1584 6 pos($self->{src}) = $start;
1585 0 ▶ if ($self->{src} =~ /\G[ \t]+/gc) { $self->{pos} = pos($self->{src}); }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G[ \t]+/cg) 0 6 6
1586 6 $p = $self->{pos};
1587 6 ▶ my $c = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 6 6
1588 6 ▶ if (defined($c) && ($c eq "\n" || $c eq "\r")) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $c and $c eq "\n" || $c eq "\r") { } 1 5 6
elsif (defined $c and $c eq '#') { } 3 2 5
elsif (defined $c and $c eq '/' and $self->_starts_with('//')) { } 0 2 2
elsif (defined $c and $c eq '/' and $self->_starts_with('/*')) { } 0 2 2
Condition66%4/6
defined $c and $c eq "\n" || $c eq "\r"
!ll&&!rl&&r
051
$c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
105
MC/DC33%1/3
defined $c and $c eq "\n" || $c eq "\r"
defined $c $c eq "\n" $c eq "\r"
Truth table50%2/4
A and B or C
A= defined $cB= $c eq "\n"C= $c eq "\r"
ABCresult
0XX0
1000
11X1
1011
1589 1 ▶ if ($c eq "\r" && !$self->_starts_with("\r\n")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\r" and not $self->_starts_with("\r\n")) 0 1 1
Condition33%1/3
$c eq "\r" and not $self->_starts_with("\r\n")
!ll&&!rl&&r
100
MC/DC0%0/2
$c eq "\r" and not $self->_starts_with("\r\n")
$c eq "\r" not $self->_starts_with("\r\n")
Truth table33%1/3
A and not(B)
A= $c eq "\r"B= not $self->_starts_with("\r\n")
ABresult
0X0
100
111
1590 0 $self->_die("bare CR is not a valid line terminator");
1591 }
1592 # Blank line: any pending leading comments are now separated
1593 # from a future sibling, so flush them as Floating on the
1594 # current path.
1595 1 $self->_flush_pending_as_floating;
1596 1 $self->_consume_eol;
1597 ▶ } elsif (defined($c) && $c eq '#') {
Condition66%2/3
defined $c and $c eq "#"
!ll&&!rl&&r
023
MC/DC50%1/2
defined $c and $c eq "#"
defined $c $c eq "#"
Truth table66%2/3
A and B
A= defined $cB= $c eq "#"
ABresult
0X0
100
111
1598 3 ▶ if ($self->_starts_with("###")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_starts_with('###')) { } 0 3 3
1599 0 my $raw = $self->_read_hash_block_comment;
1600 0 push @{$self->{pending_leading}},
1601 0 ▶ { content => $raw, kind => 'block' } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
1602 } else {
1603 3 my $raw = $self->_read_line_comment_to_eol;
1604 3 $self->_consume_eol;
1605 2 push @{$self->{pending_leading}},
1606 3 ▶ { content => $raw, kind => 'line' } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 2 1 3
1607 }
1608 ▶ } elsif (defined($c) && $c eq '/' && $self->_starts_with("//")) {
Condition33%2/6
defined $c and $c eq "/" and $self->_starts_with("//")
!ll&&!rl&&r
200
defined $c and $c eq "/"
!ll&&!rl&&r
020
MC/DC0%0/3
defined $c and $c eq "/" and $self->_starts_with("//")
defined $c $c eq "/" $self->_starts_with("//")
Truth table25%1/4
A and B and C
A= defined $cB= $c eq "/"C= $self->_starts_with("//")
ABCresult
0XX0
10X0
1100
1111
1609 0 my $raw = $self->_read_line_comment_to_eol;
1610 0 $self->_consume_eol;
1611 0 push @{$self->{pending_leading}},
1612 0 ▶ { content => $raw, kind => 'line' } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
1613 ▶ } elsif (defined($c) && $c eq '/' && $self->_starts_with("/*")) {
Condition33%2/6
defined $c and $c eq "/" and $self->_starts_with("/*")
!ll&&!rl&&r
200
defined $c and $c eq "/"
!ll&&!rl&&r
020
MC/DC0%0/3
defined $c and $c eq "/" and $self->_starts_with("/*")
defined $c $c eq "/" $self->_starts_with("/*")
Truth table25%1/4
A and B and C
A= defined $cB= $c eq "/"C= $self->_starts_with("/*")
ABCresult
0XX0
10X0
1100
1111
1614 0 my $raw = $self->_read_c_block_comment;
1615 0 push @{$self->{pending_leading}},
1616 0 ▶ { content => $raw, kind => 'block' } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
1617 } else {
1618 2 $self->{pos} = $start;
1619 2 return;
1620 }
1621 4 ▶ return if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 1 3 4
1622 }
1623 }
1624  
1625 # Drain pending_leading and attach each as a Floating comment on the
1626 # current path. Called on blank-line gaps and at end-of-block.
1627 2 ▶sub _flush_pending_as_floating {
Subroutine _flush_pending_as_floating: called CC=3 SCAR=17.3
1628 2 my $self = shift;
1629 2 ▶ return if !@{$self->{pending_leading}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"pending_leading"};} 2 0 2
1630 0 my @drained = @{$self->{pending_leading}};
1631 0 $self->{pending_leading} = [];
1632 0 for my $c (@drained) {
1633 0 push @{$self->{comments}}, {
1634 comment => $c,
1635 position => 'floating',
1636 0 path => [@{$self->{path}}],
1637 };
1638 }
1639 }
1640  
1641 # Drain pending_leading and attach each as a Leading comment on the
1642 # current path. Called by sibling-entry sites (parse_kvpair,
1643 # parse_list_block) right after pushing the new sibling's breadcrumb.
1644 0 ▶sub _flush_pending_as_leading_on_current {
Subroutine _flush_pending_as_leading_on_current: not called CC=3 SCAR=24.8
1645 0 my $self = shift;
1646 0 ▶ return if !@{$self->{pending_leading}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"pending_leading"};} 0 0 0
1647 0 my @drained = @{$self->{pending_leading}};
1648 0 $self->{pending_leading} = [];
1649 0 for my $c (@drained) {
1650 0 push @{$self->{comments}}, {
1651 comment => $c,
1652 position => 'leading',
1653 0 path => [@{$self->{path}}],
1654 };
1655 }
1656 }
1657  
1658 # Read a `# ...` or `// ...` line comment (without consuming the EOL)
1659 # and return the raw delimiter+body text.
1660 3 ▶sub _read_line_comment_to_eol {
Subroutine _read_line_comment_to_eol: called CC=2 SCAR=6.9
1661 3 my $self = shift;
1662 # Bulk scan to next \n or \r in one regex op rather than char-by-char
1663 # _peek loop. The bench fixture is 56% comments so this fires often.
1664 3 pos($self->{src}) = $self->{pos};
1665 3 $self->{src} =~ /\G[^\n\r]*/gc;
1666 3 my $end = pos($self->{src});
1667 3 my $start = $self->{pos};
1668 3 $self->{pos} = $end;
1669 # Lite mode discards comments — skip building the substr entirely.
1670 3 ▶ return '' if $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"lite"} 1 2 3
1671 2 return substr($self->{src}, $start, $end - $start);
1672 }
1673  
1674 # Read `/* ... */` (nested), returning the raw text including delimiters.
1675 0 ▶sub _read_c_block_comment {
Subroutine _read_c_block_comment: not called CC=10 SCAR=47.0
1676 0 my $self = shift;
1677 0 my ($sl, $sls, $sp) = ($self->{line}, $self->{line_start}, $self->{pos});
1678 0 my $start = $self->{pos};
1679 0 $self->{pos} += 2;
1680 0 my $depth = 1;
1681 0 ▶ while ($depth > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth > 0) 0 0 0
1682 0 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 0 0 0
1683 0 die $self->_err_at($sl, $sls, $sp, "unterminated /* block comment");
1684 }
1685 0 my $c = $self->_peek;
1686 0 ▶ if ($c eq '/' && $self->_starts_with("/*")) { $self->{pos} += 2; $depth++; }
Branch: 4 branches
BranchTrueFalseTotal
if ($c eq '/' and $self->_starts_with('/*')) { } 0 0 0
elsif ($c eq '*' and $self->_starts_with('*/')) { } 0 0 0
elsif ($c eq "\n") { } 0 0 0
elsif ($c eq "\r" and $self->_starts_with("\r\n")) { } 0 0 0
Condition0%0/3
$c eq "/" and $self->_starts_with("/*")
!ll&&!rl&&r
000
MC/DC0%0/2
$c eq "/" and $self->_starts_with("/*")
$c eq "/" $self->_starts_with("/*")
Truth table0%0/3
A and B
A= $c eq "/"B= $self->_starts_with("/*")
ABresult
0X0
100
111
1687 0 ▶ elsif ($c eq '*' && $self->_starts_with("*/")) { $self->{pos} += 2; $depth--; }
Condition0%0/3
$c eq "*" and $self->_starts_with("*/")
!ll&&!rl&&r
000
MC/DC0%0/2
$c eq "*" and $self->_starts_with("*/")
$c eq "*" $self->_starts_with("*/")
Truth table0%0/3
A and B
A= $c eq "*"B= $self->_starts_with("*/")
ABresult
0X0
100
111
1688 0 elsif ($c eq "\n") { $self->{pos}++; $self->_advance_line; }
1689 0 ▶ elsif ($c eq "\r" && $self->_starts_with("\r\n")) { $self->{pos} += 2; $self->_advance_line; }
Condition0%0/3
$c eq "\r" and $self->_starts_with("\r\n")
!ll&&!rl&&r
000
MC/DC0%0/2
$c eq "\r" and $self->_starts_with("\r\n")
$c eq "\r" $self->_starts_with("\r\n")
Truth table0%0/3
A and B
A= $c eq "\r"B= $self->_starts_with("\r\n")
ABresult
0X0
100
111
1690 0 else { $self->{pos}++; }
1691 }
1692 0 return substr($self->{src}, $start, $self->{pos} - $start);
1693 }
1694  
1695 # Read `### ... ###` or `###LABEL ... LABEL`. The terminator's EOL is
1696 # consumed but is NOT part of the returned text.
1697 0 ▶sub _read_hash_block_comment {
Subroutine _read_hash_block_comment: not called CC=15 SCAR=54.8
1698 0 my $self = shift;
1699 0 my ($sl, $sls, $sp) = ($self->{line}, $self->{line_start}, $self->{pos});
1700 0 my $start = $self->{pos};
1701 0 $self->{pos} += 3;
1702 0 my $ls = $self->{pos};
1703 0 while (1) {
1704 0 my $c = $self->_peek;
1705 0 ▶ last if !defined($c) || !($c eq '_' || $c =~ /[A-Za-z0-9]/);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c and $c eq "_" || $c =~ /[A-Za-z0-9]/ 0 0 0
Condition0%0/6
defined $c and $c eq "_" || $c =~ /[A-Za-z0-9]/
!ll&&!rl&&r
000
$c eq "_" or $c =~ /[A-Za-z0-9]/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c and $c eq "_" || $c =~ /[A-Za-z0-9]/
defined $c $c eq "_" $c =~ /[A-Za-z0-9]/
Truth table0%0/4
A and B or C
A= defined $cB= $c eq "_"C= $c =~ /[A-Za-z0-9]/
ABCresult
0XX0
1000
11X1
1011
1706 0 $self->{pos}++;
1707 }
1708 0 my $label = substr($self->{src}, $ls, $self->{pos} - $ls);
1709 0 ▶ if (length($label) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $label > 0) 0 0 0
1710 0 my $c0 = substr($label, 0, 1);
1711 0 ▶ if ($c0 ne '_' && $c0 !~ /[A-Za-z]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c0 ne "_" and not $c0 =~ /[A-Za-z]/) 0 0 0
Condition0%0/3
$c0 ne "_" and not $c0 =~ /[A-Za-z]/
!ll&&!rl&&r
000
MC/DC0%0/2
$c0 ne "_" and not $c0 =~ /[A-Za-z]/
$c0 ne "_" not $c0 =~ /[A-Za-z]/
Truth table0%0/3
A and not(B)
A= $c0 ne "_"B= not $c0 =~ /[A-Za-z]/
ABresult
0X0
100
111
1712 0 die $self->_err_at($sl, $sls, $sp, "block comment label must start with a letter or underscore");
1713 }
1714 }
1715 0 ▶ my $terminator = length($label) ? $label : "###";
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 0 0 0
1716 0 $self->_skip_inline_ws;
1717 0 ▶ if (!($self->_consume_eol || $self->_eof)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_consume_eol or $self->_eof) 0 0 0
Condition0%0/3
$self->_consume_eol or $self->_eof
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_consume_eol or $self->_eof
$self->_consume_eol $self->_eof
Truth table0%0/3
A or B
A= $self->_consume_eolB= $self->_eof
ABresult
1X1
011
000
1718 0 $self->_die("block comment opener must be on its own line");
1719 }
1720 0 while (1) {
1721 0 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 0 0 0
1722 0 die $self->_err_at($sl, $sls, $sp, "unterminated ### block comment");
1723 }
1724 0 my $lb = $self->{pos};
1725 0 while (1) {
1726 0 my $c = $self->_peek;
1727 0 ▶ last if !defined($c) || $c eq "\n" || $c eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $c or $c eq "\n" or $c eq "\r" 0 0 0
Condition0%0/6
not defined $c or $c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
000
not defined $c or $c eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $c or $c eq "\n" or $c eq "\r"
not defined $c $c eq "\n" $c eq "\r"
Truth table0%0/4
not(A) or B or C
A= not defined $cB= $c eq "\n"C= $c eq "\r"
ABCresult
1XX1
01X1
0011
0000
1728 0 $self->{pos}++;
1729 }
1730 0 my $line_text = substr($self->{src}, $lb, $self->{pos} - $lb);
1731 0 my $line_end = $self->{pos};
1732 0 $self->_consume_eol;
1733 0 my $trimmed = $line_text;
1734 0 $trimmed =~ s/^\s+|\s+$//g;
1735 0 ▶ if ($trimmed eq $terminator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed eq $terminator) 0 0 0
1736 0 return substr($self->{src}, $start, $line_end - $start);
1737 }
1738 }
1739 }
1740  
1741 13 ▶sub parse_front_matter {
Subroutine parse_front_matter: called CC=28 SCAR=40.4
Pod undocumented
1742 13 my $self = shift;
1743 13 my $save_pos = $self->{pos};
1744 13 my $save_line = $self->{line};
1745 13 my $save_ls = $self->{line_start};
1746 13 my $save_pending = scalar @{$self->{pending_leading}};
1747 13 my $save_comments = scalar @{$self->{comments}};
1748 13 $self->_skip_trivia;
1749 13 my $rest = substr($self->{src}, $self->{pos});
1750 13 ▶ if (substr($rest, 0, 3) ne '+++') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($rest, 0, 3) ne "+++") 5 8 13
1751 5 $self->{pos} = $save_pos; $self->{line} = $save_line; $self->{line_start} = $save_ls;
1752 # Speculative skip_trivia may have captured comments — undo so
1753 # the body parser re-captures them with the right path.
1754 5 splice @{$self->{pending_leading}}, $save_pending;
1755 5 splice @{$self->{comments}}, $save_comments;
1756 5 return undef;
1757 }
1758 # Any trailing content on the opener line is a parse error
1759 # (SPEC §Front matter: "each `+++` must appear on its own line,
1760 # with no trailing content"). Advance past `+++` and let the
1761 # strict EOL check below diagnose.
1762 8 my ($ol, $ols, $op) = ($self->{line}, $self->{line_start}, $self->{pos});
1763 8 $self->{pos} += 3;
1764 8 $self->_skip_inline_ws;
1765 8 ▶ if (!($self->_consume_eol || $self->_eof)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_consume_eol or $self->_eof) 0 8 8
Condition33%1/3
$self->_consume_eol or $self->_eof
l!l&&r!l&&!r
800
MC/DC0%0/2
$self->_consume_eol or $self->_eof
$self->_consume_eol $self->_eof
Truth table33%1/3
A or B
A= $self->_consume_eolB= $self->_eof
ABresult
1X1
011
000
1766 0 $self->_die("front matter opener must be on its own line");
1767 }
1768 8 my @inner;
1769 8 while (1) {
1770 17 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 1 16 17
1771 1 die $self->_err_at($ol, $ols, $op, "unterminated front matter: missing closing '+++'");
1772 }
1773 16 my $lb = $self->{pos};
1774 16 while (1) {
1775 177 my $c = $self->_peek;
1776 177 ▶ last if !defined($c) || $c eq "\n" || $c eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $c or $c eq "\n" or $c eq "\r" 16 161 177
Condition66%4/6
not defined $c or $c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
160161
not defined $c or $c eq "\n"
l!l&&r!l&&!r
016161
MC/DC33%1/3
not defined $c or $c eq "\n" or $c eq "\r"
not defined $c $c eq "\n" $c eq "\r"
Truth table50%2/4
not(A) or B or C
A= not defined $cB= $c eq "\n"C= $c eq "\r"
ABCresult
1XX1
01X1
0011
0000
1777 161 $self->{pos}++;
1778 }
1779 16 my $lt = substr($self->{src}, $lb, $self->{pos} - $lb);
1780 16 my $trimmed = $lt; $trimmed =~ s/^\s+|\s+$//g;
1781 16 ▶ if ($trimmed eq '+++') { $self->_consume_eol; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed eq "+++") 7 9 16
1782 9 push @inner, $lt;
1783 9 ▶ push @inner, "\n" if $self->_consume_eol;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_consume_eol 9 0 9
1784 }
1785 7 my $inner_src = join('', @inner);
1786 my $sub = bless {
1787 src => $inner_src,
1788 len => length($inner_src),
1789 pos => 0,
1790 line => 1,
1791 line_start => 0,
1792 pending_leading => [],
1793 path => [],
1794 comments => [],
1795 original_forms => [],
1796 record_forms => 1,
1797 lite => $self->{lite},
1798 # Front-matter is always ordered, regardless of body's ignore_order.
1799 # See SPEC §"Unordered tables".
1800 7 ignore_order => 0,
1801 }, __PACKAGE__;
1802 7 my $table = $sub->parse_body_as_table;
1803 7 my $lite = $self->{lite};
1804 7 my ($meta, $meta_order);
1805 7 ▶ if ($lite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lite) { } 7 0 7
1806 7 $meta_order = [];
1807 7 $meta = { $ORDER_KEY => $meta_order };
1808 } else {
1809 0 $meta = new_table();
1810 }
1811 7 ▶ my $fm_err = sub { die $self->_err_at($ol, $ols, $op, $_[0]); };
Subroutine __ANON__: called CC=1 SCAR=0.0
1812 # Iterate $table in insertion order: lite-mode tables carry their
1813 # order list at $ORDER_KEY, tied tables yield insertion order via
1814 # `keys`.
1815 7 my @table_keys;
1816 7 ▶ if ($lite && exists $table->{$ORDER_KEY}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lite and exists $table->{$ORDER_KEY}) { } 7 0 7
Condition33%1/3
$lite and exists $table->{$ORDER_KEY}
!ll&&!rl&&r
007
MC/DC0%0/2
$lite and exists $table->{$ORDER_KEY}
$lite exists $table->{$ORDER_KEY}
Truth table33%1/3
A and B
A= $liteB= exists $table->{$ORDER_KEY}
ABresult
0X0
100
111
1817 7 @table_keys = @{ $table->{$ORDER_KEY} };
1818 } else {
1819 0 @table_keys = grep { $_ ne $ORDER_KEY } keys %$table;
1820 }
1821 7 for my $k (@table_keys) {
1822 8 my $v = $table->{$k};
1823 8 ▶ if ($k =~ /^_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^_/) { } 4 4 8
1824 4 ▶ if ($k eq '_dms_tier') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq '_dms_tier') { } 3 1 4
1825 3 ▶ unless (ref($v) eq 'DMS::Parser::Integer') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $v eq "DMS::Parser::Integer") 1 2 3
1826 1 $fm_err->("_dms_tier must be a non-negative integer");
1827 }
1828 2 my $n = int($$v);
1829 2 ▶ if ($n < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < 0) 0 2 2
1830 0 $fm_err->("_dms_tier must be non-negative");
1831 }
1832 2 ▶ if ($n >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= 1) 1 1 2
1833 1 $fm_err->("_dms_tier: $n is not supported (no tier >= 1 is defined in this version of DMS)");
1834 }
1835 } else {
1836 1 $fm_err->("unknown reserved key: $k");
1837 }
1838 } else {
1839 4 ▶ push @$meta_order, $k if $lite;
Branch: 1 branch
BranchTrueFalseTotal
if $lite 4 0 4
1840 4 $meta->{$k} = $v;
1841 }
1842 }
1843 # Hoist sub-parser comments into ours, prefixing each path with the
1844 # sentinel string "__fm__" so callers can distinguish front-matter
1845 # comments from body comments. Comments attached to reserved
1846 # (consumed) `_dms_*` keys are dropped.
1847 4 for my $ac (@{$sub->{comments}}) {
1848 0 my $first = $ac->{path}[0];
1849 0 ▶ my $attached_to_reserved = (defined($first) && !ref($first) && substr($first, 0, 1) eq '_');
Condition0%0/6
defined $first && !ref($first) && substr($first, 0, 1) eq '_'
!ll&&!rl&&r
000
defined $first and not ref $first
!ll&&!rl&&r
000
MC/DC0%0/3
defined $first && !ref($first) && substr($first, 0, 1) eq '_'
defined $first not ref $first substr($first, 0, 1) eq '_'
Truth table0%0/4
A and not(B) && C
A= defined $firstB= not ref $firstC= substr($first, 0, 1) eq '_'
ABCresult
0XX0
10X0
1100
1111
1850 0 ▶ if ($attached_to_reserved) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attached_to_reserved) 0 0 0
1851 # Reserved key was consumed — re-attach as floating on FM.
1852 0 push @{$self->{comments}}, {
1853 comment => $ac->{comment},
1854 0 position => 'floating',
1855 path => ['__fm__'],
1856 };
1857 0 next;
1858 }
1859 0 my @new_path = ('__fm__', @{$ac->{path}});
1860 0 push @{$self->{comments}}, {
1861 comment => $ac->{comment},
1862 position => $ac->{position},
1863 0 path => \@new_path,
1864 };
1865 }
1866 # Same hoist for original_forms: `__fm__` prefix, drop entries for
1867 # consumed `_dms_*` keys.
1868 4 for my $pair (@{$sub->{original_forms}}) {
1869 0 my ($spath, $lit) = @$pair;
1870 0 my $first = $spath->[0];
1871 0 ▶ if (defined($first) && !ref($first) && substr($first, 0, 1) eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first and not ref $first and substr($first, 0, 1) eq "_") 0 0 0
Condition0%0/6
defined $first and not ref $first and substr($first, 0, 1) eq "_"
!ll&&!rl&&r
000
defined $first and not ref $first
!ll&&!rl&&r
000
MC/DC0%0/3
defined $first and not ref $first and substr($first, 0, 1) eq "_"
defined $first not ref $first substr($first, 0, 1) eq "_"
Truth table0%0/4
A and not(B) and C
A= defined $firstB= not ref $firstC= substr($first, 0, 1) eq "_"
ABCresult
0XX0
10X0
1100
1111
1872 0 next;
1873 }
1874 0 my @new_path = ('__fm__', @$spath);
1875 0 push @{$self->{original_forms}}, [ \@new_path, $lit ];
1876 }
1877 4 return $meta;
1878 }
1879  
1880 7 ▶sub parse_body_as_table {
Subroutine parse_body_as_table: called CC=9 SCAR=25.1
Pod undocumented
1881 7 my $self = shift;
1882 7 $self->_skip_trivia;
1883 7 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 1 6 7
1884 # FM body is empty or comments-only — flush pending as floating.
1885 1 $self->_flush_pending_as_floating;
1886 1 ▶ return $self->{lite} ? { $ORDER_KEY => [] } : new_table();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'lite'} ? : 1 0 1
1887 }
1888 6 my $c = $self->_peek;
1889 0 ▶ if ($c eq ' ' || $c eq "\t") { $self->_die("unexpected indentation inside front matter"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq " " or $c eq "\t") 0 6 6
Condition33%1/3
$c eq " " or $c eq "\t"
l!l&&r!l&&!r
006
MC/DC0%0/2
$c eq " " or $c eq "\t"
$c eq " " $c eq "\t"
Truth table33%1/3
A or B
A= $c eq " "B= $c eq "\t"
ABresult
1X1
011
000
1890 # SPEC §Lexical "Reserved decorator sigils": rejected before the
1891 # generic "front matter block must be a table" diagnostic so the
1892 # error message identifies the actual cause.
1893 6 $self->_check_reserved_sigil;
1894 0 ▶ if ($c eq '+' && $self->_peek_after_plus_is_space_or_eol) { $self->_die("front matter block cannot have a list root"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "+" and $self->_peek_after_plus_is_space_or_eol) 0 6 6
Condition33%1/3
$c eq "+" and $self->_peek_after_plus_is_space_or_eol
!ll&&!rl&&r
600
MC/DC0%0/2
$c eq "+" and $self->_peek_after_plus_is_space_or_eol
$c eq "+" $self->_peek_after_plus_is_space_or_eol
Truth table33%1/3
A and B
A= $c eq "+"B= $self->_peek_after_plus_is_space_or_eol
ABresult
0X0
100
111
1895 0 ▶ if (!$self->_line_starts_kvpair) { $self->_die("front matter block must be a table"); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_line_starts_kvpair) 0 6 6
1896 6 my $t = $self->parse_table_block(0);
1897 6 $self->_skip_trivia;
1898 6 ▶ $self->_die("trailing content inside front matter") unless $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_eof 0 6 6
1899 6 return $t;
1900 }
1901  
1902 2 ▶sub parse_body {
Subroutine parse_body: called CC=12 SCAR=41.5
Pod undocumented
1903 2 my $self = shift;
1904 2 $self->_skip_trivia;
1905 2 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 0 2 2
1906 # Empty / comment-only body: pending comments float on root.
1907 0 $self->_flush_pending_as_floating;
1908 0 ▶ if ($self->{ignore_order}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ignore_order"}) 0 0 0
1909 0 return new_unordered_table();
1910 }
1911 0 ▶ return $self->{lite} ? { $ORDER_KEY => [] } : new_table();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'lite'} ? : 0 0 0
1912 }
1913 2 my $c = $self->_peek;
1914 2 ▶ if ($c eq ' ' || $c eq "\t") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq " " or $c eq "\t") 0 2 2
Condition33%1/3
$c eq " " or $c eq "\t"
l!l&&r!l&&!r
002
MC/DC0%0/2
$c eq " " or $c eq "\t"
$c eq " " $c eq "\t"
Truth table33%1/3
A or B
A= $c eq " "B= $c eq "\t"
ABresult
1X1
011
000
1915 0 $self->_die("unexpected indentation at document root");
1916 }
1917 2 my $result;
1918 2 ▶ if ($c eq '+' && $self->_peek_after_plus_is_space_or_eol) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '+' and $self->_peek_after_plus_is_space_or_eol) { } 0 2 2
elsif ($self->_line_starts_kvpair) { } 2 0 2
Condition33%1/3
$c eq "+" and $self->_peek_after_plus_is_space_or_eol
!ll&&!rl&&r
200
MC/DC0%0/2
$c eq "+" and $self->_peek_after_plus_is_space_or_eol
$c eq "+" $self->_peek_after_plus_is_space_or_eol
Truth table33%1/3
A and B
A= $c eq "+"B= $self->_peek_after_plus_is_space_or_eol
ABresult
0X0
100
111
1919 0 $result = $self->parse_list_block(0);
1920 0 $self->_skip_trivia;
1921 0 ▶ $self->_die("trailing content after list root") unless $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_eof 0 0 0
1922 } elsif ($self->_line_starts_kvpair) {
1923 2 $result = $self->parse_table_block(0);
1924 0 $self->_skip_trivia;
1925 0 ▶ $self->_die("trailing content after table root") unless $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_eof 0 0 0
1926 } else {
1927 0 $result = $self->parse_inline_value_or_heredoc;
1928 0 $self->_consume_after_value(1);
1929 0 $self->_skip_trivia;
1930 0 ▶ $self->_die("scalar root cannot be followed by more content") unless $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_eof 0 0 0
1931 }
1932 # Any trivia comments seen after the body float on root.
1933 0 $self->_flush_pending_as_floating;
1934 0 return $result;
1935 }
1936  
1937 0 ▶sub _peek_after_plus_is_space_or_eol {
Subroutine _peek_after_plus_is_space_or_eol: not called CC=5 SCAR=34.0
1938 0 my $self = shift;
1939 0 my $nxt = $self->_peek_at(1);
1940 0 ▶ return 1 if !defined($nxt);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nxt 0 0 0
1941 0 ▶ return $nxt eq ' ' || $nxt eq "\t" || $nxt eq "\n" || $nxt eq "\r";
Condition0%0/9
$nxt eq ' ' || $nxt eq "\t" || $nxt eq "\n" || $nxt eq "\r"
l!l&&r!l&&!r
000
$nxt eq " " or $nxt eq "\t" or $nxt eq "\n"
l!l&&r!l&&!r
000
$nxt eq " " or $nxt eq "\t"
l!l&&r!l&&!r
000
MC/DC0%0/4
$nxt eq ' ' || $nxt eq "\t" || $nxt eq "\n" || $nxt eq "\r"
$nxt eq " " $nxt eq "\t" $nxt eq "\n" $nxt eq "\r"
Truth table0%0/5
A or B or C || D
A= $nxt eq " "B= $nxt eq "\t"C= $nxt eq "\n"D= $nxt eq "\r"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1942 }
1943  
1944 8 ▶sub _line_starts_kvpair {
Subroutine _line_starts_kvpair: called CC=23 SCAR=51.1
1945 8 my $self = shift;
1946 8 my $p = $self->{pos};
1947 8 my $s = $self->{src};
1948 8 my $n = $self->{len};
1949 8 ▶ if ($p < $n && substr($s, $p, 1) eq '"') {
Branch: 2 branches
BranchTrueFalseTotal
if ($p < $n and substr($s, $p, 1) eq '"') { } 0 8 8
elsif ($p < $n and substr($s, $p, 1) eq q[']) { } 0 8 8
Condition33%1/3
$p < $n and substr($s, $p, 1) eq "\""
!ll&&!rl&&r
080
MC/DC0%0/2
$p < $n and substr($s, $p, 1) eq "\""
$p < $n substr($s, $p, 1) eq "\""
Truth table33%1/3
A and B
A= $p < $nB= substr($s, $p, 1) eq "\""
ABresult
0X0
100
111
1950 0 $p++;
1951 0 ▶ while ($p < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $n) 0 0 0
1952 0 my $ch = substr($s, $p, 1);
1953 0 ▶ if ($ch eq '\\') { $p += 2; }
Branch: 3 branches
BranchTrueFalseTotal
if ($ch eq '\\') { } 0 0 0
elsif ($ch eq '"') { } 0 0 0
elsif ($ch eq "\n" or $ch eq "\r") { } 0 0 0
1954 0 elsif ($ch eq '"') { $p++; last; }
1955 0 ▶ elsif ($ch eq "\n" || $ch eq "\r") { return 0; }
Condition0%0/3
$ch eq "\n" or $ch eq "\r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$ch eq "\n" or $ch eq "\r"
$ch eq "\n" $ch eq "\r"
Truth table0%0/3
A or B
A= $ch eq "\n"B= $ch eq "\r"
ABresult
1X1
011
000
1956 0 else { $p++; }
1957 }
1958 ▶ } elsif ($p < $n && substr($s, $p, 1) eq "'") {
Condition33%1/3
$p < $n and substr($s, $p, 1) eq "'"
!ll&&!rl&&r
080
MC/DC0%0/2
$p < $n and substr($s, $p, 1) eq "'"
$p < $n substr($s, $p, 1) eq "'"
Truth table33%1/3
A and B
A= $p < $nB= substr($s, $p, 1) eq "'"
ABresult
0X0
100
111
1959 0 $p++;
1960 0 ▶ while ($p < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $n) 0 0 0
1961 0 my $ch = substr($s, $p, 1);
1962 0 ▶ if ($ch eq "'") { $p++; last; }
Branch: 2 branches
BranchTrueFalseTotal
if ($ch eq q[']) { } 0 0 0
elsif ($ch eq "\n" or $ch eq "\r") { } 0 0 0
1963 0 ▶ elsif ($ch eq "\n" || $ch eq "\r") { return 0; }
Condition0%0/3
$ch eq "\n" or $ch eq "\r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$ch eq "\n" or $ch eq "\r"
$ch eq "\n" $ch eq "\r"
Truth table0%0/3
A or B
A= $ch eq "\n"B= $ch eq "\r"
ABresult
1X1
011
000
1964 0 else { $p++; }
1965 }
1966 } else {
1967 8 my $any = 0;
1968 8 ▶ while ($p < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p < $n) 69 0 69
1969 69 my $ch = substr($s, $p, 1);
1970 69 ▶ last if !_is_bare_key_char($ch);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_bare_key_char($ch) 8 61 69
1971 61 $p++; $any = 1;
1972 }
1973 8 ▶ return 0 if !$any;
Branch: 1 branch
BranchTrueFalseTotal
unless $any 0 8 8
1974 }
1975 8 ▶ return 0 if $p >= $n || substr($s, $p, 1) ne ':';
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $n or substr($s, $p, 1) ne ":" 0 8 8
Condition33%1/3
$p >= $n or substr($s, $p, 1) ne ":"
l!l&&r!l&&!r
008
MC/DC0%0/2
$p >= $n or substr($s, $p, 1) ne ":"
$p >= $n substr($s, $p, 1) ne ":"
Truth table33%1/3
A or B
A= $p >= $nB= substr($s, $p, 1) ne ":"
ABresult
1X1
011
000
1976 8 ▶ return 1 if $p + 1 >= $n;
Branch: 1 branch
BranchTrueFalseTotal
if $p + 1 >= $n 0 8 8
1977 8 my $nxt = substr($s, $p+1, 1);
1978 8 ▶ return $nxt eq ' ' || $nxt eq "\t" || $nxt eq "\n" || $nxt eq "\r";
Condition33%3/9
$nxt eq ' ' || $nxt eq "\t" || $nxt eq "\n" || $nxt eq "\r"
l!l&&r!l&&!r
800
$nxt eq " " or $nxt eq "\t" or $nxt eq "\n"
l!l&&r!l&&!r
800
$nxt eq " " or $nxt eq "\t"
l!l&&r!l&&!r
800
MC/DC0%0/4
$nxt eq ' ' || $nxt eq "\t" || $nxt eq "\n" || $nxt eq "\r"
$nxt eq " " $nxt eq "\t" $nxt eq "\n" $nxt eq "\r"
Truth table20%1/5
A or B or C || D
A= $nxt eq " "B= $nxt eq "\t"C= $nxt eq "\n"D= $nxt eq "\r"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1979 }
1980  
1981 0 ▶sub _measure_line_indent {
Subroutine _measure_line_indent: not called CC=2 SCAR=17.9
1982 0 my $self = shift;
1983 # Single regex hit instead of a per-char loop. Operate directly on
1984 # $self->{src} (no copy of the 700KB+ source) — pos() set/read is
1985 # safe on a hash element.
1986 0 pos($self->{src}) = $self->{line_start};
1987 0 ▶ return $self->{src} =~ /\G( +)/g ? length($1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'src'} =~ /\G( +)/g ? : 0 0 0
1988 }
1989  
1990 8 ▶sub parse_table_block {
Subroutine parse_table_block: called CC=36 SCAR=57.4
Pod undocumented
1991 8 my ($self, $indent) = @_;
1992 8 my $lite = $self->{lite};
1993 8 my $ignore_order = $self->{ignore_order};
1994 # Lite path uses a plain (non-tied) hash with a sidecar order list
1995 # under "\0_keys" — Tie::IxHash STORE/FETCH/EXISTS dispatch overhead
1996 # is the single biggest fixed cost on flat-table parses. Non-lite
1997 # path keeps the tied hash for full Document-tree compatibility.
1998 # ignore_order path: blessed DMS::Parser::UnorderedTable plain hashref, no
1999 # order list, no tying. SPEC §"Unordered tables".
2000 8 my $t;
2001 my $order;
2002 8 ▶ if ($ignore_order) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ignore_order) { } 0 8 8
elsif ($lite) { } 6 2 8
2003 0 $t = new_unordered_table();
2004 } elsif ($lite) {
2005 6 $order = [];
2006 6 $t = { $ORDER_KEY => $order };
2007 } else {
2008 2 $t = new_table();
2009 }
2010 # Hot bulk loop (lite mode, indent == 0 only). On flat-table
2011 # benchmarks, every line matches `bareword: int\n` — we can batch
2012 # them with one tight regex and avoid 50 k method-call frames per
2013 # parse. The regex anchors at the current `pos`, captures up to N
2014 # consecutive simple-line kvpairs, and stops on the first non-match
2015 # so the slow path can handle anything else (strings, floats, dates,
2016 # nested values, comments, indented blocks). Re-entered after each
2017 # slow-path iteration so a one-off slow line doesn't disable the
2018 # batch path for the rest of the file.
2019 # Bulk path: lite + (ordered with sidecar) OR lite + ignore_order
2020 # (no sidecar). Both paths use a plain hash; the only difference is
2021 # whether `$order` is updated.
2022 6 ▶ my $bulk = $lite ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lite ? : 6 0 6
2023 # File-scoped cache below (%BULK_RE_CACHE) maps indent -> compiled
2024 # regex. Persists across calls so common levels (0, 2, 4, 6) compile
2025 # once globally even across recursive parse_table_block invocations.
2026 6 ▶ my $bulk_re = $BULK_RE_CACHE{$indent} //= do {
Condition66%2/3
$BULK_RE_CACHE{$indent} //= do { my $sp = $indent == 0 ? "" : "[ ]{$indent}"; qr/\G$sp([A-Za-z_][A-Za-z0-9_-]*):[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"([\x20-\x21\x23-\x5b\x5d-\x7e]*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+))\r?\n/ }
l!l&&r!l&&!r
510
MC/DC0%0/2
$BULK_RE_CACHE{$indent} //= do { my $sp = $indent == 0 ? "" : "[ ]{$indent}"; qr/\G$sp([A-Za-z_][A-Za-z0-9_-]*):[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"([\x20-\x21\x23-\x5b\x5d-\x7e]*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+))\r?\n/ }
$BULK_RE_CACHE{$indent} do { my $sp = $indent == 0 ? "" : "[ ]{$indent}"; qr/\G$sp([A-Za-z_][A-Za-z0-9_-]*):[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"([\x20-\x21\x23-\x5b\x5d-\x7e]*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+))\r?\n/ }
Truth table66%2/3
A //= B
A= $BULK_RE_CACHE{$indent}B= do { my $sp = $indent == 0 ? "" : "[ ]{$indent}"; qr/\G$sp([A-Za-z_][A-Za-z0-9_-]*):[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"([\x20-\x21\x23-\x5b\x5d-\x7e]*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+))\r?\n/ }
ABresult
1X1
011
000
2027 1 ▶ my $sp = $indent == 0 ? '' : "[ ]{$indent}";
Branch: 1 branch
BranchTrueFalseTotal
$indent == 0 ? : 1 0 1
2028 # Groups:
2029 # $2: positive integer
2030 # $3: negative integer
2031 # $4: bool
2032 # $5: ASCII-only basic-string content (no escapes)
2033 # $6: empty list / empty table literal
2034 # $7: decimal float (matches `-?[0-9]+\.[0-9]+`, no exponent)
2035 1 qr/\G$sp([A-Za-z_][A-Za-z0-9_-]*):[ ](?:(0|[1-9][0-9]{0,17})|(-[1-9][0-9]{0,17})|(true|false)|"([\x20-\x21\x23-\x5b\x5d-\x7e]*)"|(\[\]|\{\})|(-?(?:0|[1-9][0-9]*)\.[0-9]+))\r?\n/;
2036 };
2037 6 while (1) {
2038 6 ▶ if ($bulk && $self->{pos} == $self->{line_start}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bulk and $self->{"pos"} == $self->{"line_start"}) 6 0 6
Condition33%1/3
$bulk and $self->{"pos"} == $self->{"line_start"}
!ll&&!rl&&r
006
MC/DC0%0/2
$bulk and $self->{"pos"} == $self->{"line_start"}
$bulk $self->{"pos"} == $self->{"line_start"}
Truth table33%1/3
A and B
A= $bulkB= $self->{"pos"} == $self->{"line_start"}
ABresult
0X0
100
111
2039 6 my $src_ref = \$self->{src};
2040 6 pos($$src_ref) = $self->{pos};
2041 6 my $line = $self->{line};
2042 # One regex matches multiple value forms:
2043 # group $2: positive integer (0 or [1-9][0-9]{0,17}, 18 digits max → safe i64)
2044 # group $3: negative integer (-[1-9][0-9]{0,17})
2045 # group $4: 'true' or 'false'
2046 # group $5: simple ASCII basic-string content (no \, ", \n, \r,
2047 # and ASCII-only so we skip the NFC pass) — empty
2048 # string is common in real configs (kube values.yaml
2049 # has hundreds of `key: ""` lines).
2050 # group $6: '[]' or '{}' (empty list / empty table)
2051 # Excludes leading-zero forms (which DMS rejects) and overflow.
2052 # Accepts both LF and CRLF line endings. Anything else (escaped
2053 # strings, floats, dates, multi-line blocks, comments) falls to
2054 # the slow path on the next iteration.
2055 # Inner bulk loop: consumes any pattern we can match purely
2056 # by regex (kvpair, blank line, single-line `#` or `//`
2057 # comment) without method dispatch. Falls back to the
2058 # outer slow path the moment something complex appears
2059 # (heredoc, escaped string, list item, block comment).
2060 6 INNER: while (1) {
2061 14 ▶ if ($$src_ref =~ /$bulk_re/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$src_ref =~ /$bulk_re/cg) 8 6 14
2062 8 my $k = $1;
2063 8 ▶ if (exists $t->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $t->{$k}) 0 8 8
2064 # Roll back to start of the current line for accurate error pos.
2065 0 my $cur = pos($$src_ref);
2066 0 ▶ while ($cur > 0 && substr($$src_ref, $cur - 1, 1) ne "\n") { $cur--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($cur > 0 and substr($$src_ref, $cur - 1, 1) ne "\n") 0 0 0
Condition0%0/3
$cur > 0 and substr($$src_ref, $cur - 1, 1) ne "\n"
!ll&&!rl&&r
000
MC/DC0%0/2
$cur > 0 and substr($$src_ref, $cur - 1, 1) ne "\n"
$cur > 0 substr($$src_ref, $cur - 1, 1) ne "\n"
Truth table0%0/3
A and B
A= $cur > 0B= substr($$src_ref, $cur - 1, 1) ne "\n"
ABresult
0X0
100
111
2067 0 $self->{pos} = $cur;
2068 0 $self->{line} = $line;
2069 0 $self->{line_start} = $cur;
2070 0 $self->_die("duplicate key: $k");
2071 }
2072 8 my $val;
2073 8 ▶ if (defined $2) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $2) { } 2 6 8
elsif (defined $3) { } 0 6 6
elsif (defined $4) { } 0 6 6
elsif (defined $5) { } 6 0 6
elsif (defined $6) { } 0 0 0
2074 2 my $iv = 0 + $2;
2075 2 $val = bless \$iv, 'DMS::Parser::Integer';
2076 } elsif (defined $3) {
2077 0 my $iv = 0 + $3;
2078 0 $val = bless \$iv, 'DMS::Parser::Integer';
2079 } elsif (defined $4) {
2080 0 ▶ my $bv = $4 eq 'true' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$4 eq 'true' ? : 0 0 0
2081 0 $val = bless \$bv, 'DMS::Parser::Bool';
2082 } elsif (defined $5) {
2083 # ASCII-only basic string, no escapes / no NFC.
2084 6 $val = $5;
2085 } elsif (defined $6) {
2086 # '[]' or '{}'.
2087 0 ▶ $val = $6 eq '[]' ? [] : { $ORDER_KEY => [] };
Branch: 1 branch
BranchTrueFalseTotal
$6 eq '[]' ? : 0 0 0
2088 } else {
2089 # $7: decimal float.
2090 0 my $fv = 0 + $7;
2091 0 $val = bless \$fv, 'DMS::Parser::Float';
2092 }
2093 8 ▶ push @$order, $k if $order;
Branch: 1 branch
BranchTrueFalseTotal
if $order 8 0 8
2094 8 $t->{$k} = $val;
2095 8 $line++;
2096 8 next INNER;
2097 }
2098 # Blank line at any leading whitespace.
2099 6 ▶ if ($$src_ref =~ /\G[ \t]*\r?\n/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$src_ref =~ /\G[ \t]*\r?\n/cg) 0 6 6
2100 0 $line++;
2101 0 next INNER;
2102 }
2103 # Single-line `#` comment (NOT `###` labeled block) or `//`.
2104 # Excludes `/*` (C-style block) which spans multiple lines.
2105 # bench_realistic is 56% comments — taking these in the
2106 # bulk loop avoids hundreds of _skip_trivia method calls.
2107 6 ▶ if ($$src_ref =~ /\G[ \t]*(?:#(?!##)|\/\/(?!\*))[^\n\r]*\r?\n/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$src_ref =~ m[\G[ \t]*(?:#(?!##)|//(?!\*))[^\n\r]*\r?\n]cg) 0 6 6
2108 0 $line++;
2109 0 next INNER;
2110 }
2111 6 last INNER;
2112 }
2113 6 ▶ $self->{pos} = pos($$src_ref) // $self->{pos};
Condition33%1/3
pos $$src_ref // $self->{"pos"}
l!l&&r!l&&!r
600
MC/DC0%0/2
pos $$src_ref // $self->{"pos"}
pos $$src_ref $self->{"pos"}
Truth table33%1/3
A // B
A= pos $$src_refB= $self->{"pos"}
ABresult
1X1
011
000
2114 6 $self->{line} = $line;
2115 6 $self->{line_start} = $self->{pos};
2116 }
2117 6 $self->_skip_trivia;
2118 6 ▶ last if $self->{pos} >= $self->{len};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} >= $self->{"len"} 6 0 6
2119 # Inline _measure_line_indent: hot enough that the call cost
2120 # matters across 50k iterations. For indent==0 (most flat
2121 # tables) we can skip the regex when pos is already at
2122 # line_start with no leading space — by far the common case.
2123 0 my $li;
2124 0 ▶ if ($indent == 0 && $self->{pos} == $self->{line_start}
Branch: 1 branch
BranchTrueFalseTotal
if ($indent == 0 and $self->{'pos'} == $self->{'line_start'} and substr($self->{'src'}, $self->{'pos'}, 1) ne ' ') { } 0 0 0
Condition0%0/6
$indent == 0 and $self->{"pos"} == $self->{"line_start"} and substr($self->{"src"}, $self->{"pos"}, 1) ne " "
!ll&&!rl&&r
000
$indent == 0 and $self->{"pos"} == $self->{"line_start"}
!ll&&!rl&&r
000
MC/DC0%0/3
$indent == 0 and $self->{"pos"} == $self->{"line_start"} and substr($self->{"src"}, $self->{"pos"}, 1) ne " "
$indent == 0 $self->{"pos"} == $self->{"line_start"} substr($self->{"src"}, $self->{"pos"}, 1) ne " "
Truth table0%0/4
A and B and C
A= $indent == 0B= $self->{"pos"} == $self->{"line_start"}C= substr($self->{"src"}, $self->{"pos"}, 1) ne " "
ABCresult
0XX0
10X0
1100
1111
2125 && substr($self->{src}, $self->{pos}, 1) ne ' ') {
2126 0 $li = 0;
2127 } else {
2128 0 pos($self->{src}) = $self->{line_start};
2129 0 ▶ $li = $self->{src} =~ /\G( +)/g ? length($1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'src'} =~ /\G( +)/g ? : 0 0 0
2130 }
2131 0 ▶ last if $li < $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $li < $indent 0 0 0
2132 0 ▶ if ($li != $indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($li != $indent) 0 0 0
2133 0 die $self->_err_at($self->{line}, $self->{line_start}, $self->{line_start}+$indent,
2134 "inconsistent indent: expected $indent spaces, got $li");
2135 }
2136 0 $self->{pos} = $self->{line_start} + $indent;
2137 # SPEC §Lexical "Reserved decorator sigils": reject ! @ $ % ^ & *
2138 # | ~ ` . , > < ? ; = as the first non-whitespace character of a
2139 # body line. We sit at exactly that position now (line_start +
2140 # structural indent), so a single-char check is sufficient.
2141 0 $self->_check_reserved_sigil;
2142 0 my ($k, $v);
2143 0 ▶ if ($lite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lite) { } 0 0 0
2144 # Inlined fast-path of parse_kvpair: skip the eval frame and
2145 # the path push/pop that parse_kvpair adds for non-lite modes.
2146 0 $k = $self->parse_key;
2147 $self->_die("expected ':' after key")
2148 0 ▶ if substr($self->{src}, $self->{pos}, 1) ne ':';
Branch: 1 branch
BranchTrueFalseTotal
if substr($self->{"src"}, $self->{"pos"}, 1) ne ":" 0 0 0
2149 0 $v = $self->_parse_kvpair_after_key($indent);
2150 0 ▶ $self->_die("duplicate key: $k") if exists $t->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $t->{$k} 0 0 0
2151 0 ▶ push @$order, $k if $order;
Branch: 1 branch
BranchTrueFalseTotal
if $order 0 0 0
2152 0 $t->{$k} = $v;
2153 } else {
2154 0 ($k, $v) = $self->parse_kvpair($indent);
2155 0 ▶ $self->_die("duplicate key: $k") if exists $t->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $t->{$k} 0 0 0
2156 0 $t->{$k} = $v;
2157 }
2158 }
2159 # Block close: leftover pending comments float on the enclosing
2160 # container (this table itself).
2161 6 ▶ $self->_flush_pending_as_floating unless $lite;
Branch: 1 branch
BranchTrueFalseTotal
unless $lite 0 6 6
2162 6 return $t;
2163 }
2164  
2165 0 ▶sub parse_list_block {
Subroutine parse_list_block: not called CC=19 SCAR=59.4
Pod undocumented
2166 0 my ($self, $indent) = @_;
2167 0 my @items;
2168 0 while (1) {
2169 0 $self->_skip_trivia;
2170 0 ▶ last if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
2171 0 my $li = $self->_measure_line_indent;
2172 0 ▶ last if $li < $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $li < $indent 0 0 0
2173 0 ▶ if ($li != $indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($li != $indent) 0 0 0
2174 0 die $self->_err_at($self->{line}, $self->{line_start}, $self->{line_start}+$indent,
2175 "inconsistent indent: expected $indent spaces, got $li");
2176 }
2177 0 $self->{pos} = $self->{line_start} + $indent;
2178 0 ▶ if ($self->_peek ne '+') { last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek ne "+") 0 0 0
2179 # Commit to a new list item: push its index, attach pending
2180 # leading comments to it, then parse the value.
2181 0 my $idx = scalar @items;
2182 0 push @{$self->{path}}, DMS::Parser::Index->new($idx);
2183 0 $self->_flush_pending_as_leading_on_current;
2184 0 $self->{pos}++;
2185 0 my $c = $self->_peek;
2186 0 my $item;
2187 0 my $ok = eval {
2188 0 ▶ if (defined($c) && ($c eq ' ' || $c eq "\t")) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $c and $c eq ' ' || $c eq "\t") { } 0 0 0
elsif (not defined $c or $c eq "\n" or $c eq "\r") { } 0 0 0
Condition0%0/6
defined $c and $c eq " " || $c eq "\t"
!ll&&!rl&&r
000
$c eq " " or $c eq "\t"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c and $c eq " " || $c eq "\t"
defined $c $c eq " " $c eq "\t"
Truth table0%0/4
A and B or C
A= defined $cB= $c eq " "C= $c eq "\t"
ABCresult
0XX0
1000
11X1
1011
2189 0 $self->{pos}++;
2190 0 $self->_skip_inline_ws;
2191 0 $self->_capture_inner_block_comments;
2192 0 my $c2 = $self->_peek;
2193 0 ▶ if (!defined($c2) || $c2 eq "\n" || $c2 eq "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c2 or $c2 eq "\n" or $c2 eq "\r") { } 0 0 0
Condition0%0/6
not defined $c2 or $c2 eq "\n" or $c2 eq "\r"
l!l&&r!l&&!r
000
not defined $c2 or $c2 eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $c2 or $c2 eq "\n" or $c2 eq "\r"
not defined $c2 $c2 eq "\n" $c2 eq "\r"
Truth table0%0/4
not(A) or B or C
A= not defined $c2B= $c2 eq "\n"C= $c2 eq "\r"
ABCresult
1XX1
01X1
0011
0000
2194 # "+ INNER[EOL]" — empty item with inner comments.
2195 0 $self->_consume_eol;
2196 0 $self->_skip_trivia;
2197 0 ▶ $self->_die("expected indented block after empty '+' marker") if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
2198 0 my $inner = $self->_measure_line_indent;
2199 0 ▶ $self->_die("expected indented block after empty '+' marker") if $inner <= $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $inner <= $indent 0 0 0
2200 0 $item = $self->parse_block_value($inner);
2201 } else {
2202 0 $item = $self->parse_list_item_value($indent);
2203 }
2204 ▶ } elsif (!defined($c) || $c eq "\n" || $c eq "\r") {
Condition0%0/6
not defined $c or $c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
000
not defined $c or $c eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $c or $c eq "\n" or $c eq "\r"
not defined $c $c eq "\n" $c eq "\r"
Truth table0%0/4
not(A) or B or C
A= not defined $cB= $c eq "\n"C= $c eq "\r"
ABCresult
1XX1
01X1
0011
0000
2205 0 $self->_consume_eol;
2206 0 $self->_skip_trivia;
2207 0 ▶ $self->_die("expected indented block after empty '+' marker") if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
2208 0 my $inner = $self->_measure_line_indent;
2209 0 ▶ $self->_die("expected indented block after empty '+' marker") if $inner <= $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $inner <= $indent 0 0 0
2210 0 $item = $self->parse_block_value($inner);
2211 } else {
2212 0 $self->_die("expected space after '+'");
2213 }
2214 0 1;
2215 };
2216 0 my $err = $@;
2217 0 pop @{$self->{path}};
2218 0 ▶ if (!$ok) { die $err; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
2219 0 push @items, $item;
2220 }
2221 # Block close: leftover pending comments float on the list itself.
2222 0 $self->_flush_pending_as_floating;
2223 0 return \@items;
2224 }
2225  
2226 0 ▶sub parse_block_value {
Subroutine parse_block_value: not called CC=3 SCAR=24.8
Pod undocumented
2227 0 my ($self, $indent) = @_;
2228 0 $self->{pos} = $self->{line_start} + $indent;
2229 0 ▶ if ($self->_peek eq '+' && $self->_peek_after_plus_is_space_or_eol) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek eq "+" and $self->_peek_after_plus_is_space_or_eol) 0 0 0
Condition0%0/3
$self->_peek eq "+" and $self->_peek_after_plus_is_space_or_eol
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_peek eq "+" and $self->_peek_after_plus_is_space_or_eol
$self->_peek eq "+" $self->_peek_after_plus_is_space_or_eol
Truth table0%0/3
A and B
A= $self->_peek eq "+"B= $self->_peek_after_plus_is_space_or_eol
ABresult
0X0
100
111
2230 0 return $self->parse_list_block($indent);
2231 }
2232 0 return $self->parse_table_block($indent);
2233 }
2234  
2235 0 ▶sub parse_list_item_value {
Subroutine parse_list_item_value: not called CC=11 SCAR=48.8
Pod undocumented
2236 0 my ($self, $list_indent) = @_;
2237 0 ▶ if ($self->_line_starts_kvpair) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_line_starts_kvpair) 0 0 0
2238 0 my $key_col = $self->{pos} - $self->{line_start};
2239 0 my $lite = $self->{lite};
2240 0 my $ignore_order = $self->{ignore_order};
2241 0 my ($k, $v) = $self->parse_kvpair($key_col);
2242 0 my ($t, $order);
2243 0 ▶ if ($ignore_order) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ignore_order) { } 0 0 0
elsif ($lite) { } 0 0 0
2244 0 $t = new_unordered_table();
2245 0 $t->{$k} = $v;
2246 } elsif ($lite) {
2247 0 $order = [$k];
2248 0 $t = { $ORDER_KEY => $order, $k => $v };
2249 } else {
2250 0 $t = new_table();
2251 0 $t->{$k} = $v;
2252 }
2253 0 while (1) {
2254 0 $self->_skip_trivia;
2255 0 ▶ last if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
2256 0 my $li = $self->_measure_line_indent;
2257 0 ▶ last if $li < $key_col;
Branch: 1 branch
BranchTrueFalseTotal
if $li < $key_col 0 0 0
2258 0 ▶ if ($li != $key_col) {
Branch: 1 branch
BranchTrueFalseTotal
if ($li != $key_col) 0 0 0
2259 0 die $self->_err_at($self->{line}, $self->{line_start}, $self->{line_start}+$key_col,
2260 "list-item table sibling key must align with first key");
2261 }
2262 0 $self->{pos} = $self->{line_start} + $key_col;
2263 0 ▶ $self->_die("'+' marker at sibling-key column is ambiguous") if $self->_peek eq '+';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_peek eq "+" 0 0 0
2264 0 ▶ last if !$self->_line_starts_kvpair;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_line_starts_kvpair 0 0 0
2265 0 my ($k2, $v2) = $self->parse_kvpair($key_col);
2266 0 ▶ $self->_die("duplicate key: $k2") if exists $t->{$k2};
Branch: 1 branch
BranchTrueFalseTotal
if exists $t->{$k2} 0 0 0
2267 0 ▶ push @$order, $k2 if $order;
Branch: 1 branch
BranchTrueFalseTotal
if $order 0 0 0
2268 0 $t->{$k2} = $v2;
2269 }
2270 # End of inline-table-in-list-item: any pending leading comments
2271 # belong to the enclosing list item itself (Floating).
2272 0 $self->_flush_pending_as_floating;
2273 0 return $t;
2274 }
2275 0 my $v = $self->parse_inline_value_or_heredoc;
2276 0 $self->_consume_after_value(0);
2277 0 return $v;
2278 }
2279  
2280 0 ▶sub parse_kvpair {
Subroutine parse_kvpair: not called CC=4 SCAR=30.0
Pod undocumented
2281 0 my ($self, $parent_indent) = @_;
2282 0 my $key = $self->parse_key;
2283 0 ▶ $self->_die("expected ':' after key") if substr($self->{src}, $self->{pos}, 1) ne ':';
Branch: 1 branch
BranchTrueFalseTotal
if substr($self->{"src"}, $self->{"pos"}, 1) ne ":" 0 0 0
2284 # Lite mode: no comment-AST, no original_form recording, no path
2285 # bookkeeping needed. Skip the breadcrumb push/pop + eval frame.
2286 0 ▶ if ($self->{lite}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lite"}) 0 0 0
2287 0 my $v = $self->_parse_kvpair_after_key($parent_indent);
2288 0 return ($key, $v);
2289 }
2290 # We've now committed: this is a kvpair. Push the breadcrumb so
2291 # pending leading comments attach here and so trailing comments
2292 # captured by _consume_after_value get the right path.
2293 0 push @{$self->{path}}, $key;
2294 0 $self->_flush_pending_as_leading_on_current;
2295 0 my $v;
2296 0 my $ok = eval { $v = $self->_parse_kvpair_after_key($parent_indent); 1 };
2297 0 my $err = $@;
2298 0 pop @{$self->{path}};
2299 0 ▶ if (!$ok) { die $err; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
2300 0 return ($key, $v);
2301 }
2302  
2303 0 ▶sub _parse_kvpair_after_key {
Subroutine _parse_kvpair_after_key: not called CC=23 SCAR=63.1
2304 0 my ($self, $parent_indent) = @_;
2305 0 $self->{pos}++; # consume ':'
2306 # Inline _peek: per-key dispatch overhead is significant on flat-50k.
2307 0 my $p = $self->{pos};
2308 0 ▶ my $c = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 0 0
2309 0 ▶ if (defined($c) && ($c eq ' ' || $c eq "\t")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq " " || $c eq "\t") 0 0 0
Condition0%0/6
defined $c and $c eq " " || $c eq "\t"
!ll&&!rl&&r
000
$c eq " " or $c eq "\t"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c and $c eq " " || $c eq "\t"
defined $c $c eq " " $c eq "\t"
Truth table0%0/4
A and B or C
A= defined $cB= $c eq " "C= $c eq "\t"
ABCresult
0XX0
1000
11X1
1011
2310 0 $self->{pos}++;
2311 0 $p = $self->{pos};
2312 # Inline _skip_inline_ws fast path — only run the regex if the
2313 # next byte is itself ws (single-space `key: v` is the common case).
2314 0 ▶ my $c2 = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 0 0
2315 0 ▶ if (defined($c2) && ($c2 eq ' ' || $c2 eq "\t")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and $c2 eq " " || $c2 eq "\t") 0 0 0
Condition0%0/6
defined $c2 and $c2 eq " " || $c2 eq "\t"
!ll&&!rl&&r
000
$c2 eq " " or $c2 eq "\t"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $c2 and $c2 eq " " || $c2 eq "\t"
defined $c2 $c2 eq " " $c2 eq "\t"
Truth table0%0/4
A and B or C
A= defined $c2B= $c2 eq " "C= $c2 eq "\t"
ABCresult
0XX0
1000
11X1
1011
2316 0 pos($self->{src}) = $p;
2317 0 $self->{src} =~ /\G[ \t]+/gc;
2318 0 $self->{pos} = pos($self->{src});
2319 0 $p = $self->{pos};
2320 0 ▶ $c2 = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 0 0
2321 }
2322 # Inline _capture_inner_block_comments fast path: only call out
2323 # if the next byte is '/'.
2324 0 ▶ if (defined($c2) && $c2 eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c2 and $c2 eq "/") 0 0 0
Condition0%0/3
defined $c2 and $c2 eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c2 and $c2 eq "/"
defined $c2 $c2 eq "/"
Truth table0%0/3
A and B
A= defined $c2B= $c2 eq "/"
ABresult
0X0
100
111
2325 0 $self->_capture_inner_block_comments;
2326 0 $p = $self->{pos};
2327 0 ▶ $c2 = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 0 0
2328 }
2329 0 ▶ if (!defined($c2) || $c2 eq "\n" || $c2 eq "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c2 or $c2 eq "\n" or $c2 eq "\r") 0 0 0
Condition0%0/6
not defined $c2 or $c2 eq "\n" or $c2 eq "\r"
l!l&&r!l&&!r
000
not defined $c2 or $c2 eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $c2 or $c2 eq "\n" or $c2 eq "\r"
not defined $c2 $c2 eq "\n" $c2 eq "\r"
Truth table0%0/4
not(A) or B or C
A= not defined $c2B= $c2 eq "\n"C= $c2 eq "\r"
ABCresult
1XX1
01X1
0011
0000
2330 # "key: INNER[EOL]" — child block with inner comments.
2331 0 $self->_consume_eol;
2332 0 $self->_skip_trivia;
2333 0 ▶ $self->_die("expected indented child block") if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
2334 0 my $child = $self->_measure_line_indent;
2335 0 ▶ $self->_die("expected indented child block") if $child <= $parent_indent;
Branch: 1 branch
BranchTrueFalseTotal
if $child <= $parent_indent 0 0 0
2336 0 return $self->parse_block_value($child);
2337 }
2338 0 my $v = $self->parse_inline_value_or_heredoc;
2339 0 $self->_consume_after_value(0);
2340 0 return $v;
2341 }
2342 0 ▶ if (!defined($c) || $c eq "\n" || $c eq "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c or $c eq "\n" or $c eq "\r") 0 0 0
Condition0%0/6
not defined $c or $c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
000
not defined $c or $c eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $c or $c eq "\n" or $c eq "\r"
not defined $c $c eq "\n" $c eq "\r"
Truth table0%0/4
not(A) or B or C
A= not defined $cB= $c eq "\n"C= $c eq "\r"
ABCresult
1XX1
01X1
0011
0000
2343 0 $self->_consume_eol;
2344 0 $self->_skip_trivia;
2345 0 ▶ $self->_die("expected indented child block") if $self->_eof;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_eof 0 0 0
2346 0 my $child = $self->_measure_line_indent;
2347 0 ▶ $self->_die("expected indented child block") if $child <= $parent_indent;
Branch: 1 branch
BranchTrueFalseTotal
if $child <= $parent_indent 0 0 0
2348 0 return $self->parse_block_value($child);
2349 }
2350 0 $self->_die("expected whitespace after ':'");
2351 }
2352  
2353 0 ▶sub parse_key {
Subroutine parse_key: not called CC=11 SCAR=48.8
Pod undocumented
2354 0 my $self = shift;
2355 0 my $p = $self->{pos};
2356 0 ▶ my $c = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 0 0
2357 0 ▶ if (defined($c) && $c eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq "\"") 0 0 0
Condition0%0/3
defined $c and $c eq "\""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and $c eq "\""
defined $c $c eq "\""
Truth table0%0/3
A and B
A= defined $cB= $c eq "\""
ABresult
0X0
100
111
2358 0 ▶ $self->_die("triple-quoted strings are not allowed as keys") if $self->_starts_with('"""');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_starts_with("\"\"\"") 0 0 0
2359 # Suppress original-form recording: keys are not values and must
2360 # not generate OriginalLiteral entries on the parent path.
2361 0 my $saved = $self->{record_forms};
2362 0 $self->{record_forms} = 0;
2363 0 my $r = eval { $self->parse_basic_string_value };
2364 0 my $e = $@;
2365 0 $self->{record_forms} = $saved;
2366 0 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
2367 0 return $r;
2368 }
2369 0 ▶ if (defined($c) && $c eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and $c eq "'") 0 0 0
Condition0%0/3
defined $c and $c eq "'"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and $c eq "'"
defined $c $c eq "'"
Truth table0%0/3
A and B
A= defined $cB= $c eq "'"
ABresult
0X0
100
111
2370 0 ▶ $self->_die("triple-quoted strings are not allowed as keys") if $self->_starts_with("'''");
Branch: 1 branch
BranchTrueFalseTotal
if $self->_starts_with("'''") 0 0 0
2371 0 my $saved = $self->{record_forms};
2372 0 $self->{record_forms} = 0;
2373 0 my $r = eval { $self->parse_literal_string_value };
2374 0 my $e = $@;
2375 0 $self->{record_forms} = $saved;
2376 0 ▶ die $e if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
2377 0 return $r;
2378 }
2379 0 ▶ $self->_die("expected key") if !defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
2380 0 return $self->parse_bare_key;
2381 }
2382  
2383 0 ▶sub parse_bare_key {
Subroutine parse_bare_key: not called CC=7 SCAR=40.3
Pod undocumented
2384 0 my $self = shift;
2385 0 my $start = $self->{pos};
2386 # Fast path: ASCII-only bare key. One regex bite handles the entire
2387 # token — no per-byte loop, no Unicode codepoint test.
2388 0 pos($self->{src}) = $start;
2389 0 ▶ if ($self->{src} =~ /\G[A-Za-z0-9_-]+/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G[A-Za-z0-9_-]+/cg) 0 0 0
2390 0 $self->{pos} = pos($self->{src});
2391 }
2392 # Slow path: extend across non-ASCII XID_Continue codepoints if any.
2393 0 ▶ while ($self->{pos} < $self->{len}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pos"} < $self->{"len"}) 0 0 0
2394 0 my $c = substr($self->{src}, $self->{pos}, 1);
2395 0 ▶ last if ord($c) < 128;
Branch: 1 branch
BranchTrueFalseTotal
if ord $c < 128 0 0 0
2396 0 ▶ last unless _is_bare_key_char($c);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_bare_key_char($c) 0 0 0
2397 0 $self->{pos}++;
2398 0 pos($self->{src}) = $self->{pos};
2399 0 ▶ if ($self->{src} =~ /\G[A-Za-z0-9_-]+/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G[A-Za-z0-9_-]+/cg) 0 0 0
2400 0 $self->{pos} = pos($self->{src});
2401 }
2402 }
2403 0 ▶ $self->_die("expected key") if $self->{pos} == $start;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} == $start 0 0 0
2404 0 return substr($self->{src}, $start, $self->{pos} - $start);
2405 }
2406  
2407 0 ▶sub _capture_inner_block_comments {
Subroutine _capture_inner_block_comments: not called CC=7 SCAR=40.3
2408 0 my $self = shift;
2409 # Hot-path early-out: if the next byte isn't '/', there's nothing to do.
2410 # Per-key cost is one substr instead of two method calls.
2411 0 my $p = $self->{pos};
2412 return if $p >= $self->{len} || substr($self->{src}, $p, 1) ne '/'
2413 0 ▶ || substr($self->{src}, $p, 2) ne '/*';
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $self->{"len"} or substr($self->{"src"}, $p, 1) ne "/" or substr($self->{"src"}, $p, 2) ne "/*" 0 0 0
Condition0%0/6
$p >= $self->{"len"} or substr($self->{"src"}, $p, 1) ne "/" or substr($self->{"src"}, $p, 2) ne "/*"
l!l&&r!l&&!r
000
$p >= $self->{"len"} or substr($self->{"src"}, $p, 1) ne "/"
l!l&&r!l&&!r
000
MC/DC0%0/3
$p >= $self->{"len"} or substr($self->{"src"}, $p, 1) ne "/" or substr($self->{"src"}, $p, 2) ne "/*"
$p >= $self->{"len"} substr($self->{"src"}, $p, 1) ne "/" substr($self->{"src"}, $p, 2) ne "/*"
Truth table0%0/4
A or B or C
A= $p >= $self->{"len"}B= substr($self->{"src"}, $p, 1) ne "/"C= substr($self->{"src"}, $p, 2) ne "/*"
ABCresult
1XX1
01X1
0011
0000
2414 0 while (1) {
2415 0 $p = $self->{pos};
2416 0 ▶ last if $p >= $self->{len} || substr($self->{src}, $p, 2) ne '/*';
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $self->{"len"} or substr($self->{"src"}, $p, 2) ne "/*" 0 0 0
Condition0%0/3
$p >= $self->{"len"} or substr($self->{"src"}, $p, 2) ne "/*"
l!l&&r!l&&!r
000
MC/DC0%0/2
$p >= $self->{"len"} or substr($self->{"src"}, $p, 2) ne "/*"
$p >= $self->{"len"} substr($self->{"src"}, $p, 2) ne "/*"
Truth table0%0/3
A or B
A= $p >= $self->{"len"}B= substr($self->{"src"}, $p, 2) ne "/*"
ABresult
1X1
011
000
2417 0 my $raw = $self->_read_c_block_comment;
2418 0 push @{$self->{comments}}, {
2419 comment => { content => $raw, kind => 'block' },
2420 position => 'inner',
2421 0 path => [@{$self->{path}}],
2422 0 ▶ } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
2423 0 $self->_skip_inline_ws;
2424 }
2425 }
2426  
2427 0 ▶sub parse_inline_value_or_heredoc {
Subroutine parse_inline_value_or_heredoc: not called CC=20 SCAR=60.4
Pod undocumented
2428 0 my $self = shift;
2429 # Inner /* ... */ comments are captured by the caller via
2430 # _capture_inner_block_comments before this function runs.
2431 0 my $p = $self->{pos};
2432 0 ▶ my $c = $p >= $self->{len} ? undef : substr($self->{src}, $p, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p >= $self->{'len'} ? : 0 0 0
2433 # SPEC §Lexical "Reserved decorator sigils": a value position that
2434 # leads with one of `! @ $ % ^ & * | ~ \` . , > < ? ; =` is rejected
2435 # at tier 0. Covers `key: !tag`, `+ !tag`, scalar-root `!tag`, and
2436 # the same forms inside flow containers (which dispatch per item).
2437 0 ▶ if (defined($c) && exists $RESERVED_DECORATOR_SIGIL{$c}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and exists $RESERVED_DECORATOR_SIGIL{$c}) 0 0 0
Condition0%0/3
defined $c and exists $RESERVED_DECORATOR_SIGIL{$c}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and exists $RESERVED_DECORATOR_SIGIL{$c}
defined $c exists $RESERVED_DECORATOR_SIGIL{$c}
Truth table0%0/3
A and B
A= defined $cB= exists $RESERVED_DECORATOR_SIGIL{$c}
ABresult
0X0
100
111
2438 0 $self->_die(
2439 "'$c' is a reserved decorator sigil at line-start (tier 0)"
2440 );
2441 }
2442 0 ▶ if (defined($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c) 0 0 0
2443 # Hot path: ASCII digit (the most common leaf). Dispatch
2444 # straight to parse_number_or_datetime without hitting the
2445 # other typed-leaf branches.
2446 0 ▶ if ($c ge '0' && $c le '9') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c ge 0 and $c le 9) 0 0 0
Condition0%0/3
$c ge 0 and $c le 9
!ll&&!rl&&r
000
MC/DC0%0/2
$c ge 0 and $c le 9
$c ge 0 $c le 9
Truth table0%0/3
A and B
A= $c ge 0B= $c le 9
ABresult
0X0
100
111
2447 0 return $self->parse_number_or_datetime;
2448 }
2449 0 ▶ if ($c eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\"") 0 0 0
2450 0 ▶ return $self->parse_heredoc_basic if $self->_starts_with('"""');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_starts_with("\"\"\"") 0 0 0
2451 # Basic is the emitter's default for strings — no record.
2452 0 return $self->parse_basic_string_value;
2453 }
2454 0 ▶ if ($c eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "'") 0 0 0
2455 0 ▶ return $self->parse_heredoc_literal if $self->_starts_with("'''");
Branch: 1 branch
BranchTrueFalseTotal
if $self->_starts_with("'''") 0 0 0
2456 0 my $r = $self->parse_literal_string_value;
2457 0 $self->_record_form({ string_form => { kind => 'literal' } });
2458 0 return $r;
2459 }
2460 0 ▶ return $self->parse_flow_array if $c eq '[';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "[" 0 0 0
2461 0 ▶ return $self->parse_flow_table if $c eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "{" 0 0 0
2462 0 ▶ return $self->parse_bool_value if $c eq 't' || $c eq 'f';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "t" or $c eq "f" 0 0 0
Condition0%0/3
$c eq "t" or $c eq "f"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "t" or $c eq "f"
$c eq "t" $c eq "f"
Truth table0%0/3
A or B
A= $c eq "t"B= $c eq "f"
ABresult
1X1
011
000
2463 0 ▶ return $self->parse_inf_value if $c eq 'i';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "i" 0 0 0
2464 0 ▶ return $self->parse_nan_value if $c eq 'n';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "n" 0 0 0
2465 0 ▶ return $self->parse_number_or_datetime if $c eq '+' || $c eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "+" or $c eq "-" 0 0 0
Condition0%0/3
$c eq "+" or $c eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "+" or $c eq "-"
$c eq "+" $c eq "-"
Truth table0%0/3
A or B
A= $c eq "+"B= $c eq "-"
ABresult
1X1
011
000
2466 }
2467 0 ▶ $self->_die("expected value") if !defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
2468 0 $self->_die("unexpected character '$c' in value");
2469 }
2470  
2471 0 ▶sub parse_bool_value {
Subroutine parse_bool_value: not called CC=5 SCAR=34.0
Pod undocumented
2472 0 my $self = shift;
2473 0 ▶ if ($self->_starts_with("true") && _is_value_terminator($self->_peek_at(4))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_starts_with("true") and _is_value_terminator($self->_peek_at(4))) 0 0 0
Condition0%0/3
$self->_starts_with("true") and _is_value_terminator($self->_peek_at(4))
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_starts_with("true") and _is_value_terminator($self->_peek_at(4))
$self->_starts_with("true") _is_value_terminator($self->_peek_at(4))
Truth table0%0/3
A and B
A= $self->_starts_with("true")B= _is_value_terminator($self->_peek_at(4))
ABresult
0X0
100
111
2474 0 $self->{pos} += 4;
2475 0 return DMS::Parser::Bool->new(1);
2476 }
2477 0 ▶ if ($self->_starts_with("false") && _is_value_terminator($self->_peek_at(5))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_starts_with("false") and _is_value_terminator($self->_peek_at(5))) 0 0 0
Condition0%0/3
$self->_starts_with("false") and _is_value_terminator($self->_peek_at(5))
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_starts_with("false") and _is_value_terminator($self->_peek_at(5))
$self->_starts_with("false") _is_value_terminator($self->_peek_at(5))
Truth table0%0/3
A and B
A= $self->_starts_with("false")B= _is_value_terminator($self->_peek_at(5))
ABresult
0X0
100
111
2478 0 $self->{pos} += 5;
2479 0 return DMS::Parser::Bool->new(0);
2480 }
2481 0 $self->_die("expected value");
2482 }
2483  
2484 0 ▶sub parse_inf_value {
Subroutine parse_inf_value: not called CC=3 SCAR=24.8
Pod undocumented
2485 0 my $self = shift;
2486 0 ▶ if ($self->_starts_with("inf") && _is_value_terminator($self->_peek_at(3))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_starts_with("inf") and _is_value_terminator($self->_peek_at(3))) 0 0 0
Condition0%0/3
$self->_starts_with("inf") and _is_value_terminator($self->_peek_at(3))
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_starts_with("inf") and _is_value_terminator($self->_peek_at(3))
$self->_starts_with("inf") _is_value_terminator($self->_peek_at(3))
Truth table0%0/3
A and B
A= $self->_starts_with("inf")B= _is_value_terminator($self->_peek_at(3))
ABresult
0X0
100
111
2487 0 $self->{pos} += 3;
2488 0 return DMS::Parser::Float->new(9**9**9);
2489 }
2490 0 $self->_die("expected 'inf'");
2491 }
2492  
2493 0 ▶sub parse_nan_value {
Subroutine parse_nan_value: not called CC=3 SCAR=24.8
Pod undocumented
2494 0 my $self = shift;
2495 0 ▶ if ($self->_starts_with("nan") && _is_value_terminator($self->_peek_at(3))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_starts_with("nan") and _is_value_terminator($self->_peek_at(3))) 0 0 0
Condition0%0/3
$self->_starts_with("nan") and _is_value_terminator($self->_peek_at(3))
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_starts_with("nan") and _is_value_terminator($self->_peek_at(3))
$self->_starts_with("nan") _is_value_terminator($self->_peek_at(3))
Truth table0%0/3
A and B
A= $self->_starts_with("nan")B= _is_value_terminator($self->_peek_at(3))
ABresult
0X0
100
111
2496 0 $self->{pos} += 3;
2497 0 return DMS::Parser::Float->new(-(9**9**9) + (9**9**9));
2498 }
2499 0 $self->_die("expected 'nan'");
2500 }
2501  
2502 0 ▶sub parse_number_or_datetime {
Subroutine parse_number_or_datetime: not called CC=19 SCAR=59.4
Pod undocumented
2503 0 my $self = shift;
2504 0 my $base = $self->{pos};
2505 0 my $len_src = $self->{len};
2506 # Combined hot-path: a plain decimal integer that doesn't look like
2507 # a date or time. One regex bite scans the token; a structural
2508 # check rejects anything _parse_integer would die on. This single
2509 # branch is taken by every leaf in flat-data benchmarks.
2510 0 pos($self->{src}) = $base;
2511 0 ▶ if ($self->{src} =~ /\G(0|[1-9][0-9]{0,17})(?![\d_.eExob:-])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G(0|[1-9][0-9]{0,17})(?![\d_.eExob:-])/g) 0 0 0
2512 0 my $tok = $1;
2513 0 $self->{pos} = $base + length($tok);
2514 0 my $iv = 0 + $tok;
2515 0 return bless \$iv, 'DMS::Parser::Integer';
2516 }
2517 # Inline first-char peek: avoid the function-call + substr in _peek.
2518 0 my $first = substr($self->{src}, $base, 1);
2519 0 ▶ my $starts_sign = ($first eq '+' || $first eq '-');
Condition0%0/3
$first eq '+' || $first eq '-'
l!l&&r!l&&!r
000
MC/DC0%0/2
$first eq '+' || $first eq '-'
$first eq '+' $first eq '-'
Truth table0%0/3
A || B
A= $first eq '+'B= $first eq '-'
ABresult
1X1
011
000
2520 0 ▶ if (!$starts_sign) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($starts_sign) 0 0 0
2521 # Combined date/time-prefix sniff, regex-only. Skips _looks_like_*
2522 # which themselves do another substr+regex.
2523 0 pos($self->{src}) = $base;
2524 0 ▶ if ($len_src - $base >= 10 && $self->{src} =~ /\G\d\d\d\d-\d\d-\d\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_src - $base >= 10 and $self->{"src"} =~ /\G\d\d\d\d-\d\d-\d\d/) 0 0 0
Condition0%0/3
$len_src - $base >= 10 and $self->{"src"} =~ /\G\d\d\d\d-\d\d-\d\d/
!ll&&!rl&&r
000
MC/DC0%0/2
$len_src - $base >= 10 and $self->{"src"} =~ /\G\d\d\d\d-\d\d-\d\d/
$len_src - $base >= 10 $self->{"src"} =~ /\G\d\d\d\d-\d\d-\d\d/
Truth table0%0/3
A and B
A= $len_src - $base >= 10B= $self->{"src"} =~ /\G\d\d\d\d-\d\d-\d\d/
ABresult
0X0
100
111
2525 0 return $self->parse_datetime_value;
2526 }
2527 0 ▶ if ($len_src - $base >= 8 && $self->{src} =~ /\G\d\d:\d\d:\d\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_src - $base >= 8 and $self->{"src"} =~ /\G\d\d:\d\d:\d\d/) 0 0 0
Condition0%0/3
$len_src - $base >= 8 and $self->{"src"} =~ /\G\d\d:\d\d:\d\d/
!ll&&!rl&&r
000
MC/DC0%0/2
$len_src - $base >= 8 and $self->{"src"} =~ /\G\d\d:\d\d:\d\d/
$len_src - $base >= 8 $self->{"src"} =~ /\G\d\d:\d\d:\d\d/
Truth table0%0/3
A and B
A= $len_src - $base >= 8B= $self->{"src"} =~ /\G\d\d:\d\d:\d\d/
ABresult
0X0
100
111
2528 0 return $self->parse_local_time_value;
2529 }
2530 }
2531 0 ▶ if ($starts_sign && substr($self->{src}, $base + 1, 3) eq 'inf') {
Branch: 1 branch
BranchTrueFalseTotal
if ($starts_sign and substr($self->{"src"}, $base + 1, 3) eq "inf") 0 0 0
Condition0%0/3
$starts_sign and substr($self->{"src"}, $base + 1, 3) eq "inf"
!ll&&!rl&&r
000
MC/DC0%0/2
$starts_sign and substr($self->{"src"}, $base + 1, 3) eq "inf"
$starts_sign substr($self->{"src"}, $base + 1, 3) eq "inf"
Truth table0%0/3
A and B
A= $starts_signB= substr($self->{"src"}, $base + 1, 3) eq "inf"
ABresult
0X0
100
111
2532 0 my $p4 = $base + 4;
2533 0 ▶ my $next = $p4 >= $len_src ? undef : substr($self->{src}, $p4, 1);
Branch: 1 branch
BranchTrueFalseTotal
$p4 >= $len_src ? : 0 0 0
2534 0 ▶ if (_is_value_terminator($next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_value_terminator($next)) 0 0 0
2535 0 my $neg = $first eq '-';
2536 0 $self->{pos} += 4;
2537 0 ▶ return DMS::Parser::Float->new($neg ? -(9**9**9) : 9**9**9);
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 0 0 0
2538 }
2539 }
2540 0 my ($len, $is_float) = $self->_scan_number_token;
2541 0 my $s = substr($self->{src}, $base, $len);
2542 0 ▶ if ($is_float) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_float) 0 0 0
2543 0 my $f;
2544 0 eval { $f = _parse_float_val($s); };
2545 0 ▶ $self->_die("invalid float: $s ($@)") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
2546 0 $self->{pos} += $len;
2547 0 return DMS::Parser::Float->new($f);
2548 }
2549 # Fast path: plain decimal (no sign, no leading-0, fits in 18 digits)
2550 # never dies — skip the eval frame entirely. The validating regex
2551 # rejects anything _parse_integer would error on. Bless inline to
2552 # avoid a method call per leaf.
2553 0 ▶ if ($s =~ /\A(?:0|[1-9][0-9]{0,17})\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\A(?:0|[1-9][0-9]{0,17})\z/) 0 0 0
2554 0 $self->{pos} += $len;
2555 0 my $iv = 0 + $s;
2556 0 return bless \$iv, 'DMS::Parser::Integer';
2557 }
2558 0 my $n;
2559 0 eval { $n = _parse_integer($s); };
2560 0 ▶ if ($@) { my $msg = $@; $msg =~ s/\n.*//s; $self->_die($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2561 0 $self->{pos} += $len;
2562 # Record original lexeme when it differs from the canonical
2563 # "decimal, no underscores, no '+' sign" form the default emitter
2564 # would produce. Hex/oct/bin, underscores, explicit '+' → recorded.
2565 # Skipped entirely in lite mode (record_forms gate inside _record_form).
2566 0 ▶ if (!$self->{lite} && $s ne $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"lite"} and $s ne $n) 0 0 0
Condition0%0/3
not $self->{"lite"} and $s ne $n
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"lite"} and $s ne $n
not $self->{"lite"} $s ne $n
Truth table0%0/3
not(A) and B
A= not $self->{"lite"}B= $s ne $n
ABresult
0X0
100
111
2567 0 $self->_record_form({ integer_lit => $s });
2568 }
2569 0 return DMS::Parser::Integer->new($n);
2570 }
2571  
2572 0 ▶sub _scan_number_token {
Subroutine _scan_number_token: not called CC=7 SCAR=40.3
2573 0 my $self = shift;
2574 0 my $base = $self->{pos};
2575 0 pos($self->{src}) = $base;
2576 # Fast path: plain decimal integer (no sign, no '.' / 'e' / 'x' /
2577 # 'o' / 'b' prefix continuation). Most leaves in flat data are like
2578 # this — skip the heavy alternation and avoid the post-scan token
2579 # re-classification. The negative lookahead must reject anything
2580 # that would extend the token under the slow grammar (digits, '_',
2581 # '.', 'e'/'E', and the 0x/0o/0b prefix indicators).
2582 0 ▶ if ($self->{src} =~ /\G(\d+)(?![\d_.eExob])/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G(\d+)(?![\d_.eExob])/g) 0 0 0
2583 0 return (length($1), 0);
2584 }
2585 # One regex covers both prefixed (0x/0o/0b) and decimal forms. Behavior
2586 # mirrors the per-char loop: the prefix branch accepts hex digits +
2587 # underscores with at most one '.' and one 'p[+-]?' exponent; the
2588 # decimal branch accepts digits + underscores with at most one '.' and
2589 # one 'e[+-]?' exponent.
2590 0 pos($self->{src}) = $base;
2591 0 $self->{src} =~ m{
2592 \G [+-]?
2593 (?:
2594 0[xob] [0-9a-fA-F_]* (?: \. [0-9a-fA-F_]* )? (?: p [+-]? \d* )?
2595 | [\d_]* (?: \. [\d_]* )? (?: [eE] [+-]? \d* )?
2596 )
2597 }gxc;
2598 0 my $end = pos($self->{src});
2599 0 ▶ $end = $base unless defined $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 0 0
2600 0 my $len = $end - $base;
2601 0 ▶ return (0, 0) if $len == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len == 0 0 0 0
2602 0 my $tok = substr($self->{src}, $base, $len);
2603 # In prefixed (0x/0o/0b) tokens 'e' is a hex digit, not an exponent —
2604 # only '.' or 'p' make the token a float there.
2605 0 ▶ if ($tok =~ /^[+-]?0[xob]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok =~ /^[+-]?0[xob]/) 0 0 0
2606 0 ▶ return ($len, $tok =~ /[.p]/ ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ /[.p]/ ? : 0 0 0
2607 }
2608 0 ▶ return ($len, $tok =~ /[.eE]/ ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ /[.eE]/ ? : 0 0 0
2609 }
2610  
2611 0 ▶sub _valid_underscores {
Subroutine _valid_underscores: not called CC=7 SCAR=40.3
2612 0 my ($s) = @_;
2613 0 ▶ return 1 if length($s) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $s == 0 0 0 0
2614 0 ▶ return 0 if substr($s,0,1) eq '_' || substr($s,-1,1) eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if substr($s, 0, 1) eq "_" or substr($s, -1, 1) eq "_" 0 0 0
Condition0%0/3
substr($s, 0, 1) eq "_" or substr($s, -1, 1) eq "_"
l!l&&r!l&&!r
000
MC/DC0%0/2
substr($s, 0, 1) eq "_" or substr($s, -1, 1) eq "_"
substr($s, 0, 1) eq "_" substr($s, -1, 1) eq "_"
Truth table0%0/3
A or B
A= substr($s, 0, 1) eq "_"B= substr($s, -1, 1) eq "_"
ABresult
1X1
011
000
2615 0 my $prev = 0;
2616 0 for my $c (split //, $s) {
2617 0 ▶ if ($c eq '_') { return 0 if $prev; $prev = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq '_') { } 0 0 0
if $prev 0 0 0
2618 0 else { $prev = 0; }
2619 }
2620 0 return 1;
2621 }
2622  
2623 # Returns the canonical decimal string for an DMS integer literal. The hot
2624 # path (decimal, no underscores, fits in i64) avoids Math::BigInt entirely
2625 # because BigInt construction/arithmetic dominates the parser otherwise.
2626 # Errors mirror the old Math::BigInt-based implementation byte-for-byte.
2627 0 ▶sub _parse_integer {
Subroutine _parse_integer: not called CC=52 SCAR=79.2
2628 0 my ($s) = @_;
2629 # Hot path: a plain decimal token (no sign, no leading zero, no
2630 # underscore, fits in 18 chars i.e. always within i64). Covers the
2631 # vast majority of real-world keys/leaves and skips ~10 substr +
2632 # length checks below.
2633 0 ▶ if ($s =~ /\A(?:0|[1-9][0-9]{0,17})\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\A(?:0|[1-9][0-9]{0,17})\z/) 0 0 0
2634 0 return $s;
2635 }
2636 0 my $sign_str = '';
2637 0 my $is_neg = 0;
2638 0 my $rest = $s;
2639 0 my $first = substr($rest, 0, 1);
2640 0 ▶ if ($first eq '-') { $sign_str = '-'; $is_neg = 1; $rest = substr($rest, 1); }
Branch: 2 branches
BranchTrueFalseTotal
if ($first eq '-') { } 0 0 0
elsif ($first eq '+') { } 0 0 0
2641 0 elsif ($first eq '+') { $rest = substr($rest, 1); }
2642 0 ▶ die "hex prefix must be lowercase '0x'\n" if substr($rest, 0, 2) eq '0X';
Branch: 1 branch
BranchTrueFalseTotal
if substr($rest, 0, 2) eq "0X" 0 0 0
2643 0 my $radix = 10;
2644 0 my $body = $rest;
2645 0 ▶ if (length($rest) >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $rest >= 2) 0 0 0
2646 0 my $p2 = substr($rest, 0, 2);
2647 0 ▶ if ($p2 eq '0x') { $radix = 16; $body = substr($rest, 2); }
Branch: 3 branches
BranchTrueFalseTotal
if ($p2 eq '0x') { } 0 0 0
elsif ($p2 eq '0o') { } 0 0 0
elsif ($p2 eq '0b') { } 0 0 0
2648 0 elsif ($p2 eq '0o') { $radix = 8; $body = substr($rest, 2); }
2649 0 elsif ($p2 eq '0b') { $radix = 2; $body = substr($rest, 2); }
2650 }
2651 0 ▶ die "empty number\n" if length($body) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $body == 0 0 0 0
2652 0 ▶ die "underscore must be between digits\n"
Branch: 1 branch
BranchTrueFalseTotal
if substr($body, 0, 1) eq "_" or substr($body, -1, 1) eq "_" 0 0 0
Condition0%0/3
substr($body, 0, 1) eq "_" or substr($body, -1, 1) eq "_"
l!l&&r!l&&!r
000
MC/DC0%0/2
substr($body, 0, 1) eq "_" or substr($body, -1, 1) eq "_"
substr($body, 0, 1) eq "_" substr($body, -1, 1) eq "_"
Truth table0%0/3
A or B
A= substr($body, 0, 1) eq "_"B= substr($body, -1, 1) eq "_"
ABresult
1X1
011
000
2653 if substr($body, 0, 1) eq '_' || substr($body, -1, 1) eq '_';
2654 0 ▶ if ($radix == 10 && length($rest) > 1 && substr($rest, 0, 1) eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($radix == 10 and length $rest > 1 and substr($rest, 0, 1) eq 0) 0 0 0
Condition0%0/6
$radix == 10 and length $rest > 1 and substr($rest, 0, 1) eq 0
!ll&&!rl&&r
000
$radix == 10 and length $rest > 1
!ll&&!rl&&r
000
MC/DC0%0/3
$radix == 10 and length $rest > 1 and substr($rest, 0, 1) eq 0
$radix == 10 length $rest > 1 substr($rest, 0, 1) eq 0
Truth table0%0/4
A and B and C
A= $radix == 10B= length $rest > 1C= substr($rest, 0, 1) eq 0
ABCresult
0XX0
10X0
1100
1111
2655 0 die "leading zeros are not allowed on decimal integers\n";
2656 }
2657 0 ▶ die "underscore must be between digits\n" if index($body, '__') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($body, "__") != -1 0 0 0
2658 0 my $clean = $body;
2659 0 ▶ $clean =~ tr/_//d if index($clean, '_') >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($clean, "_") != -1 0 0 0
2660 0 ▶ if ($radix == 10) {
Branch: 3 branches
BranchTrueFalseTotal
if ($radix == 10) { } 0 0 0
elsif ($radix == 16) { } 0 0 0
elsif ($radix == 8) { } 0 0 0
2661 0 ▶ die "invalid digit for base 10\n" if $clean =~ /\D/;
Branch: 1 branch
BranchTrueFalseTotal
if $clean =~ /\D/ 0 0 0
2662 } elsif ($radix == 16) {
2663 0 ▶ die "invalid digit for base 16\n" if $clean =~ /[^0-9a-fA-F]/;
Branch: 1 branch
BranchTrueFalseTotal
if $clean =~ /[^0-9a-fA-F]/ 0 0 0
2664 } elsif ($radix == 8) {
2665 0 ▶ die "invalid digit for base 8\n" if $clean =~ /[^0-7]/;
Branch: 1 branch
BranchTrueFalseTotal
if $clean =~ /[^0-7]/ 0 0 0
2666 } else {
2667 0 ▶ die "invalid digit for base 2\n" if $clean =~ /[^01]/;
Branch: 1 branch
BranchTrueFalseTotal
if $clean =~ /[^01]/ 0 0 0
2668 }
2669  
2670 0 ▶ if ($radix == 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($radix == 10) 0 0 0
2671 # Strip leading zeros (keep at least one digit).
2672 0 $clean =~ s/^0+(?=\d)//;
2673 0 ▶ my $bound = $is_neg ? '9223372036854775808' : '9223372036854775807';
Branch: 1 branch
BranchTrueFalseTotal
$is_neg ? : 0 0 0
2674 0 ▶ die "integer out of i64 range\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $clean > length $bound or length $clean == length $bound and $clean gt $bound 0 0 0
Condition0%0/6
length $clean > length $bound or length $clean == length $bound and $clean gt $bound
l!l&&r!l&&!r
000
length $clean == length $bound and $clean gt $bound
!ll&&!rl&&r
000
MC/DC0%0/3
length $clean > length $bound or length $clean == length $bound and $clean gt $bound
length $clean > length $bound length $clean == length $bound $clean gt $bound
Truth table0%0/4
A or B and C
A= length $clean > length $boundB= length $clean == length $boundC= $clean gt $bound
ABCresult
1XX1
0111
00X0
0100
2675 if length($clean) > length($bound)
2676 || (length($clean) == length($bound) && $clean gt $bound);
2677 0 ▶ return '0' if $clean eq '0';
Branch: 1 branch
BranchTrueFalseTotal
if $clean eq 0 0 0 0
2678 0 return "${sign_str}${clean}";
2679 }
2680  
2681 # Non-decimal: cap by max digit count for i64 magnitude.
2682 0 ▶ if ($radix == 16 && length($clean) > 16) { die "integer out of i64 range\n"; }
Branch: 3 branches
BranchTrueFalseTotal
if ($radix == 16 and length $clean > 16) { } 0 0 0
elsif ($radix == 8 and length $clean > 22) { } 0 0 0
elsif ($radix == 2 and length $clean > 64) { } 0 0 0
Condition0%0/3
$radix == 16 and length $clean > 16
!ll&&!rl&&r
000
MC/DC0%0/2
$radix == 16 and length $clean > 16
$radix == 16 length $clean > 16
Truth table0%0/3
A and B
A= $radix == 16B= length $clean > 16
ABresult
0X0
100
111
2683 0 ▶ elsif ($radix == 8 && length($clean) > 22) { die "integer out of i64 range\n"; }
Condition0%0/3
$radix == 8 and length $clean > 22
!ll&&!rl&&r
000
MC/DC0%0/2
$radix == 8 and length $clean > 22
$radix == 8 length $clean > 22
Truth table0%0/3
A and B
A= $radix == 8B= length $clean > 22
ABresult
0X0
100
111
2684 0 ▶ elsif ($radix == 2 && length($clean) > 64) { die "integer out of i64 range\n"; }
Condition0%0/3
$radix == 2 and length $clean > 64
!ll&&!rl&&r
000
MC/DC0%0/2
$radix == 2 and length $clean > 64
$radix == 2 length $clean > 64
Truth table0%0/3
A and B
A= $radix == 2B= length $clean > 64
ABresult
0X0
100
111
2685  
2686 0 my $val_lc = lc $clean;
2687 # Detect magnitudes in the high half (>= 2^63) that don't fit a signed
2688 # 64-bit positive value. Allowed only as the exact i64 minimum: -2^63.
2689 0 my $high_half = 0;
2690 0 ▶ if ($radix == 16) { $high_half = length($val_lc) == 16 && substr($val_lc, 0, 1) ge '8'; }
Branch: 2 branches
BranchTrueFalseTotal
if ($radix == 16) { } 0 0 0
elsif ($radix == 8) { } 0 0 0
Condition0%0/3
length $val_lc == 16 && substr($val_lc, 0, 1) ge '8'
!ll&&!rl&&r
000
MC/DC0%0/2
length $val_lc == 16 && substr($val_lc, 0, 1) ge '8'
length $val_lc == 16 substr($val_lc, 0, 1) ge '8'
Truth table0%0/3
A && B
A= length $val_lc == 16B= substr($val_lc, 0, 1) ge '8'
ABresult
0X0
100
111
2691 0 ▶ elsif ($radix == 8) { $high_half = length($val_lc) == 22 && substr($val_lc, 0, 1) gt '0'; }
Condition0%0/3
length $val_lc == 22 && substr($val_lc, 0, 1) gt '0'
!ll&&!rl&&r
000
MC/DC0%0/2
length $val_lc == 22 && substr($val_lc, 0, 1) gt '0'
length $val_lc == 22 substr($val_lc, 0, 1) gt '0'
Truth table0%0/3
A && B
A= length $val_lc == 22B= substr($val_lc, 0, 1) gt '0'
ABresult
0X0
100
111
2692 0 ▶ else { $high_half = length($val_lc) == 64 && substr($val_lc, 0, 1) eq '1'; }
Condition0%0/3
length $val_lc == 64 && substr($val_lc, 0, 1) eq '1'
!ll&&!rl&&r
000
MC/DC0%0/2
length $val_lc == 64 && substr($val_lc, 0, 1) eq '1'
length $val_lc == 64 substr($val_lc, 0, 1) eq '1'
Truth table0%0/3
A && B
A= length $val_lc == 64B= substr($val_lc, 0, 1) eq '1'
ABresult
0X0
100
111
2693 0 ▶ if ($high_half) {
Branch: 1 branch
BranchTrueFalseTotal
if ($high_half) 0 0 0
2694 0 ▶ if ($is_neg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_neg) 0 0 0
2695 0 ▶ return '-9223372036854775808'
Branch: 1 branch
BranchTrueFalseTotal
if $radix == 16 and $val_lc eq "8000000000000000" or $radix == 8 and $val_lc eq "1000000000000000000000" or $radix == 2 and $val_lc eq "1000000000000000000000000000000000000000000000000000000000000000" 0 0 0
Condition0%0/15
$radix == 16 and $val_lc eq "8000000000000000" or $radix == 8 and $val_lc eq "1000000000000000000000" or $radix == 2 and $val_lc eq "1000000000000000000000000000000000000000000000000000000000000000"
l!l&&r!l&&!r
000
$radix == 16 and $val_lc eq "8000000000000000" or $radix == 8 and $val_lc eq "1000000000000000000000"
l!l&&r!l&&!r
000
$radix == 16 and $val_lc eq "8000000000000000"
!ll&&!rl&&r
000
$radix == 8 and $val_lc eq "1000000000000000000000"
!ll&&!rl&&r
000
$radix == 2 and $val_lc eq "1000000000000000000000000000000000000000000000000000000000000000"
!ll&&!rl&&r
000
MC/DC0%0/6
$radix == 16 and $val_lc eq "8000000000000000" or $radix == 8 and $val_lc eq "1000000000000000000000" or $radix == 2 and $val_lc eq "1000000000000000000000000000000000000000000000000000000000000000"
$radix == 16 $val_lc eq "8000000000000000" $radix == 8 $val_lc eq "1000000000000000000000" $radix == 2 $val_lc eq "1000000000000000000000000000000000000000000000000000000000000000"
Truth table0%0/15
A and B or C and D or E and F
A= $radix == 16B= $val_lc eq "8000000000000000"C= $radix == 8D= $val_lc eq "1000000000000000000000"E= $radix == 2F= $val_lc eq "1000000000000000000000000000000000000000000000000000000000000000"
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
2696 if ($radix == 16 && $val_lc eq '8000000000000000')
2697 || ($radix == 8 && $val_lc eq '1000000000000000000000')
2698 || ($radix == 2 && $val_lc eq '1' . ('0' x 63));
2699 }
2700 0 die "integer out of i64 range\n";
2701 }
2702  
2703 0 my $native;
2704 0 ▶ if ($radix == 16) { $native = hex($val_lc); }
Branch: 2 branches
BranchTrueFalseTotal
if ($radix == 16) { } 0 0 0
elsif ($radix == 8) { } 0 0 0
2705 0 elsif ($radix == 8) { $native = oct("0$val_lc"); }
2706 0 else { $native = oct("0b$val_lc"); }
2707 0 ▶ return '0' if $native == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $native == 0 0 0 0
2708 0 return "${sign_str}$native";
2709 }
2710  
2711 0 ▶sub _parse_float_val {
Subroutine _parse_float_val: not called CC=6 SCAR=37.4
2712 0 my ($s) = @_;
2713 0 my $sign = 1.0;
2714 0 my $rest = $s;
2715 0 ▶ if (substr($rest,0,1) eq '-') { $sign = -1.0; $rest = substr($rest, 1); }
Branch: 2 branches
BranchTrueFalseTotal
if (substr($rest, 0, 1) eq '-') { } 0 0 0
elsif (substr($rest, 0, 1) eq '+') { } 0 0 0
2716 0 elsif (substr($rest,0,1) eq '+') { $rest = substr($rest, 1); }
2717 0 ▶ if (substr($rest,0,2) eq '0x' || substr($rest,0,2) eq '0o' || substr($rest,0,2) eq '0b') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($rest, 0, 2) eq "0x" or substr($rest, 0, 2) eq "0o" or substr($rest, 0, 2) eq "0b") 0 0 0
Condition0%0/6
substr($rest, 0, 2) eq "0x" or substr($rest, 0, 2) eq "0o" or substr($rest, 0, 2) eq "0b"
l!l&&r!l&&!r
000
substr($rest, 0, 2) eq "0x" or substr($rest, 0, 2) eq "0o"
l!l&&r!l&&!r
000
MC/DC0%0/3
substr($rest, 0, 2) eq "0x" or substr($rest, 0, 2) eq "0o" or substr($rest, 0, 2) eq "0b"
substr($rest, 0, 2) eq "0x" substr($rest, 0, 2) eq "0o" substr($rest, 0, 2) eq "0b"
Truth table0%0/4
A or B or C
A= substr($rest, 0, 2) eq "0x"B= substr($rest, 0, 2) eq "0o"C= substr($rest, 0, 2) eq "0b"
ABCresult
1XX1
01X1
0011
0000
2718 0 return $sign * _parse_nondec_float($rest);
2719 }
2720 0 return $sign * _parse_dec_float($rest);
2721 }
2722  
2723 0 ▶sub _parse_dec_float {
Subroutine _parse_dec_float: not called CC=18 SCAR=58.3
2724 0 my ($s) = @_;
2725 0 my $e_idx = -1;
2726 0 ▶ for (my $i = 0; $i < length($s); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $s) 0 0 0
2727 0 my $c = substr($s, $i, 1);
2728 0 ▶ if ($c eq 'e' || $c eq 'E') { $e_idx = $i; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "e" or $c eq "E") 0 0 0
Condition0%0/3
$c eq "e" or $c eq "E"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "e" or $c eq "E"
$c eq "e" $c eq "E"
Truth table0%0/3
A or B
A= $c eq "e"B= $c eq "E"
ABresult
1X1
011
000
2729 }
2730 0 ▶ my $m = $e_idx == -1 ? $s : substr($s, 0, $e_idx);
Branch: 1 branch
BranchTrueFalseTotal
$e_idx == -1 ? : 0 0 0
2731 0 ▶ my $e = $e_idx == -1 ? undef : substr($s, $e_idx+1);
Branch: 1 branch
BranchTrueFalseTotal
$e_idx == -1 ? : 0 0 0
2732 0 ▶ die "decimal float requires '.'\n" if index($m, '.') < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($m, ".") == -1 0 0 0
2733 0 my @parts = split /\./, $m, 2;
2734 0 ▶ die "decimal float requires digit on both sides of '.'\n"
Branch: 1 branch
BranchTrueFalseTotal
if @parts != 2 or $parts[0] eq "" or $parts[1] eq "" 0 0 0
Condition0%0/6
@parts != 2 or $parts[0] eq "" or $parts[1] eq ""
l!l&&r!l&&!r
000
@parts != 2 or $parts[0] eq ""
l!l&&r!l&&!r
000
MC/DC0%0/3
@parts != 2 or $parts[0] eq "" or $parts[1] eq ""
@parts != 2 $parts[0] eq "" $parts[1] eq ""
Truth table0%0/4
A or B or C
A= @parts != 2B= $parts[0] eq ""C= $parts[1] eq ""
ABCresult
1XX1
01X1
0011
0000
2735 if @parts != 2 || $parts[0] eq '' || $parts[1] eq '';
2736 0 ▶ die "invalid character in mantissa\n" if $parts[0] =~ /[^\d_]/;
Branch: 1 branch
BranchTrueFalseTotal
if $parts[0] =~ /[^\d_]/ 0 0 0
2737 0 ▶ die "invalid character in mantissa\n" if $parts[1] =~ /[^\d_]/;
Branch: 1 branch
BranchTrueFalseTotal
if $parts[1] =~ /[^\d_]/ 0 0 0
2738 0 ▶ die "bad underscore in mantissa\n"
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_underscores($parts[0]) and _valid_underscores($parts[1]) 0 0 0
Condition0%0/3
_valid_underscores($parts[0]) and _valid_underscores($parts[1])
!ll&&!rl&&r
000
MC/DC0%0/2
_valid_underscores($parts[0]) and _valid_underscores($parts[1])
_valid_underscores($parts[0]) _valid_underscores($parts[1])
Truth table0%0/3
A and B
A= _valid_underscores($parts[0])B= _valid_underscores($parts[1])
ABresult
0X0
100
111
2739 unless _valid_underscores($parts[0]) && _valid_underscores($parts[1]);
2740 0 my $full = $parts[0]; $full =~ s/_//g; $full .= '.';
2741 0 my $frac = $parts[1]; $frac =~ s/_//g; $full .= $frac;
2742 0 ▶ if (defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e) 0 0 0
2743 0 my $e_clean = $e; $e_clean =~ s/^[+-]//;
2744 0 ▶ die "underscore not allowed in exponent\n" if $e_clean =~ /_/;
Branch: 1 branch
BranchTrueFalseTotal
if $e_clean =~ /_/ 0 0 0
2745 0 ▶ die "invalid character in exponent\n" if $e =~ /[^\d+-]/;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /[^\d+-]/ 0 0 0
2746 0 ▶ die "empty exponent\n" if $e_clean eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $e_clean eq "" 0 0 0
2747 0 $full .= 'e' . $e;
2748 }
2749 0 return 0 + $full;
2750 }
2751  
2752 0 ▶sub _parse_nondec_float {
Subroutine _parse_nondec_float: not called CC=19 SCAR=59.4
2753 0 my ($s) = @_;
2754 0 my ($radix, $rest);
2755 0 ▶ if (substr($s,0,2) eq '0x') { $radix = 16; $rest = substr($s,2); }
Branch: 3 branches
BranchTrueFalseTotal
if (substr($s, 0, 2) eq '0x') { } 0 0 0
elsif (substr($s, 0, 2) eq '0o') { } 0 0 0
elsif (substr($s, 0, 2) eq '0b') { } 0 0 0
2756 0 elsif (substr($s,0,2) eq '0o') { $radix = 8; $rest = substr($s,2); }
2757 0 elsif (substr($s,0,2) eq '0b') { $radix = 2; $rest = substr($s,2); }
2758 0 else { die "non-decimal float prefix required\n"; }
2759 0 my $p_idx = index($rest, 'p');
2760 0 ▶ die "non-decimal float requires 'p' exponent\n" if $p_idx < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p_idx < 0 0 0 0
2761 0 my $mant = substr($rest, 0, $p_idx);
2762 0 my $exp_str = substr($rest, $p_idx+1);
2763 0 ▶ die "empty exponent\n" if $exp_str eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $exp_str eq "" 0 0 0
2764 0 ▶ die "underscore not allowed in exponent\n" if $exp_str =~ /_/;
Branch: 1 branch
BranchTrueFalseTotal
if $exp_str =~ /_/ 0 0 0
2765 0 ▶ die "invalid exponent character\n" if $exp_str =~ /[^\d+-]/;
Branch: 1 branch
BranchTrueFalseTotal
if $exp_str =~ /[^\d+-]/ 0 0 0
2766 0 my $exp = int($exp_str);
2767 0 my ($ip, $fp);
2768 0 ▶ if (index($mant, '.') >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($mant, '.') != -1) { } 0 0 0
2769 0 ($ip, $fp) = split /\./, $mant, 2;
2770 0 ▶ die "digit required on both sides of '.'\n" if $ip eq '' || $fp eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $ip eq "" or $fp eq "" 0 0 0
Condition0%0/3
$ip eq "" or $fp eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
$ip eq "" or $fp eq ""
$ip eq "" $fp eq ""
Truth table0%0/3
A or B
A= $ip eq ""B= $fp eq ""
ABresult
1X1
011
000
2771 } else {
2772 0 $ip = $mant; $fp = '';
2773 }
2774 0 ▶ die "bad underscore\n" unless _valid_underscores($ip) && _valid_underscores($fp);
Branch: 1 branch
BranchTrueFalseTotal
unless _valid_underscores($ip) and _valid_underscores($fp) 0 0 0
Condition0%0/3
_valid_underscores($ip) and _valid_underscores($fp)
!ll&&!rl&&r
000
MC/DC0%0/2
_valid_underscores($ip) and _valid_underscores($fp)
_valid_underscores($ip) _valid_underscores($fp)
Truth table0%0/3
A and B
A= _valid_underscores($ip)B= _valid_underscores($fp)
ABresult
0X0
100
111
2775 0 $ip =~ s/_//g; $fp =~ s/_//g;
2776 0 my $digit_chars = substr("0123456789abcdef", 0, $radix);
2777 0 for my $c (split //, $ip) {
2778 0 ▶ die "invalid digit for base $radix\n" if index($digit_chars, lc $c) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($digit_chars, lc $c) == -1 0 0 0
2779 }
2780 0 for my $c (split //, $fp) {
2781 0 ▶ die "invalid digit for base $radix\n" if index($digit_chars, lc $c) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($digit_chars, lc $c) == -1 0 0 0
2782 }
2783 0 ▶ my $int_val = $ip eq '' ? 0 : hex_to_int($ip, $radix);
Branch: 1 branch
BranchTrueFalseTotal
$ip eq '' ? : 0 0 0
2784 0 my $frac_val = 0.0;
2785 0 my $div = $radix * 1.0;
2786 0 for my $c (split //, $fp) {
2787 0 my $d = index("0123456789abcdef", lc $c);
2788 0 $frac_val += $d / $div;
2789 0 $div *= $radix;
2790 }
2791 0 return ($int_val + $frac_val) * (2 ** $exp);
2792 }
2793  
2794 0 ▶sub hex_to_int {
Subroutine hex_to_int: not called CC=2 SCAR=17.9
Pod undocumented
2795 0 my ($s, $radix) = @_;
2796 0 my $v = 0;
2797 0 for my $c (split //, $s) {
2798 0 $v = $v * $radix + index("0123456789abcdef", lc $c);
2799 }
2800 0 return $v;
2801 }
2802  
2803 0 ▶sub _days_in_month {
Subroutine _days_in_month: not called CC=16 SCAR=56.1
2804 0 my ($y, $m) = @_;
2805 0 ▶ return 31 if $m == 1 || $m == 3 || $m == 5 || $m == 7 || $m == 8 || $m == 10 || $m == 12;
Branch: 1 branch
BranchTrueFalseTotal
if $m == 1 or $m == 3 or $m == 5 or $m == 7 or $m == 8 or $m == 10 or $m == 12 0 0 0
Condition0%0/18
$m == 1 or $m == 3 or $m == 5 or $m == 7 or $m == 8 or $m == 10 or $m == 12
l!l&&r!l&&!r
000
$m == 1 or $m == 3 or $m == 5 or $m == 7 or $m == 8 or $m == 10
l!l&&r!l&&!r
000
$m == 1 or $m == 3 or $m == 5 or $m == 7 or $m == 8
l!l&&r!l&&!r
000
$m == 1 or $m == 3 or $m == 5 or $m == 7
l!l&&r!l&&!r
000
$m == 1 or $m == 3 or $m == 5
l!l&&r!l&&!r
000
$m == 1 or $m == 3
l!l&&r!l&&!r
000
MC/DC0%0/7
$m == 1 or $m == 3 or $m == 5 or $m == 7 or $m == 8 or $m == 10 or $m == 12
$m == 1 $m == 3 $m == 5 $m == 7 $m == 8 $m == 10 $m == 12
Truth table0%0/8
A or B or C or D or E or F or G
A= $m == 1B= $m == 3C= $m == 5D= $m == 7E= $m == 8F= $m == 10G= $m == 12
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
2806 0 ▶ return 30 if $m == 4 || $m == 6 || $m == 9 || $m == 11;
Branch: 1 branch
BranchTrueFalseTotal
if $m == 4 or $m == 6 or $m == 9 or $m == 11 0 0 0
Condition0%0/9
$m == 4 or $m == 6 or $m == 9 or $m == 11
l!l&&r!l&&!r
000
$m == 4 or $m == 6 or $m == 9
l!l&&r!l&&!r
000
$m == 4 or $m == 6
l!l&&r!l&&!r
000
MC/DC0%0/4
$m == 4 or $m == 6 or $m == 9 or $m == 11
$m == 4 $m == 6 $m == 9 $m == 11
Truth table0%0/5
A or B or C or D
A= $m == 4B= $m == 6C= $m == 9D= $m == 11
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2807 0 ▶ if ($m == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m == 2) 0 0 0
2808 0 ▶ return ((($y % 4 == 0) && ($y % 100 != 0)) || ($y % 400 == 0)) ? 29 : 28;
Branch: 1 branch
BranchTrueFalseTotal
$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0 ? : 0 0 0
Condition0%0/6
$y % 4 == 0 and $y % 100 != 0 or $y % 400 == 0
l!l&&r!l&&!r
000
$y % 4 == 0 and $y % 100 != 0
!ll&&!rl&&r
000
MC/DC0%0/3
$y % 4 == 0 and $y % 100 != 0 or $y % 400 == 0
$y % 4 == 0 $y % 100 != 0 $y % 400 == 0
Truth table0%0/5
A and B or C
A= $y % 4 == 0B= $y % 100 != 0C= $y % 400 == 0
ABCresult
11X1
0X11
1011
0X00
1000
2809 }
2810 0 return 0;
2811 }
2812  
2813 0 ▶sub _validate_date {
Subroutine _validate_date: not called CC=10 SCAR=47.0
2814 0 my ($s) = @_;
2815 0 ▶ die "invalid date format\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $s != 10 or substr($s, 4, 1) ne "-" or substr($s, 7, 1) ne "-" 0 0 0
Condition0%0/6
length $s != 10 or substr($s, 4, 1) ne "-" or substr($s, 7, 1) ne "-"
l!l&&r!l&&!r
000
length $s != 10 or substr($s, 4, 1) ne "-"
l!l&&r!l&&!r
000
MC/DC0%0/3
length $s != 10 or substr($s, 4, 1) ne "-" or substr($s, 7, 1) ne "-"
length $s != 10 substr($s, 4, 1) ne "-" substr($s, 7, 1) ne "-"
Truth table0%0/4
A or B or C
A= length $s != 10B= substr($s, 4, 1) ne "-"C= substr($s, 7, 1) ne "-"
ABCresult
1XX1
01X1
0011
0000
2816 if length($s) != 10 || substr($s,4,1) ne '-' || substr($s,7,1) ne '-';
2817 0 for my $i (0,1,2,3,5,6,8,9) {
2818 0 ▶ die "date must be all digits\n" if substr($s,$i,1) !~ /\d/;
Branch: 1 branch
BranchTrueFalseTotal
unless substr($s, $i, 1) =~ /\d/ 0 0 0
2819 }
2820 0 my $y = int(substr($s,0,4));
2821 0 my $mo = int(substr($s,5,2));
2822 0 my $d = int(substr($s,8,2));
2823 0 ▶ die "month out of range\n" if $mo < 1 || $mo > 12;
Branch: 1 branch
BranchTrueFalseTotal
if $mo < 1 or $mo > 12 0 0 0
Condition0%0/3
$mo < 1 or $mo > 12
l!l&&r!l&&!r
000
MC/DC0%0/2
$mo < 1 or $mo > 12
$mo < 1 $mo > 12
Truth table0%0/3
A or B
A= $mo < 1B= $mo > 12
ABresult
1X1
011
000
2824 0 ▶ die "day out of range\n" if $d < 1 || $d > _days_in_month($y, $mo);
Branch: 1 branch
BranchTrueFalseTotal
if $d < 1 or $d > _days_in_month($y, $mo) 0 0 0
Condition0%0/3
$d < 1 or $d > _days_in_month($y, $mo)
l!l&&r!l&&!r
000
MC/DC0%0/2
$d < 1 or $d > _days_in_month($y, $mo)
$d < 1 $d > _days_in_month($y, $mo)
Truth table0%0/3
A or B
A= $d < 1B= $d > _days_in_month($y, $mo)
ABresult
1X1
011
000
2825 }
2826  
2827 0 ▶sub _validate_time {
Subroutine _validate_time: not called CC=9 SCAR=45.0
2828 0 my ($s) = @_;
2829 0 ▶ die "invalid time format\n"
Branch: 1 branch
BranchTrueFalseTotal
if length $s != 8 or substr($s, 2, 1) ne ":" or substr($s, 5, 1) ne ":" 0 0 0
Condition0%0/6
length $s != 8 or substr($s, 2, 1) ne ":" or substr($s, 5, 1) ne ":"
l!l&&r!l&&!r
000
length $s != 8 or substr($s, 2, 1) ne ":"
l!l&&r!l&&!r
000
MC/DC0%0/3
length $s != 8 or substr($s, 2, 1) ne ":" or substr($s, 5, 1) ne ":"
length $s != 8 substr($s, 2, 1) ne ":" substr($s, 5, 1) ne ":"
Truth table0%0/4
A or B or C
A= length $s != 8B= substr($s, 2, 1) ne ":"C= substr($s, 5, 1) ne ":"
ABCresult
1XX1
01X1
0011
0000
2830 if length($s) != 8 || substr($s,2,1) ne ':' || substr($s,5,1) ne ':';
2831 0 for my $i (0,1,3,4,6,7) {
2832 0 ▶ die "time must be all digits\n" if substr($s,$i,1) !~ /\d/;
Branch: 1 branch
BranchTrueFalseTotal
unless substr($s, $i, 1) =~ /\d/ 0 0 0
2833 }
2834 0 my $h = int(substr($s,0,2));
2835 0 my $m = int(substr($s,3,2));
2836 0 my $sec = int(substr($s,6,2));
2837 0 ▶ die "hour out of range\n" if $h > 23;
Branch: 1 branch
BranchTrueFalseTotal
if $h > 23 0 0 0
2838 0 ▶ die "minute out of range\n" if $m > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $m > 59 0 0 0
2839 0 ▶ die "second out of range (leap seconds not supported)\n" if $sec > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $sec > 59 0 0 0
2840 }
2841  
2842 0 ▶sub parse_datetime_value {
Subroutine parse_datetime_value: not called CC=31 SCAR=69.0
Pod undocumented
2843 0 my $self = shift;
2844 0 my $rest = substr($self->{src}, $self->{pos});
2845 0 my $date = substr($rest, 0, 10);
2846 0 eval { _validate_date($date); };
2847 0 ▶ if ($@) { my $msg = $@; chomp $msg; $self->_die($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2848 0 my $rest2 = substr($rest, 10);
2849 0 ▶ if (substr($rest2,0,1) ne 'T' && substr($rest2,0,1) ne ' ') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($rest2, 0, 1) ne "T" and substr($rest2, 0, 1) ne " ") 0 0 0
Condition0%0/3
substr($rest2, 0, 1) ne "T" and substr($rest2, 0, 1) ne " "
!ll&&!rl&&r
000
MC/DC0%0/2
substr($rest2, 0, 1) ne "T" and substr($rest2, 0, 1) ne " "
substr($rest2, 0, 1) ne "T" substr($rest2, 0, 1) ne " "
Truth table0%0/3
A and B
A= substr($rest2, 0, 1) ne "T"B= substr($rest2, 0, 1) ne " "
ABresult
0X0
100
111
2850 0 ▶ if (substr($rest2,0,1) eq 't') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($rest2, 0, 1) eq "t") 0 0 0
2851 0 $self->_die("date and time separator must be uppercase 'T' (lowercase 't' not permitted)");
2852 }
2853 0 my $after = substr($rest2,0,1);
2854 0 ▶ $after = undef if $after eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $after eq "" 0 0 0
2855 0 ▶ $self->_die("invalid character after date") unless _is_value_terminator($after);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_value_terminator($after) 0 0 0
2856 0 $self->{pos} += 10;
2857 0 return DMS::Parser::LocalDate->new($date);
2858 }
2859 0 ▶ if (substr($rest2,0,1) eq ' ') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($rest2, 0, 1) eq " ") 0 0 0
2860 0 (my $after_ws = $rest2) =~ s/\A[ \t]+//;
2861 0 ▶ if (length($after_ws) > 0 && substr($after_ws, 0, 1) =~ /\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $after_ws > 0 and substr($after_ws, 0, 1) =~ /\d/) 0 0 0
Condition0%0/3
length $after_ws > 0 and substr($after_ws, 0, 1) =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
length $after_ws > 0 and substr($after_ws, 0, 1) =~ /\d/
length $after_ws > 0 substr($after_ws, 0, 1) =~ /\d/
Truth table0%0/3
A and B
A= length $after_ws > 0B= substr($after_ws, 0, 1) =~ /\d/
ABresult
0X0
100
111
2862 0 $self->_die("date and time must be separated by 'T' (space not permitted)");
2863 }
2864 0 $self->{pos} += 10;
2865 0 return DMS::Parser::LocalDate->new($date);
2866 }
2867 0 my $after_t = substr($rest2, 1);
2868 0 ▶ $self->_die("expected HH:MM:SS after 'T'") unless _looks_like_time_prefix($after_t);
Branch: 1 branch
BranchTrueFalseTotal
unless _looks_like_time_prefix($after_t) 0 0 0
2869 0 my $time_str = substr($after_t, 0, 8);
2870 0 eval { _validate_time($time_str); };
2871 0 ▶ if ($@) { my $msg = $@; chomp $msg; $self->_die($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2872 0 my $consumed = 10 + 1 + 8;
2873 0 my $after_time = substr($rest, $consumed);
2874 0 my $frac_len = 0;
2875 0 ▶ if (substr($after_time,0,1) eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($after_time, 0, 1) eq ".") 0 0 0
2876 0 my $k = 1;
2877 0 ▶ while ($k < length($after_time) && substr($after_time,$k,1) =~ /\d/) { $k++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($k < length $after_time and substr($after_time, $k, 1) =~ /\d/) 0 0 0
Condition0%0/3
$k < length $after_time and substr($after_time, $k, 1) =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
$k < length $after_time and substr($after_time, $k, 1) =~ /\d/
$k < length $after_time substr($after_time, $k, 1) =~ /\d/
Truth table0%0/3
A and B
A= $k < length $after_timeB= substr($after_time, $k, 1) =~ /\d/
ABresult
0X0
100
111
2878 0 my $digits = $k - 1;
2879 0 ▶ $self->_die("expected fractional digits after '.'") if $digits == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $digits == 0 0 0 0
2880 0 ▶ $self->_die("fractional seconds limited to 9 digits (nanosecond precision)") if $digits > 9;
Branch: 1 branch
BranchTrueFalseTotal
if $digits > 9 0 0 0
2881 0 $frac_len = $k;
2882 }
2883 0 $consumed += $frac_len;
2884 0 my $after_frac = substr($rest, $consumed);
2885 0 ▶ if (substr($after_frac,0,1) eq 'Z' || substr($after_frac,0,1) eq 'z') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($after_frac, 0, 1) eq "Z" or substr($after_frac, 0, 1) eq "z") 0 0 0
Condition0%0/3
substr($after_frac, 0, 1) eq "Z" or substr($after_frac, 0, 1) eq "z"
l!l&&r!l&&!r
000
MC/DC0%0/2
substr($after_frac, 0, 1) eq "Z" or substr($after_frac, 0, 1) eq "z"
substr($after_frac, 0, 1) eq "Z" substr($after_frac, 0, 1) eq "z"
Truth table0%0/3
A or B
A= substr($after_frac, 0, 1) eq "Z"B= substr($after_frac, 0, 1) eq "z"
ABresult
1X1
011
000
2886 0 $consumed += 1;
2887 0 my $s = substr($rest, 0, $consumed);
2888 0 $self->{pos} += $consumed;
2889 0 return DMS::Parser::OffsetDateTime->new($s);
2890 }
2891 0 ▶ if (substr($after_frac,0,1) eq '+' || substr($after_frac,0,1) eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($after_frac, 0, 1) eq "+" or substr($after_frac, 0, 1) eq "-") 0 0 0
Condition0%0/3
substr($after_frac, 0, 1) eq "+" or substr($after_frac, 0, 1) eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
substr($after_frac, 0, 1) eq "+" or substr($after_frac, 0, 1) eq "-"
substr($after_frac, 0, 1) eq "+" substr($after_frac, 0, 1) eq "-"
Truth table0%0/3
A or B
A= substr($after_frac, 0, 1) eq "+"B= substr($after_frac, 0, 1) eq "-"
ABresult
1X1
011
000
2892 0 ▶ if (length($after_frac) < 6
Branch: 1 branch
BranchTrueFalseTotal
if (length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/ or not substr($after_frac, 2, 1) =~ /\d/ or substr($after_frac, 3, 1) ne ":" or not substr($after_frac, 4, 1) =~ /\d/ or not substr($after_frac, 5, 1) =~ /\d/) 0 0 0
Condition0%0/15
length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/ or not substr($after_frac, 2, 1) =~ /\d/ or substr($after_frac, 3, 1) ne ":" or not substr($after_frac, 4, 1) =~ /\d/ or not substr($after_frac, 5, 1) =~ /\d/
l!l&&r!l&&!r
000
length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/ or not substr($after_frac, 2, 1) =~ /\d/ or substr($after_frac, 3, 1) ne ":" or not substr($after_frac, 4, 1) =~ /\d/
l!l&&r!l&&!r
000
length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/ or not substr($after_frac, 2, 1) =~ /\d/ or substr($after_frac, 3, 1) ne ":"
l!l&&r!l&&!r
000
length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/ or not substr($after_frac, 2, 1) =~ /\d/
l!l&&r!l&&!r
000
length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/
l!l&&r!l&&!r
000
MC/DC0%0/6
length $after_frac < 6 or not substr($after_frac, 1, 1) =~ /\d/ or not substr($after_frac, 2, 1) =~ /\d/ or substr($after_frac, 3, 1) ne ":" or not substr($after_frac, 4, 1) =~ /\d/ or not substr($after_frac, 5, 1) =~ /\d/
length $after_frac < 6 not substr($after_frac, 1, 1) =~ /\d/ not substr($after_frac, 2, 1) =~ /\d/ substr($after_frac, 3, 1) ne ":" not substr($after_frac, 4, 1) =~ /\d/ not substr($after_frac, 5, 1) =~ /\d/
Truth table0%0/7
A or not(B) or not(C) or D or not(E) or not(F)
A= length $after_frac < 6B= not substr($after_frac, 1, 1) =~ /\d/C= not substr($after_frac, 2, 1) =~ /\d/D= substr($after_frac, 3, 1) ne ":"E= not substr($after_frac, 4, 1) =~ /\d/F= not substr($after_frac, 5, 1) =~ /\d/
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
2893 || substr($after_frac,1,1) !~ /\d/ || substr($after_frac,2,1) !~ /\d/
2894 || substr($after_frac,3,1) ne ':'
2895 || substr($after_frac,4,1) !~ /\d/ || substr($after_frac,5,1) !~ /\d/) {
2896 0 $self->_die("invalid offset; expected ±HH:MM");
2897 }
2898 0 my $oh = int(substr($after_frac,1,2));
2899 0 my $om = int(substr($after_frac,4,2));
2900 0 ▶ $self->_die("offset out of range") if $oh > 23 || $om > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $oh > 23 or $om > 59 0 0 0
Condition0%0/3
$oh > 23 or $om > 59
l!l&&r!l&&!r
000
MC/DC0%0/2
$oh > 23 or $om > 59
$oh > 23 $om > 59
Truth table0%0/3
A or B
A= $oh > 23B= $om > 59
ABresult
1X1
011
000
2901 0 $consumed += 6;
2902 0 my $s = substr($rest, 0, $consumed);
2903 0 $self->{pos} += $consumed;
2904 0 return DMS::Parser::OffsetDateTime->new($s);
2905 }
2906 0 my $after = substr($after_frac,0,1);
2907 0 ▶ $after = undef if $after eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $after eq "" 0 0 0
2908 0 ▶ $self->_die("invalid character after datetime") unless _is_value_terminator($after);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_value_terminator($after) 0 0 0
2909 0 my $s = substr($rest, 0, $consumed);
2910 0 $self->{pos} += $consumed;
2911 0 return DMS::Parser::LocalDateTime->new($s);
2912 }
2913  
2914 0 ▶sub parse_local_time_value {
Subroutine parse_local_time_value: not called CC=9 SCAR=45.0
Pod undocumented
2915 0 my $self = shift;
2916 0 my $rest = substr($self->{src}, $self->{pos});
2917 0 my $time_str = substr($rest, 0, 8);
2918 0 eval { _validate_time($time_str); };
2919 0 ▶ if ($@) { my $msg = $@; chomp $msg; $self->_die($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
2920 0 my $consumed = 8;
2921 0 my $after = substr($rest, $consumed);
2922 0 ▶ if (substr($after,0,1) eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($after, 0, 1) eq ".") 0 0 0
2923 0 my $k = 1;
2924 0 ▶ while ($k < length($after) && substr($after,$k,1) =~ /\d/) { $k++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($k < length $after and substr($after, $k, 1) =~ /\d/) 0 0 0
Condition0%0/3
$k < length $after and substr($after, $k, 1) =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
$k < length $after and substr($after, $k, 1) =~ /\d/
$k < length $after substr($after, $k, 1) =~ /\d/
Truth table0%0/3
A and B
A= $k < length $afterB= substr($after, $k, 1) =~ /\d/
ABresult
0X0
100
111
2925 0 my $digits = $k - 1;
2926 0 ▶ $self->_die("expected fractional digits after '.'") if $digits == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $digits == 0 0 0 0
2927 0 ▶ $self->_die("fractional seconds limited to 9 digits") if $digits > 9;
Branch: 1 branch
BranchTrueFalseTotal
if $digits > 9 0 0 0
2928 0 $consumed += $k;
2929 }
2930 0 my $after2 = substr($rest, $consumed);
2931 0 my $nxt = substr($after2,0,1);
2932 0 ▶ $nxt = undef if $nxt eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $nxt eq "" 0 0 0
2933 0 ▶ $self->_die("invalid character after time") unless _is_value_terminator($nxt);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_value_terminator($nxt) 0 0 0
2934 0 my $s = substr($rest, 0, $consumed);
2935 0 $self->{pos} += $consumed;
2936 0 return DMS::Parser::LocalTime->new($s);
2937 }
2938  
2939 0 ▶sub parse_basic_string_value {
Subroutine parse_basic_string_value: not called CC=19 SCAR=59.4
Pod undocumented
2940 0 my $self = shift;
2941 0 my ($sl, $sls, $sp) = ($self->{line}, $self->{line_start}, $self->{pos});
2942 0 $self->{pos}++;
2943 0 my $out = '';
2944 0 my $src = $self->{src};
2945 0 my $len = $self->{len};
2946 0 pos($src) = $self->{pos};
2947 0 while (1) {
2948 # Bulk-scan a run of safe characters (anything but ", \, or line-end)
2949 # in one regex op. The previous per-char _peek loop did O(N) Perl-VM
2950 # round-trips; this reduces typical string parsing to a single regex
2951 # plus per-escape handling. parse_basic_string_value was the
2952 # heaviest leaf at 19% of decode time on bench_realistic.
2953 0 ▶ if ($src =~ /\G([^"\\\n\r]*)/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src =~ /\G([^"\\\n\r]*)/cg) 0 0 0
2954 0 ▶ $out .= $1 if length($1);
Branch: 1 branch
BranchTrueFalseTotal
if length $1 0 0 0
2955 }
2956 0 my $p = pos($src);
2957 0 ▶ if ($p >= $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= $len) 0 0 0
2958 0 $self->{pos} = $p;
2959 0 die $self->_err_at($sl, $sls, $sp, "unterminated string");
2960 }
2961 0 my $c = substr($src, $p, 1);
2962 0 ▶ if ($c eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\"") 0 0 0
2963 0 $self->{pos} = $p + 1;
2964 # SPEC §Unicode normalization: re-NFC after escape decoding.
2965 0 ▶ return $out !~ /[^\x00-\x7F]/ ? $out : _NFC($out);
Branch: 1 branch
BranchTrueFalseTotal
!($out =~ /[^\x00-\x7F]/) ? : 0 0 0
2966 }
2967 0 ▶ if ($c eq "\n" || $c eq "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n" or $c eq "\r") 0 0 0
Condition0%0/3
$c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "\n" or $c eq "\r"
$c eq "\n" $c eq "\r"
Truth table0%0/3
A or B
A= $c eq "\n"B= $c eq "\r"
ABresult
1X1
011
000
2968 0 $self->{pos} = $p;
2969 0 $self->_die("strings cannot span lines");
2970 }
2971 # $c is '\\' — handle the escape, then resume the bulk scan.
2972 0 $p++; # past the backslash
2973 0 ▶ if ($p >= $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= $len) 0 0 0
2974 0 $self->{pos} = $p;
2975 0 $self->_die("unterminated escape");
2976 }
2977 0 my $esc = substr($src, $p, 1);
2978 0 $p++;
2979 0 ▶ if ($esc eq '"') { $out .= '"'; }
Branch: 8 branches
BranchTrueFalseTotal
if ($esc eq '"') { } 0 0 0
elsif ($esc eq '\\') { } 0 0 0
elsif ($esc eq 'n') { } 0 0 0
elsif ($esc eq 't') { } 0 0 0
elsif ($esc eq 'r') { } 0 0 0
elsif ($esc eq 'b') { } 0 0 0
elsif ($esc eq 'f') { } 0 0 0
elsif ($esc eq 'u' or $esc eq 'U') { } 0 0 0
2980 0 elsif ($esc eq '\\') { $out .= '\\'; }
2981 0 elsif ($esc eq 'n') { $out .= "\n"; }
2982 0 elsif ($esc eq 't') { $out .= "\t"; }
2983 0 elsif ($esc eq 'r') { $out .= "\r"; }
2984 0 elsif ($esc eq 'b') { $out .= "\b"; }
2985 0 elsif ($esc eq 'f') { $out .= "\f"; }
2986 ▶ elsif ($esc eq 'u' || $esc eq 'U') {
Condition0%0/3
$esc eq "u" or $esc eq "U"
l!l&&r!l&&!r
000
MC/DC0%0/2
$esc eq "u" or $esc eq "U"
$esc eq "u" $esc eq "U"
Truth table0%0/3
A or B
A= $esc eq "u"B= $esc eq "U"
ABresult
1X1
011
000
2987 # _read_hex_codepoint reads from $self->{pos}; sync it first.
2988 0 $self->{pos} = $p;
2989 0 ▶ $out .= $self->_read_hex_codepoint($esc eq 'u' ? 4 : 8);
Branch: 1 branch
BranchTrueFalseTotal
$esc eq 'u' ? : 0 0 0
2990 0 $p = $self->{pos};
2991 }
2992 else {
2993 0 $self->{pos} = $p;
2994 0 $self->_die("invalid escape '\\$esc'");
2995 }
2996 0 pos($src) = $p;
2997 }
2998 }
2999  
3000 0 ▶sub parse_literal_string_value {
Subroutine parse_literal_string_value: not called CC=5 SCAR=34.0
Pod undocumented
3001 0 my $self = shift;
3002 0 my ($sl, $sls, $sp) = ($self->{line}, $self->{line_start}, $self->{pos});
3003 0 $self->{pos}++;
3004 0 my $out = '';
3005 0 while (1) {
3006 0 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 0 0 0
3007 0 die $self->_err_at($sl, $sls, $sp, "unterminated string");
3008 }
3009 0 my $c = $self->_peek;
3010 0 ▶ $self->_die("strings cannot span lines") if $c eq "\n" || $c eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if $c eq "\n" or $c eq "\r" 0 0 0
Condition0%0/3
$c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq "\n" or $c eq "\r"
$c eq "\n" $c eq "\r"
Truth table0%0/3
A or B
A= $c eq "\n"B= $c eq "\r"
ABresult
1X1
011
000
3011 0 ▶ if ($c eq "'") { $self->{pos}++; return $out; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "'") 0 0 0
3012 0 $self->{pos}++;
3013 0 $out .= $c;
3014 }
3015 }
3016  
3017 0 ▶sub _read_hex_codepoint {
Subroutine _read_hex_codepoint: not called CC=7 SCAR=40.3
3018 0 my ($self, $n) = @_;
3019 0 my $rest = substr($self->{src}, $self->{pos});
3020 0 ▶ $self->_die("expected $n hex digits in unicode escape") if length($rest) < $n;
Branch: 1 branch
BranchTrueFalseTotal
if length $rest < $n 0 0 0
3021 0 my $hex = substr($rest, 0, $n);
3022 0 ▶ $self->_die("invalid hex in unicode escape: $hex") if $hex !~ /^[0-9a-fA-F]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $hex =~ /^[0-9a-fA-F]+$/ 0 0 0
3023 0 my $v = hex($hex);
3024 # SPEC: U+0000 is forbidden anywhere in DMS source, including via
3025 # escape decoding. ` ` / `\U00000000` must not slip through.
3026 0 ▶ if ($v == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v == 0) 0 0 0
3027 0 $self->_die("\\u0000 escape forbidden");
3028 }
3029 0 ▶ if ($v >= 0xD800 && $v <= 0xDFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v >= 55296 and $v <= 57343) 0 0 0
Condition0%0/3
$v >= 55296 and $v <= 57343
!ll&&!rl&&r
000
MC/DC0%0/2
$v >= 55296 and $v <= 57343
$v >= 55296 $v <= 57343
Truth table0%0/3
A and B
A= $v >= 55296B= $v <= 57343
ABresult
0X0
100
111
3030 0 $self->_die(sprintf("surrogate codepoint U+%04X in escape", $v));
3031 }
3032 0 ▶ if ($v > 0x10FFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v > 1114111) 0 0 0
3033 0 $self->_die("unicode escape is not a scalar value");
3034 }
3035 0 $self->{pos} += $n;
3036 0 return chr($v);
3037 }
3038  
3039 # Heredocs
3040  
3041 0 ▶sub parse_heredoc_basic {
Subroutine parse_heredoc_basic: not called CC=7 SCAR=40.3
Pod undocumented
3042 0 my $self = shift;
3043 0 $self->{pos} += 3;
3044 0 my $label = $self->_parse_heredoc_label;
3045 0 my $mods = $self->_parse_heredoc_modifiers;
3046 0 $self->_skip_inline_ws;
3047 0 ▶ if (!($self->_consume_eol || $self->_eof)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_consume_eol or $self->_eof) 0 0 0
Condition0%0/3
$self->_consume_eol or $self->_eof
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_consume_eol or $self->_eof
$self->_consume_eol $self->_eof
Truth table0%0/3
A or B
A= $self->_consume_eolB= $self->_eof
ABresult
1X1
011
000
3048 0 $self->_die("heredoc opener must be followed by end of line");
3049 }
3050 0 ▶ my $terminator = length($label) ? $label : '"""';
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 0 0 0
3051 0 my $body = $self->_collect_heredoc_body($terminator);
3052 # SPEC §basic-string escapes: surrogate codepoints (U+D800..U+DFFF)
3053 # and U+0000 are not valid in `\uXXXX` / `\UXXXXXXXX` escapes.
3054 # Basic-heredoc bodies are kept raw, so we validate the rules by
3055 # scanning the body for offending escape sequences.
3056 0 _validate_heredoc_basic_escapes($body);
3057 0 my $stripped = _strip_indent_and_continuations($body, 1);
3058 0 my $out;
3059 0 eval { $out = _apply_modifiers($stripped, $mods); };
3060 0 ▶ if ($@) { my $msg = $@; chomp $msg; $self->_die($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3061 $self->_record_form({
3062 string_form => {
3063 kind => 'heredoc',
3064 flavor => 'basic_triple',
3065 label => (length($label) ? $label : undef),
3066 0 ▶ modifiers => [ map { { name => $_->{name}, args => $_->{args} } } @$mods ],
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 0 0 0
3067 },
3068 });
3069 # SPEC §Unicode normalization: re-NFC after escape decoding.
3070 0 ▶ return $out !~ /[^\x00-\x7F]/ ? $out : _NFC($out);
Branch: 1 branch
BranchTrueFalseTotal
!($out =~ /[^\x00-\x7F]/) ? : 0 0 0
3071 }
3072  
3073 # SPEC §basic-string escapes: a `\uXXXX` / `\UXXXXXXXX` escape whose
3074 # decoded value falls in the surrogate range U+D800..U+DFFF is not a
3075 # Unicode scalar and is a parse error. Likewise U+0000 is forbidden.
3076 # Basic-heredoc body lines are collected raw, so we validate the same
3077 # rules by scanning the body for offending escape sequences.
3078 0 ▶sub _validate_heredoc_basic_escapes {
Subroutine _validate_heredoc_basic_escapes: not called CC=16 SCAR=56.1
3079 0 my ($body) = @_;
3080 0 for my $ln (@{$body->{lines}}) {
3081 0 my $text = $ln->{text};
3082 0 my $len = length($text);
3083 0 my $i = 0;
3084 0 ▶ while ($i < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
3085 0 ▶ if (substr($text, $i, 1) eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($text, $i, 1) eq '\\') { } 0 0 0
3086 # find run of consecutive backslashes
3087 0 my $j = $i;
3088 0 ▶ while ($j < $len && substr($text, $j, 1) eq '\\') { $j++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $len and substr($text, $j, 1) eq "\\") 0 0 0
Condition0%0/3
$j < $len and substr($text, $j, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$j < $len and substr($text, $j, 1) eq "\\"
$j < $len substr($text, $j, 1) eq "\\"
Truth table0%0/3
A and B
A= $j < $lenB= substr($text, $j, 1) eq "\\"
ABresult
0X0
100
111
3089 0 my $run = $j - $i;
3090 0 ▶ if ($run % 2 == 1 && $j < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run % 2 == 1 and $j < $len) 0 0 0
Condition0%0/3
$run % 2 == 1 and $j < $len
!ll&&!rl&&r
000
MC/DC0%0/2
$run % 2 == 1 and $j < $len
$run % 2 == 1 $j < $len
Truth table0%0/3
A and B
A= $run % 2 == 1B= $j < $len
ABresult
0X0
100
111
3091 0 my $intro = substr($text, $j, 1);
3092 0 ▶ my $n = ($intro eq 'u') ? 4 : ($intro eq 'U') ? 8 : 0;
Branch: 2 branches
BranchTrueFalseTotal
$intro eq 'u' ? : 0 0 0
$intro eq 'U' ? : 0 0 0
3093 0 ▶ if ($n > 0 && $j + 1 + $n <= $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 0 and $j + 1 + $n <= $len) 0 0 0
Condition0%0/3
$n > 0 and $j + 1 + $n <= $len
!ll&&!rl&&r
000
MC/DC0%0/2
$n > 0 and $j + 1 + $n <= $len
$n > 0 $j + 1 + $n <= $len
Truth table0%0/3
A and B
A= $n > 0B= $j + 1 + $n <= $len
ABresult
0X0
100
111
3094 0 my $hex = substr($text, $j + 1, $n);
3095 0 ▶ if ($hex =~ /^[0-9a-fA-F]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hex =~ /^[0-9a-fA-F]+$/) 0 0 0
3096 0 my $cp = hex($hex);
3097 0 my $esc_off = $j - 1;
3098 0 ▶ if ($cp == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp == 0) 0 0 0
3099 die sprintf("%d:%d: \\u0000 escape forbidden\n",
3100 0 $ln->{line}, $esc_off + 1);
3101 }
3102 0 ▶ if ($cp >= 0xD800 && $cp <= 0xDFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp >= 55296 and $cp <= 57343) 0 0 0
Condition0%0/3
$cp >= 55296 and $cp <= 57343
!ll&&!rl&&r
000
MC/DC0%0/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296 $cp <= 57343
Truth table0%0/3
A and B
A= $cp >= 55296B= $cp <= 57343
ABresult
0X0
100
111
3103 die sprintf("%d:%d: surrogate codepoint U+%04X in escape\n",
3104 0 $ln->{line}, $esc_off + 1, $cp);
3105 }
3106 }
3107 }
3108 }
3109 0 $i = $j;
3110 } else {
3111 0 $i++;
3112 }
3113 }
3114 }
3115 }
3116  
3117 0 ▶sub parse_heredoc_literal {
Subroutine parse_heredoc_literal: not called CC=6 SCAR=37.4
Pod undocumented
3118 0 my $self = shift;
3119 0 $self->{pos} += 3;
3120 0 my $label = $self->_parse_heredoc_label;
3121 0 my $mods = $self->_parse_heredoc_modifiers;
3122 0 $self->_skip_inline_ws;
3123 0 ▶ if (!($self->_consume_eol || $self->_eof)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_consume_eol or $self->_eof) 0 0 0
Condition0%0/3
$self->_consume_eol or $self->_eof
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_consume_eol or $self->_eof
$self->_consume_eol $self->_eof
Truth table0%0/3
A or B
A= $self->_consume_eolB= $self->_eof
ABresult
1X1
011
000
3124 0 $self->_die("heredoc opener must be followed by end of line");
3125 }
3126 0 ▶ my $terminator = length($label) ? $label : "'''";
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 0 0 0
3127 0 my $body = $self->_collect_heredoc_body($terminator);
3128 0 my $stripped = _strip_indent_and_continuations($body, 0);
3129 0 my $out;
3130 0 eval { $out = _apply_modifiers($stripped, $mods); };
3131 0 ▶ if ($@) { my $msg = $@; chomp $msg; $self->_die($msg); }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
3132 $self->_record_form({
3133 string_form => {
3134 kind => 'heredoc',
3135 flavor => 'literal_triple',
3136 label => (length($label) ? $label : undef),
3137 0 ▶ modifiers => [ map { { name => $_->{name}, args => $_->{args} } } @$mods ],
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 0 0 0
3138 },
3139 });
3140 0 return $out;
3141 }
3142  
3143 0 ▶sub _parse_heredoc_label {
Subroutine _parse_heredoc_label: not called CC=3 SCAR=24.8
3144 0 my $self = shift;
3145 0 my $c = $self->_peek;
3146 0 ▶ return '' if !_is_label_start($c);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_label_start($c) 0 0 0
3147 0 my $start = $self->{pos};
3148 0 while (1) {
3149 0 my $c2 = $self->_peek;
3150 0 ▶ last if !_is_label_cont($c2);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_label_cont($c2) 0 0 0
3151 0 $self->{pos}++;
3152 }
3153 0 return substr($self->{src}, $start, $self->{pos} - $start);
3154 }
3155  
3156 0 ▶sub _parse_heredoc_modifiers {
Subroutine _parse_heredoc_modifiers: not called CC=4 SCAR=30.0
3157 0 my $self = shift;
3158 0 my @mods;
3159 0 while (1) {
3160 0 my $ws_start = $self->{pos};
3161 0 $self->_skip_inline_ws;
3162 0 my $had_ws = $self->{pos} > $ws_start;
3163 0 my $c = $self->_peek;
3164 0 ▶ if (defined($c) && _is_label_start($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c and _is_label_start($c)) { } 0 0 0
Condition0%0/3
defined $c and _is_label_start($c)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and _is_label_start($c)
defined $c _is_label_start($c)
Truth table0%0/3
A and B
A= defined $cB= _is_label_start($c)
ABresult
0X0
100
111
3165 0 ▶ $self->_die("modifier must be preceded by whitespace") unless $had_ws;
Branch: 1 branch
BranchTrueFalseTotal
unless $had_ws 0 0 0
3166 0 push @mods, $self->_parse_one_modifier;
3167 } else {
3168 0 $self->{pos} = $ws_start;
3169 0 return \@mods;
3170 }
3171 }
3172 }
3173  
3174 0 ▶sub _parse_one_modifier {
Subroutine _parse_one_modifier: not called CC=7 SCAR=40.3
3175 0 my $self = shift;
3176 0 my $ns = $self->{pos};
3177 0 while (1) {
3178 0 my $c = $self->_peek;
3179 0 ▶ last if !_is_label_cont($c);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_label_cont($c) 0 0 0
3180 0 $self->{pos}++;
3181 }
3182 0 my $name = substr($self->{src}, $ns, $self->{pos} - $ns);
3183 0 ▶ $self->_die("modifiers require parentheses") if $self->_peek ne '(';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_peek ne "(" 0 0 0
3184 0 $self->{pos}++;
3185 # Suppress original-form recording for modifier args: they're
3186 # parse-time values used as call arguments and must not pollute the
3187 # host heredoc node's original_forms slot.
3188 0 my $saved = $self->{record_forms};
3189 0 $self->{record_forms} = 0;
3190 0 my @args;
3191 0 my $ok = eval {
3192 0 while (1) {
3193 0 $self->_skip_inline_ws;
3194 0 ▶ if ($self->_peek eq ')') { $self->{pos}++; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek eq ")") 0 0 0
3195 0 push @args, $self->parse_inline_value_or_heredoc;
3196 0 $self->_skip_inline_ws;
3197 0 my $c = $self->_peek;
3198 0 ▶ if ($c eq ',') { $self->{pos}++; }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq ',') { } 0 0 0
elsif ($c eq ')') { } 0 0 0
3199 0 elsif ($c eq ')') { $self->{pos}++; last; }
3200 0 else { $self->_die("expected ',' or ')' in modifier args"); }
3201 }
3202 0 1;
3203 };
3204 0 my $err = $@;
3205 0 $self->{record_forms} = $saved;
3206 0 ▶ die $err if !$ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
3207 0 return { name => $name, args => \@args };
3208 }
3209  
3210 0 ▶sub _collect_heredoc_body {
Subroutine _collect_heredoc_body: not called CC=8 SCAR=42.8
3211 0 my ($self, $terminator) = @_;
3212 0 my @lines;
3213 0 my ($sl, $sls, $sp) = ($self->{line}, $self->{line_start}, $self->{pos});
3214 0 while (1) {
3215 0 ▶ if ($self->_eof) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_eof) 0 0 0
3216 0 die $self->_err_at($sl, $sls, $sp, "unterminated heredoc");
3217 }
3218 0 my $lb = $self->{pos};
3219 0 while (1) {
3220 0 my $c = $self->_peek;
3221 0 ▶ last if !defined($c) || $c eq "\n" || $c eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $c or $c eq "\n" or $c eq "\r" 0 0 0
Condition0%0/6
not defined $c or $c eq "\n" or $c eq "\r"
l!l&&r!l&&!r
000
not defined $c or $c eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $c or $c eq "\n" or $c eq "\r"
not defined $c $c eq "\n" $c eq "\r"
Truth table0%0/4
not(A) or B or C
A= not defined $cB= $c eq "\n"C= $c eq "\r"
ABCresult
1XX1
01X1
0011
0000
3222 0 $self->{pos}++;
3223 }
3224 0 my $raw = substr($self->{src}, $lb, $self->{pos} - $lb);
3225 0 my ($this_line, $this_lstart) = ($self->{line}, $self->{line_start});
3226 0 my $trimmed = $raw; $trimmed =~ s/^\s+|\s+$//g;
3227 0 ▶ if ($trimmed eq $terminator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed eq $terminator) 0 0 0
3228 0 my $strip_depth = 0;
3229 0 for my $c (split //, $raw) {
3230 0 ▶ if ($c eq ' ') { $strip_depth++; } else { last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ' ') { } 0 0 0
3231 }
3232 0 return { lines => \@lines, strip_depth => $strip_depth };
3233 }
3234 0 $self->_consume_eol;
3235 0 push @lines, { text => $raw, line => $this_line, line_start => $this_lstart };
3236 }
3237 }
3238  
3239 0 ▶sub _strip_indent_and_continuations {
Subroutine _strip_indent_and_continuations: not called CC=16 SCAR=56.1
3240 0 my ($body, $allow_cont) = @_;
3241 0 my @out;
3242 0 my $first = 1;
3243 0 my $pending = 0;
3244 0 my @last = (1, 0);
3245 0 for my $ln (@{$body->{lines}}) {
3246 0 @last = ($ln->{line}, $ln->{line_start});
3247 0 my $is_blank = ($ln->{text} =~ /\A[ \t]*\z/);
3248 0 my $stripped;
3249 0 ▶ if ($is_blank) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_blank) { } 0 0 0
3250 0 $stripped = '';
3251 } else {
3252 0 my $leading = 0;
3253 0 for my $c (split //, $ln->{text}) {
3254 0 ▶ if ($c eq ' ') { $leading++; } else { last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ' ') { } 0 0 0
3255 }
3256 0 ▶ if ($leading < $body->{strip_depth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($leading < $body->{"strip_depth"}) 0 0 0
3257 die sprintf("%d:%d: heredoc body line indented %d spaces, less than strip depth %d\n",
3258 0 $ln->{line}, $leading + 1, $leading, $body->{strip_depth});
3259 }
3260 0 $stripped = substr($ln->{text}, $body->{strip_depth});
3261 }
3262 0 my $piece = $stripped;
3263 0 my $splice = 0;
3264 0 ▶ if ($allow_cont) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_cont) 0 0 0
3265 0 my $trimmed_end = $piece; $trimmed_end =~ s/[ \t]+$//;
3266 0 my $idx = rindex($trimmed_end, '\\');
3267 0 ▶ if ($idx != -1 && $idx == length($trimmed_end) - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx != -1 and $idx == length($trimmed_end) - 1) 0 0 0
Condition0%0/3
$idx != -1 and $idx == length($trimmed_end) - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$idx != -1 and $idx == length($trimmed_end) - 1
$idx != -1 $idx == length($trimmed_end) - 1
Truth table0%0/3
A and B
A= $idx != -1B= $idx == length($trimmed_end) - 1
ABresult
0X0
100
111
3268 0 my $preceding = 0;
3269 0 ▶ for (my $k = $idx - 1; $k >= 0 && substr($trimmed_end,$k,1) eq '\\'; $k--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k >= 0 and substr($trimmed_end, $k, 1) eq "\\") 0 0 0
Condition0%0/3
$k >= 0 and substr($trimmed_end, $k, 1) eq "\\"
!ll&&!rl&&r
000
MC/DC0%0/2
$k >= 0 and substr($trimmed_end, $k, 1) eq "\\"
$k >= 0 substr($trimmed_end, $k, 1) eq "\\"
Truth table0%0/3
A and B
A= $k >= 0B= substr($trimmed_end, $k, 1) eq "\\"
ABresult
0X0
100
111
3270 0 $preceding++;
3271 }
3272 0 ▶ if ($preceding % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preceding % 2 == 0) 0 0 0
3273 0 $piece = substr($trimmed_end, 0, $idx);
3274 0 $splice = 1;
3275 }
3276 }
3277 }
3278 0 ▶ if ($first) {
Branch: 2 branches
BranchTrueFalseTotal
if ($first) { } 0 0 0
elsif ($pending) { } 0 0 0
3279 0 push @out, $piece;
3280 0 $first = 0;
3281 } elsif ($pending) {
3282 0 my $trimmed_start = $piece; $trimmed_start =~ s/^[ \t]+//;
3283 0 ▶ push @out, $trimmed_start unless $is_blank;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_blank 0 0 0
3284 } else {
3285 0 push @out, "\n", $piece;
3286 }
3287 0 $pending = $splice;
3288 }
3289 0 ▶ if ($pending) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending) 0 0 0
3290 0 die sprintf("%d:1: trailing line continuation has nothing to splice to\n", $last[0]);
3291 }
3292 0 return join('', @out);
3293 }
3294  
3295 0 ▶sub _fold_paragraphs {
Subroutine _fold_paragraphs: not called CC=1 SCAR=6.9
3296 0 my ($s) = @_;
3297 0 my @paras = split /\n\n/, $s, -1;
3298 return join("\n", map {
3299 0 join(' ', grep { length($_) } split /\n/, $_, -1);
3300 } @paras);
3301 }
3302  
3303 0 ▶sub _replace_all_runs {
Subroutine _replace_all_runs: not called CC=5 SCAR=34.0
3304 0 my ($s, $charset, $replacement) = @_;
3305 0 my $out = '';
3306 0 my @chars = split //, $s;
3307 0 my $i = 0;
3308 0 ▶ while ($i < @chars) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chars) 0 0 0
3309 0 ▶ if ($charset->{$chars[$i]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$charset{$chars[$i]}) { } 0 0 0
3310 0 ▶ while ($i < @chars && $charset->{$chars[$i]}) { $i++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chars and $$charset{$chars[$i]}) 0 0 0
Condition0%0/3
$i < @chars and $$charset{$chars[$i]}
!ll&&!rl&&r
000
MC/DC0%0/2
$i < @chars and $$charset{$chars[$i]}
$i < @chars $$charset{$chars[$i]}
Truth table0%0/3
A and B
A= $i < @charsB= $$charset{$chars[$i]}
ABresult
0X0
100
111
3311 0 $out .= $replacement;
3312 } else {
3313 0 $out .= $chars[$i];
3314 0 $i++;
3315 }
3316 }
3317 0 return $out;
3318 }
3319  
3320 0 ▶sub _replace_leading_run {
Subroutine _replace_leading_run: not called CC=4 SCAR=30.0
3321 0 my ($s, $charset, $replacement) = @_;
3322 0 my @chars = split //, $s;
3323 0 my $end = 0;
3324 0 ▶ while ($end < @chars && $charset->{$chars[$end]}) { $end++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($end < @chars and $$charset{$chars[$end]}) 0 0 0
Condition0%0/3
$end < @chars and $$charset{$chars[$end]}
!ll&&!rl&&r
000
MC/DC0%0/2
$end < @chars and $$charset{$chars[$end]}
$end < @chars $$charset{$chars[$end]}
Truth table0%0/3
A and B
A= $end < @charsB= $$charset{$chars[$end]}
ABresult
0X0
100
111
3325 0 ▶ return $s if $end == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $end == 0 0 0 0
3326 0 return $replacement . join('', @chars[$end..$#chars]);
3327 }
3328  
3329 0 ▶sub _replace_trailing_run {
Subroutine _replace_trailing_run: not called CC=4 SCAR=30.0
3330 0 my ($s, $charset, $replacement) = @_;
3331 0 my @chars = split //, $s;
3332 0 my $start = scalar @chars;
3333 0 ▶ while ($start > 0 && $charset->{$chars[$start-1]}) { $start--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($start > 0 and $$charset{$chars[$start - 1]}) 0 0 0
Condition0%0/3
$start > 0 and $$charset{$chars[$start - 1]}
!ll&&!rl&&r
000
MC/DC0%0/2
$start > 0 and $$charset{$chars[$start - 1]}
$start > 0 $$charset{$chars[$start - 1]}
Truth table0%0/3
A and B
A= $start > 0B= $$charset{$chars[$start - 1]}
ABresult
0X0
100
111
3334 0 ▶ return $s if $start == @chars;
Branch: 1 branch
BranchTrueFalseTotal
if $start == @chars 0 0 0
3335 0 return join('', @chars[0..$start-1]) . $replacement;
3336 }
3337  
3338 0 ▶sub _per_line_edges {
Subroutine _per_line_edges: not called CC=2 SCAR=17.9
3339 0 my ($s, $charset, $replacement) = @_;
3340 0 my @lines = split /\n/, $s, -1;
3341 0 for my $line (@lines) {
3342 0 $line = _replace_leading_run($line, $charset, $replacement);
3343 0 $line = _replace_trailing_run($line, $charset, $replacement);
3344 }
3345 0 return join("\n", @lines);
3346 }
3347  
3348 0 ▶sub _apply_trim {
Subroutine _apply_trim: not called CC=10 SCAR=47.0
3349 0 my ($s, $chars, $where, $replacement) = @_;
3350 0 ▶ return $s if length($chars) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $chars == 0 0 0 0
3351 0 my %charset = map { $_ => 1 } split //, $chars;
3352 0 my $has_star = (index($where, '*') >= 0);
3353 0 my $has_pipe = (index($where, '|') >= 0);
3354 0 my $has_lt = (index($where, '<') >= 0);
3355 0 my $has_gt = (index($where, '>') >= 0);
3356 0 ▶ return $s if !($has_star || $has_pipe || $has_lt || $has_gt);
Branch: 1 branch
BranchTrueFalseTotal
unless $has_star or $has_pipe or $has_lt or $has_gt 0 0 0
Condition0%0/9
$has_star or $has_pipe or $has_lt or $has_gt
l!l&&r!l&&!r
000
$has_star or $has_pipe or $has_lt
l!l&&r!l&&!r
000
$has_star or $has_pipe
l!l&&r!l&&!r
000
MC/DC0%0/4
$has_star or $has_pipe or $has_lt or $has_gt
$has_star $has_pipe $has_lt $has_gt
Truth table0%0/5
A or B or C or D
A= $has_starB= $has_pipeC= $has_ltD= $has_gt
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3357 0 ▶ return _replace_all_runs($s, \%charset, $replacement) if $has_star;
Branch: 1 branch
BranchTrueFalseTotal
if $has_star 0 0 0
3358 0 my $cur = $s;
3359 0 ▶ $cur = _per_line_edges($cur, \%charset, $replacement) if $has_pipe;
Branch: 1 branch
BranchTrueFalseTotal
if $has_pipe 0 0 0
3360 0 ▶ $cur = _replace_leading_run($cur, \%charset, $replacement) if $has_lt;
Branch: 1 branch
BranchTrueFalseTotal
if $has_lt 0 0 0
3361 0 ▶ $cur = _replace_trailing_run($cur, \%charset, $replacement) if $has_gt;
Branch: 1 branch
BranchTrueFalseTotal
if $has_gt 0 0 0
3362 0 return $cur;
3363 }
3364  
3365 0 ▶sub _apply_modifiers {
Subroutine _apply_modifiers: not called CC=11 SCAR=48.8
3366 0 my ($s, $mods) = @_;
3367 0 my $cur = $s;
3368 0 for my $m (@$mods) {
3369 0 my $name = $m->{name};
3370 0 my $args = $m->{args};
3371 0 ▶ if ($name eq '_fold_paragraphs') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq '_fold_paragraphs') { } 0 0 0
elsif ($name eq '_trim') { } 0 0 0
3372 0 ▶ die "fold_paragraphs() takes no arguments\n" if @$args;
Branch: 1 branch
BranchTrueFalseTotal
if @$args 0 0 0
3373 0 $cur = _fold_paragraphs($cur);
3374 } elsif ($name eq '_trim') {
3375 0 ▶ die qq{trim(chars, where, replacement = "") expects 2 or 3 arguments\n}
Branch: 1 branch
BranchTrueFalseTotal
if @$args < 2 or @$args > 3 0 0 0
Condition0%0/3
@$args < 2 or @$args > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args < 2 or @$args > 3
@$args < 2 @$args > 3
Truth table0%0/3
A or B
A= @$args < 2B= @$args > 3
ABresult
1X1
011
000
3376 if @$args < 2 || @$args > 3;
3377 0 my $chars = $args->[0];
3378 0 ▶ die "trim: first argument (chars) must be a string\n" if ref($chars) ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $chars ne "" 0 0 0
3379 0 my $where = $args->[1];
3380 0 ▶ die "trim: second argument (where) must be a string\n" if ref($where) ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $where ne "" 0 0 0
3381 0 my $replacement = '';
3382 0 ▶ if (@$args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 3) 0 0 0
3383 0 ▶ die "trim: third argument (replacement) must be a string\n" if ref($args->[2]) ne '';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args->[2] ne "" 0 0 0
3384 0 $replacement = $args->[2];
3385 }
3386 0 $cur = _apply_trim($cur, $chars, $where, $replacement);
3387 } else {
3388 0 die "unknown modifier: $name\n";
3389 }
3390 }
3391 0 return $cur;
3392 }
3393  
3394 # Flow forms
3395  
3396 0 ▶sub parse_flow_array {
Subroutine parse_flow_array: not called CC=6 SCAR=37.4
Pod undocumented
3397 0 my $self = shift;
3398 0 $self->{pos}++;
3399 0 my @items;
3400 0 while (1) {
3401 0 $self->_skip_flow_ws;
3402 0 ▶ if ($self->_peek eq ']') { $self->{pos}++; return \@items; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek eq "]") 0 0 0
3403 # Push the current index onto the path so any OriginalLiteral
3404 # records inside the flow value get the right breadcrumb.
3405 0 my $idx = scalar @items;
3406 0 push @{$self->{path}}, DMS::Parser::Index->new($idx);
3407 0 my $v;
3408 0 my $ok = eval { $v = $self->_parse_inline_value_in_flow; 1 };
3409 0 my $err = $@;
3410 0 pop @{$self->{path}};
3411 0 ▶ if (!$ok) { die $err; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
3412 0 push @items, $v;
3413 0 $self->_skip_flow_ws;
3414 0 my $c = $self->_peek;
3415 0 ▶ if ($c eq ',') { $self->{pos}++; }
Branch: 3 branches
BranchTrueFalseTotal
if ($c eq ',') { } 0 0 0
elsif ($c eq ']') { } 0 0 0
elsif (not defined $c) { } 0 0 0
3416 0 elsif ($c eq ']') { $self->{pos}++; return \@items; }
3417 0 elsif (!defined($c)) { $self->_die("unterminated flow array"); }
3418 0 else { $self->_die("unexpected '$c' in flow array; expected ',' or ']'"); }
3419 }
3420 }
3421  
3422 0 ▶sub parse_flow_table {
Subroutine parse_flow_table: not called CC=18 SCAR=58.3
Pod undocumented
3423 0 my $self = shift;
3424 0 $self->{pos}++;
3425 0 my $lite = $self->{lite};
3426 0 my $ignore_order = $self->{ignore_order};
3427 0 my ($t, $order);
3428 0 ▶ if ($ignore_order) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ignore_order) { } 0 0 0
elsif ($lite) { } 0 0 0
3429 0 $t = new_unordered_table();
3430 } elsif ($lite) {
3431 0 $order = [];
3432 0 $t = { $ORDER_KEY => $order };
3433 } else {
3434 0 $t = new_table();
3435 }
3436 0 while (1) {
3437 0 $self->_skip_flow_ws;
3438 0 ▶ if ($self->_peek eq '}') { $self->{pos}++; return $t; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek eq "}") 0 0 0
3439 0 my $key = $self->parse_key;
3440 0 ▶ $self->_die("expected ':' after flow-table key") if $self->_peek ne ':';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_peek ne ":" 0 0 0
3441 0 $self->{pos}++;
3442 0 my $c = $self->_peek;
3443 0 ▶ if (!defined($c) || ($c ne ' ' && $c ne "\t" && $c ne "\n" && $c ne "\r")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $c or $c ne " " and $c ne "\t" and $c ne "\n" and $c ne "\r") 0 0 0
Condition0%0/12
not defined $c or $c ne " " and $c ne "\t" and $c ne "\n" and $c ne "\r"
l!l&&r!l&&!r
000
$c ne " " and $c ne "\t" and $c ne "\n" and $c ne "\r"
!ll&&!rl&&r
000
$c ne " " and $c ne "\t" and $c ne "\n"
!ll&&!rl&&r
000
$c ne " " and $c ne "\t"
!ll&&!rl&&r
000
MC/DC0%0/5
not defined $c or $c ne " " and $c ne "\t" and $c ne "\n" and $c ne "\r"
not defined $c $c ne " " $c ne "\t" $c ne "\n" $c ne "\r"
Truth table0%0/6
not(A) or B and C and D and E
A= not defined $cB= $c ne " "C= $c ne "\t"D= $c ne "\n"E= $c ne "\r"
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
3444 0 $self->_die("expected whitespace after ':'");
3445 }
3446 0 $self->_skip_flow_ws;
3447 # Path push so OriginalLiteral records inside the value get the
3448 # key path as their breadcrumb.
3449 0 ▶ push @{$self->{path}}, $key unless $lite;
Branch: 1 branch
BranchTrueFalseTotal
unless $lite 0 0 0
3450 0 my $v;
3451 0 ▶ if ($lite) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lite) { } 0 0 0
3452 0 $v = $self->_parse_inline_value_in_flow;
3453 } else {
3454 0 my $ok = eval { $v = $self->_parse_inline_value_in_flow; 1 };
3455 0 my $err = $@;
3456 0 pop @{$self->{path}};
3457 0 ▶ if (!$ok) { die $err; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
3458 }
3459 0 ▶ $self->_die("duplicate key: $key") if exists $t->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $t->{$key} 0 0 0
3460 0 ▶ push @$order, $key if $order;
Branch: 1 branch
BranchTrueFalseTotal
if $order 0 0 0
3461 0 $t->{$key} = $v;
3462 0 $self->_skip_flow_ws;
3463 0 my $c2 = $self->_peek;
3464 0 ▶ if ($c2 eq ',') { $self->{pos}++; }
Branch: 3 branches
BranchTrueFalseTotal
if ($c2 eq ',') { } 0 0 0
elsif ($c2 eq '}') { } 0 0 0
elsif (not defined $c2) { } 0 0 0
3465 0 elsif ($c2 eq '}') { $self->{pos}++; return $t; }
3466 0 elsif (!defined($c2)) { $self->_die("unterminated flow table"); }
3467 0 else { $self->_die("unexpected '$c2' in flow table; expected ',' or '}'"); }
3468 }
3469 }
3470  
3471 0 ▶sub _skip_flow_ws {
Subroutine _skip_flow_ws: not called CC=10 SCAR=47.0
3472 0 my $self = shift;
3473 0 while (1) {
3474 0 pos($self->{src}) = $self->{pos};
3475 0 ▶ if ($self->{src} =~ /\G[ \t]+/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"src"} =~ /\G[ \t]+/cg) 0 0 0
3476 0 $self->{pos} = pos($self->{src});
3477 }
3478 0 ▶ return if $self->{pos} >= $self->{len};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pos"} >= $self->{"len"} 0 0 0
3479 0 my $c = substr($self->{src}, $self->{pos}, 1);
3480 0 ▶ if ($c eq "\n") { $self->{pos}++; $self->_advance_line; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 0 0 0
3481 0 ▶ if ($c eq "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\r") 0 0 0
3482 0 ▶ if (substr($self->{src}, $self->{pos}, 2) eq "\r\n") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{"src"}, $self->{"pos"}, 2) eq "\r\n") 0 0 0
3483 0 $self->{pos} += 2; $self->_advance_line; next;
3484 }
3485 0 return;
3486 }
3487 0 ▶ if ($c eq '#') { $self->_die("comments not allowed inside flow forms"); }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "#") 0 0 0
3488 0 ▶ if ($c eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "/") 0 0 0
3489 0 my $n = substr($self->{src}, $self->{pos} + 1, 1);
3490 0 ▶ if ($n eq '/' || $n eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "/" or $n eq "*") 0 0 0
Condition0%0/3
$n eq "/" or $n eq "*"
l!l&&r!l&&!r
000
MC/DC0%0/2
$n eq "/" or $n eq "*"
$n eq "/" $n eq "*"
Truth table0%0/3
A or B
A= $n eq "/"B= $n eq "*"
ABresult
1X1
011
000
3491 0 $self->_die("comments not allowed inside flow forms");
3492 }
3493 }
3494 0 return;
3495 }
3496 }
3497  
3498 0 ▶sub _parse_inline_value_in_flow {
Subroutine _parse_inline_value_in_flow: not called CC=5 SCAR=34.0
3499 0 my $self = shift;
3500 0 ▶ if ($self->_peek eq '"' && $self->_starts_with('"""')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek eq "\"" and $self->_starts_with("\"\"\"")) 0 0 0
Condition0%0/3
$self->_peek eq "\"" and $self->_starts_with("\"\"\"")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_peek eq "\"" and $self->_starts_with("\"\"\"")
$self->_peek eq "\"" $self->_starts_with("\"\"\"")
Truth table0%0/3
A and B
A= $self->_peek eq "\""B= $self->_starts_with("\"\"\"")
ABresult
0X0
100
111
3501 0 $self->_die("heredocs are not allowed inside flow forms");
3502 }
3503 0 ▶ if ($self->_peek eq "'" && $self->_starts_with("'''")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek eq "'" and $self->_starts_with("'''")) 0 0 0
Condition0%0/3
$self->_peek eq "'" and $self->_starts_with("'''")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_peek eq "'" and $self->_starts_with("'''")
$self->_peek eq "'" $self->_starts_with("'''")
Truth table0%0/3
A and B
A= $self->_peek eq "'"B= $self->_starts_with("'''")
ABresult
0X0
100
111
3504 0 $self->_die("heredocs are not allowed inside flow forms");
3505 }
3506 0 return $self->parse_inline_value_or_heredoc;
3507 }
3508  
3509 0 ▶sub _consume_after_value {
Subroutine _consume_after_value: not called CC=30 SCAR=68.4
3510 0 my ($self, $allow_eof) = @_;
3511 # Hot-path early-out for the no-comment case (every flat-table leaf):
3512 # check the byte at pos. Common case: directly at \n with no
3513 # trailing WS — return after one substr + branch. _advance_line is
3514 # inlined too so the hot path has zero method calls.
3515 0 my $hot_had_ws = 0;
3516 0 my $p = $self->{pos};
3517 {
3518 0 ▶ if ($p >= $self->{len}) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= $self->{"len"}) 0 0 0
3519 0 my $c = substr($self->{src}, $p, 1);
3520 0 ▶ if ($c eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 0 0 0
3521 0 my $np = $p + 1;
3522 0 $self->{pos} = $np;
3523 0 $self->{line}++;
3524 0 $self->{line_start} = $np;
3525 0 return;
3526 }
3527 0 ▶ if ($c eq ' ' || $c eq "\t") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq " " or $c eq "\t") 0 0 0
Condition0%0/3
$c eq " " or $c eq "\t"
l!l&&r!l&&!r
000
MC/DC0%0/2
$c eq " " or $c eq "\t"
$c eq " " $c eq "\t"
Truth table0%0/3
A or B
A= $c eq " "B= $c eq "\t"
ABresult
1X1
011
000
3528 # Have trailing WS: skip it, then re-check.
3529 0 pos($self->{src}) = $p;
3530 0 $self->{src} =~ /\G[ \t]+/gc;
3531 0 $self->{pos} = pos($self->{src});
3532 0 $hot_had_ws = 1;
3533 0 $p = $self->{pos};
3534 0 ▶ if ($p >= $self->{len}) { return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($p >= $self->{"len"}) 0 0 0
3535 0 $c = substr($self->{src}, $p, 1);
3536 0 ▶ if ($c eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 0 0 0
3537 0 my $np = $p + 1;
3538 0 $self->{pos} = $np;
3539 0 $self->{line}++;
3540 0 $self->{line_start} = $np;
3541 0 return;
3542 }
3543 }
3544 0 ▶ if ($c ne '#' && $c ne '/' && $c ne "\r") {
Branch: 1 branch
BranchTrueFalseTotal
if ($c ne "#" and $c ne "/" and $c ne "\r") 0 0 0
Condition0%0/6
$c ne "#" and $c ne "/" and $c ne "\r"
!ll&&!rl&&r
000
$c ne "#" and $c ne "/"
!ll&&!rl&&r
000
MC/DC0%0/3
$c ne "#" and $c ne "/" and $c ne "\r"
$c ne "#" $c ne "/" $c ne "\r"
Truth table0%0/4
A and B and C
A= $c ne "#"B= $c ne "/"C= $c ne "\r"
ABCresult
0XX0
10X0
1100
1111
3545 0 $self->_die("unexpected character '$c' after value");
3546 }
3547 # else fall through to the comment-handling slow path. Pass
3548 # $hot_had_ws so the first iteration knows ws was already consumed.
3549 }
3550 # Same-line comment(s) after a value attach as `trailing`. Multiple
3551 # block comments may stack; a `#`/`//` line comment, if present,
3552 # consumes to EOL and must come last.
3553 0 my $first_iter = 1;
3554 0 while (1) {
3555 0 my $ws_start = $self->{pos};
3556 0 $self->_skip_inline_ws;
3557 0 my $had_ws = $self->{pos} > $ws_start;
3558 0 ▶ $had_ws = 1 if $first_iter && $hot_had_ws;
Branch: 1 branch
BranchTrueFalseTotal
if $first_iter and $hot_had_ws 0 0 0
Condition0%0/3
$first_iter and $hot_had_ws
!ll&&!rl&&r
000
MC/DC0%0/2
$first_iter and $hot_had_ws
$first_iter $hot_had_ws
Truth table0%0/3
A and B
A= $first_iterB= $hot_had_ws
ABresult
0X0
100
111
3559 0 $first_iter = 0;
3560 0 my $c = $self->_peek;
3561 0 ▶ if (defined($c) && $c eq '#' && !$self->_starts_with("###")) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $c and $c eq '#' and not $self->_starts_with('###')) { } 0 0 0
elsif (defined $c and $c eq '/' and $self->_starts_with('//')) { } 0 0 0
elsif (defined $c and $c eq '/' and $self->_starts_with('/*')) { } 0 0 0
Condition0%0/6
defined $c and $c eq "#" and not $self->_starts_with("###")
!ll&&!rl&&r
000
defined $c and $c eq "#"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c and $c eq "#" and not $self->_starts_with("###")
defined $c $c eq "#" not $self->_starts_with("###")
Truth table0%0/4
A and B and not(C)
A= defined $cB= $c eq "#"C= not $self->_starts_with("###")
ABCresult
0XX0
10X0
1100
1111
3562 0 ▶ $self->_die("expected whitespace before '#' comment") unless $had_ws;
Branch: 1 branch
BranchTrueFalseTotal
unless $had_ws 0 0 0
3563 0 my $raw = $self->_read_line_comment_to_eol;
3564 0 push @{$self->{comments}}, {
3565 comment => { content => $raw, kind => 'line' },
3566 position => 'trailing',
3567 0 path => [@{$self->{path}}],
3568 0 ▶ } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
3569 0 last;
3570 ▶ } elsif (defined($c) && $c eq '/' && $self->_starts_with("//")) {
Condition0%0/6
defined $c and $c eq "/" and $self->_starts_with("//")
!ll&&!rl&&r
000
defined $c and $c eq "/"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c and $c eq "/" and $self->_starts_with("//")
defined $c $c eq "/" $self->_starts_with("//")
Truth table0%0/4
A and B and C
A= defined $cB= $c eq "/"C= $self->_starts_with("//")
ABCresult
0XX0
10X0
1100
1111
3571 0 ▶ $self->_die("expected whitespace before '//' comment") unless $had_ws;
Branch: 1 branch
BranchTrueFalseTotal
unless $had_ws 0 0 0
3572 0 my $raw = $self->_read_line_comment_to_eol;
3573 0 push @{$self->{comments}}, {
3574 comment => { content => $raw, kind => 'line' },
3575 position => 'trailing',
3576 0 path => [@{$self->{path}}],
3577 0 ▶ } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
3578 0 last;
3579 ▶ } elsif (defined($c) && $c eq '/' && $self->_starts_with("/*")) {
Condition0%0/6
defined $c and $c eq "/" and $self->_starts_with("/*")
!ll&&!rl&&r
000
defined $c and $c eq "/"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c and $c eq "/" and $self->_starts_with("/*")
defined $c $c eq "/" $self->_starts_with("/*")
Truth table0%0/4
A and B and C
A= defined $cB= $c eq "/"C= $self->_starts_with("/*")
ABCresult
0XX0
10X0
1100
1111
3580 0 my $raw = $self->_read_c_block_comment;
3581 0 push @{$self->{comments}}, {
3582 comment => { content => $raw, kind => 'block' },
3583 position => 'trailing',
3584 0 path => [@{$self->{path}}],
3585 0 ▶ } unless $self->{lite};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"lite"} 0 0 0
3586 0 next;
3587 } else {
3588 0 last;
3589 }
3590 }
3591 0 my $c = $self->_peek;
3592 0 ▶ return if !defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
3593 0 ▶ if ($c eq "\n") { $self->{pos}++; $self->_advance_line; return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\n") 0 0 0
3594 0 ▶ if ($c eq "\r" && $self->_starts_with("\r\n")) { $self->{pos} += 2; $self->_advance_line; return; }
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "\r" and $self->_starts_with("\r\n")) 0 0 0
Condition0%0/3
$c eq "\r" and $self->_starts_with("\r\n")
!ll&&!rl&&r
000
MC/DC0%0/2
$c eq "\r" and $self->_starts_with("\r\n")
$c eq "\r" $self->_starts_with("\r\n")
Truth table0%0/3
A and B
A= $c eq "\r"B= $self->_starts_with("\r\n")
ABresult
0X0
100
111
3595 0 $self->_die("unexpected character '$c' after value");
3596 }
3597  
3598 3 1;
3599  
3600 __END__
« blib/lib/DMS/Parser/Tier1.pm ↑ Summary blib/lib/DMS/Parser/Emitter.pm »