PluginProbe
Gutenberg / 4.2.0
Gutenberg v4.2.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / parser.php

parser.php in Gutenberg 4.2.0, at lib/parser.php

1,519 lines 48.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Generated by PEG.js 0.10.x with phpegjs plugin
4 *
5 * http://pegjs.majda.cz/
6 */
7
8
9 /* Useful functions: */
10
11 /* Gutenberg_PEG_chr_unicode - get unicode character from its char code */
12 if (!function_exists("Gutenberg_PEG_chr_unicode")) {
13 function Gutenberg_PEG_chr_unicode($code) {
14 return html_entity_decode("&#$code;", ENT_QUOTES, "UTF-8");
15 }
16 }
17 /* Gutenberg_PEG_ord_unicode - get unicode char code from string */
18 if (!function_exists("Gutenberg_PEG_ord_unicode")) {
19 function Gutenberg_PEG_ord_unicode($character) {
20 if (strlen($character) === 1) {
21 return ord($character);
22 }
23 $json = json_encode($character);
24 $utf16_1 = hexdec(substr($json, 3, 4));
25 if (substr($json, 7, 2) === "\u") {
26 $utf16_2 = hexdec(substr($json, 9, 4));
27 return 0x10000 + (($utf16_1 & 0x3ff) << 10) + ($utf16_2 & 0x3ff);
28 } else {
29 return $utf16_1;
30 }
31 }
32 }
33 /* Gutenberg_PEG_peg_char_class_test - simple character class test */
34 if (!function_exists("Gutenberg_PEG_peg_char_class_test")) {
35 function Gutenberg_PEG_peg_char_class_test($class, $character) {
36 $code = Gutenberg_PEG_ord_unicode($character);
37 foreach ($class as $range) {
38 if ($code >= $range[0] && $code <= $range[1]) {
39 return true;
40 }
41 }
42 return false;
43 }
44 }
45
46 /* Syntax error exception */
47 if (!class_exists("Gutenberg_PEG_SyntaxError", false)) {
48 class Gutenberg_PEG_SyntaxError extends Exception {
49 public $expected;
50 public $found;
51 public $grammarOffset;
52 public $grammarLine;
53 public $grammarColumn;
54 public $name;
55 public function __construct($message, $expected, $found, $offset, $line, $column) {
56 parent::__construct($message, 0);
57 $this->expected = $expected;
58 $this->found = $found;
59 $this->grammarOffset = $offset;
60 $this->grammarLine = $line;
61 $this->grammarColumn = $column;
62 $this->name = "Gutenberg_PEG_SyntaxError";
63 }
64 }
65 }
66
67 class Gutenberg_PEG_Parser {
68 private $peg_currPos = 0;
69 private $peg_reportedPos = 0;
70 private $peg_cachedPos = 0;
71 private $peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false );
72 private $peg_maxFailPos = 0;
73 private $peg_maxFailExpected = array();
74 private $peg_silentFails = 0;
75 private $input = array();
76 private $input_length = 0;
77
78 private function cleanup_state() {
79 $this->peg_currPos = 0;
80 $this->peg_reportedPos = 0;
81 $this->peg_cachedPos = 0;
82 $this->peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false );
83 $this->peg_maxFailPos = 0;
84 $this->peg_maxFailExpected = array();
85 $this->peg_silentFails = 0;
86 $this->input = array();
87 $this->input_length = 0;
88
89 }
90
91 private function input_substr($start, $length) {
92 if ($length === 1 && $start < $this->input_length) {
93 return $this->input[$start];
94 }
95 $substr = '';
96 $max = min($start + $length, $this->input_length);
97 for ($i = $start; $i < $max; $i++) {
98 $substr .= $this->input[$i];
99 }
100 return $substr;
101 }
102
103
104 private function text() {
105 return substr($this->input, $this->peg_reportedPos, $this->peg_reportedPos + $this->peg_currPos);
106 }
107
108 private function offset() {
109 return $this->peg_reportedPos;
110 }
111
112 private function line() {
113 $compute_pd = $this->peg_computePosDetails($this->peg_reportedPos);
114 return $compute_pd["line"];
115 }
116
117 private function column() {
118 $compute_pd = $this->peg_computePosDetails($this->peg_reportedPos);
119 return $compute_pd["column"];
120 }
121
122 private function expected($description) {
123 throw $this->peg_buildException(
124 null,
125 array(array("type" => "other", "description" => $description )),
126 $this->peg_reportedPos
127 );
128 }
129
130 private function error($message) {
131 throw $this->peg_buildException($message, null, $this->peg_reportedPos);
132 }
133
134 private function peg_advancePos(&$details, $startPos, $endPos) {
135 for ($p = $startPos; $p < $endPos; $p++) {
136 $ch = $this->input_substr($p, 1);
137 if ($ch === "\n") {
138 if (!$details["seenCR"]) { $details["line"]++; }
139 $details["column"] = 1;
140 $details["seenCR"] = false;
141 } else if ($ch === "\r" || $ch === "\u2028" || $ch === "\u2029") {
142 $details["line"]++;
143 $details["column"] = 1;
144 $details["seenCR"] = true;
145 } else {
146 $details["column"]++;
147 $details["seenCR"] = false;
148 }
149 }
150 }
151
152 private function peg_computePosDetails($pos) {
153 if ($this->peg_cachedPos !== $pos) {
154 if ($this->peg_cachedPos > $pos) {
155 $this->peg_cachedPos = 0;
156 $this->peg_cachedPosDetails = array( "line" => 1, "column" => 1, "seenCR" => false );
157 }
158 $this->peg_advancePos($this->peg_cachedPosDetails, $this->peg_cachedPos, $pos);
159 $this->peg_cachedPos = $pos;
160 }
161
162 return $this->peg_cachedPosDetails;
163 }
164
165 private function peg_fail($expected) {
166 if ($this->peg_currPos < $this->peg_maxFailPos) { return; }
167
168 if ($this->peg_currPos > $this->peg_maxFailPos) {
169 $this->peg_maxFailPos = $this->peg_currPos;
170 $this->peg_maxFailExpected = array();
171 }
172
173 $this->peg_maxFailExpected[] = $expected;
174 }
175
176 private function peg_buildException_expectedComparator($a, $b) {
177 if ($a["description"] < $b["description"]) {
178 return -1;
179 } else if ($a["description"] > $b["description"]) {
180 return 1;
181 } else {
182 return 0;
183 }
184 }
185
186 private function peg_buildException($message, $expected, $pos) {
187 $posDetails = $this->peg_computePosDetails($pos);
188 $found = $pos < $this->input_length ? $this->input[$pos] : null;
189
190 if ($expected !== null) {
191 usort($expected, array($this, "peg_buildException_expectedComparator"));
192 $i = 1;
193 while ($i < count($expected)) {
194 if ($expected[$i - 1] === $expected[$i]) {
195 array_splice($expected, $i, 1);
196 } else {
197 $i++;
198 }
199 }
200 }
201
202 if ($message === null) {
203 $expectedDescs = array_fill(0, count($expected), null);
204
205 for ($i = 0; $i < count($expected); $i++) {
206 $expectedDescs[$i] = $expected[$i]["description"];
207 }
208
209 $expectedDesc = count($expected) > 1
210 ? join(", ", array_slice($expectedDescs, 0, -1))
211 . " or "
212 . $expectedDescs[count($expected) - 1]
213 : $expectedDescs[0];
214
215 $foundDesc = $found ? json_encode($found) : "end of input";
216
217 $message = "Expected " . $expectedDesc . " but " . $foundDesc . " found.";
218 }
219
220 return new Gutenberg_PEG_SyntaxError(
221 $message,
222 $expected,
223 $found,
224 $pos,
225 $posDetails["line"],
226 $posDetails["column"]
227 );
228 }
229
230 private $peg_FAILED;
231 private $peg_c0;
232 private $peg_c1;
233 private $peg_c2;
234 private $peg_c3;
235 private $peg_c4;
236 private $peg_c5;
237 private $peg_c6;
238 private $peg_c7;
239 private $peg_c8;
240 private $peg_c9;
241 private $peg_c10;
242 private $peg_c11;
243 private $peg_c12;
244 private $peg_c13;
245 private $peg_c14;
246 private $peg_c15;
247 private $peg_c16;
248 private $peg_c17;
249 private $peg_c18;
250 private $peg_c19;
251 private $peg_c20;
252 private $peg_c21;
253 private $peg_c22;
254 private $peg_c23;
255 private $peg_c24;
256
257 private function peg_f0($pre, $b, $html) { return array( $b, $html ); }
258 private function peg_f1($pre, $bs, $post) { return peg_join_blocks( $pre, $bs, $post ); }
259 private function peg_f2($blockName, $a) { return $a; }
260 private function peg_f3($blockName, $attrs) {
261 return array(
262 'blockName' => $blockName,
263 'attrs' => isset( $attrs ) ? $attrs : array(),
264 'innerBlocks' => array(),
265 'innerHTML' => '',
266 );
267 }
268 private function peg_f4($s, $children, $e) {
269 list( $innerHTML, $innerBlocks ) = peg_array_partition( $children, 'is_string' );
270
271 return array(
272 'blockName' => $s['blockName'],
273 'attrs' => $s['attrs'],
274 'innerBlocks' => $innerBlocks,
275 'innerHTML' => implode( '', $innerHTML ),
276 );
277 }
278 private function peg_f5($blockName, $attrs) {
279 return array(
280 'blockName' => $blockName,
281 'attrs' => isset( $attrs ) ? $attrs : array(),
282 );
283 }
284 private function peg_f6($blockName) {
285 return array(
286 'blockName' => $blockName,
287 );
288 }
289 private function peg_f7($type) { return "core/$type"; }
290 private function peg_f8($attrs) { return json_decode( $attrs, true ); }
291
292 private function peg_parseBlock_List() {
293
294 $s0 = $this->peg_currPos;
295 $s1 = $this->peg_currPos;
296 $s2 = array();
297 $s3 = $this->peg_currPos;
298 $s4 = $this->peg_currPos;
299 $this->peg_silentFails++;
300 $s5 = $this->peg_parseBlock();
301 $this->peg_silentFails--;
302 if ($s5 === $this->peg_FAILED) {
303 $s4 = null;
304 } else {
305 $this->peg_currPos = $s4;
306 $s4 = $this->peg_FAILED;
307 }
308 if ($s4 !== $this->peg_FAILED) {
309 if ($this->input_length > $this->peg_currPos) {
310 $s5 = $this->input_substr($this->peg_currPos, 1);
311 $this->peg_currPos++;
312 } else {
313 $s5 = $this->peg_FAILED;
314 if ($this->peg_silentFails === 0) {
315 $this->peg_fail($this->peg_c0);
316 }
317 }
318 if ($s5 !== $this->peg_FAILED) {
319 $s4 = array($s4, $s5);
320 $s3 = $s4;
321 } else {
322 $this->peg_currPos = $s3;
323 $s3 = $this->peg_FAILED;
324 }
325 } else {
326 $this->peg_currPos = $s3;
327 $s3 = $this->peg_FAILED;
328 }
329 while ($s3 !== $this->peg_FAILED) {
330 $s2[] = $s3;
331 $s3 = $this->peg_currPos;
332 $s4 = $this->peg_currPos;
333 $this->peg_silentFails++;
334 $s5 = $this->peg_parseBlock();
335 $this->peg_silentFails--;
336 if ($s5 === $this->peg_FAILED) {
337 $s4 = null;
338 } else {
339 $this->peg_currPos = $s4;
340 $s4 = $this->peg_FAILED;
341 }
342 if ($s4 !== $this->peg_FAILED) {
343 if ($this->input_length > $this->peg_currPos) {
344 $s5 = $this->input_substr($this->peg_currPos, 1);
345 $this->peg_currPos++;
346 } else {
347 $s5 = $this->peg_FAILED;
348 if ($this->peg_silentFails === 0) {
349 $this->peg_fail($this->peg_c0);
350 }
351 }
352 if ($s5 !== $this->peg_FAILED) {
353 $s4 = array($s4, $s5);
354 $s3 = $s4;
355 } else {
356 $this->peg_currPos = $s3;
357 $s3 = $this->peg_FAILED;
358 }
359 } else {
360 $this->peg_currPos = $s3;
361 $s3 = $this->peg_FAILED;
362 }
363 }
364 if ($s2 !== $this->peg_FAILED) {
365 $s1 = $this->input_substr($s1, $this->peg_currPos - $s1);
366 } else {
367 $s1 = $s2;
368 }
369 if ($s1 !== $this->peg_FAILED) {
370 $s2 = array();
371 $s3 = $this->peg_currPos;
372 $s4 = $this->peg_parseBlock();
373 if ($s4 !== $this->peg_FAILED) {
374 $s5 = $this->peg_currPos;
375 $s6 = array();
376 $s7 = $this->peg_currPos;
377 $s8 = $this->peg_currPos;
378 $this->peg_silentFails++;
379 $s9 = $this->peg_parseBlock();
380 $this->peg_silentFails--;
381 if ($s9 === $this->peg_FAILED) {
382 $s8 = null;
383 } else {
384 $this->peg_currPos = $s8;
385 $s8 = $this->peg_FAILED;
386 }
387 if ($s8 !== $this->peg_FAILED) {
388 if ($this->input_length > $this->peg_currPos) {
389 $s9 = $this->input_substr($this->peg_currPos, 1);
390 $this->peg_currPos++;
391 } else {
392 $s9 = $this->peg_FAILED;
393 if ($this->peg_silentFails === 0) {
394 $this->peg_fail($this->peg_c0);
395 }
396 }
397 if ($s9 !== $this->peg_FAILED) {
398 $s8 = array($s8, $s9);
399 $s7 = $s8;
400 } else {
401 $this->peg_currPos = $s7;
402 $s7 = $this->peg_FAILED;
403 }
404 } else {
405 $this->peg_currPos = $s7;
406 $s7 = $this->peg_FAILED;
407 }
408 while ($s7 !== $this->peg_FAILED) {
409 $s6[] = $s7;
410 $s7 = $this->peg_currPos;
411 $s8 = $this->peg_currPos;
412 $this->peg_silentFails++;
413 $s9 = $this->peg_parseBlock();
414 $this->peg_silentFails--;
415 if ($s9 === $this->peg_FAILED) {
416 $s8 = null;
417 } else {
418 $this->peg_currPos = $s8;
419 $s8 = $this->peg_FAILED;
420 }
421 if ($s8 !== $this->peg_FAILED) {
422 if ($this->input_length > $this->peg_currPos) {
423 $s9 = $this->input_substr($this->peg_currPos, 1);
424 $this->peg_currPos++;
425 } else {
426 $s9 = $this->peg_FAILED;
427 if ($this->peg_silentFails === 0) {
428 $this->peg_fail($this->peg_c0);
429 }
430 }
431 if ($s9 !== $this->peg_FAILED) {
432 $s8 = array($s8, $s9);
433 $s7 = $s8;
434 } else {
435 $this->peg_currPos = $s7;
436 $s7 = $this->peg_FAILED;
437 }
438 } else {
439 $this->peg_currPos = $s7;
440 $s7 = $this->peg_FAILED;
441 }
442 }
443 if ($s6 !== $this->peg_FAILED) {
444 $s5 = $this->input_substr($s5, $this->peg_currPos - $s5);
445 } else {
446 $s5 = $s6;
447 }
448 if ($s5 !== $this->peg_FAILED) {
449 $this->peg_reportedPos = $s3;
450 $s4 = $this->peg_f0($s1, $s4, $s5);
451 $s3 = $s4;
452 } else {
453 $this->peg_currPos = $s3;
454 $s3 = $this->peg_FAILED;
455 }
456 } else {
457 $this->peg_currPos = $s3;
458 $s3 = $this->peg_FAILED;
459 }
460 while ($s3 !== $this->peg_FAILED) {
461 $s2[] = $s3;
462 $s3 = $this->peg_currPos;
463 $s4 = $this->peg_parseBlock();
464 if ($s4 !== $this->peg_FAILED) {
465 $s5 = $this->peg_currPos;
466 $s6 = array();
467 $s7 = $this->peg_currPos;
468 $s8 = $this->peg_currPos;
469 $this->peg_silentFails++;
470 $s9 = $this->peg_parseBlock();
471 $this->peg_silentFails--;
472 if ($s9 === $this->peg_FAILED) {
473 $s8 = null;
474 } else {
475 $this->peg_currPos = $s8;
476 $s8 = $this->peg_FAILED;
477 }
478 if ($s8 !== $this->peg_FAILED) {
479 if ($this->input_length > $this->peg_currPos) {
480 $s9 = $this->input_substr($this->peg_currPos, 1);
481 $this->peg_currPos++;
482 } else {
483 $s9 = $this->peg_FAILED;
484 if ($this->peg_silentFails === 0) {
485 $this->peg_fail($this->peg_c0);
486 }
487 }
488 if ($s9 !== $this->peg_FAILED) {
489 $s8 = array($s8, $s9);
490 $s7 = $s8;
491 } else {
492 $this->peg_currPos = $s7;
493 $s7 = $this->peg_FAILED;
494 }
495 } else {
496 $this->peg_currPos = $s7;
497 $s7 = $this->peg_FAILED;
498 }
499 while ($s7 !== $this->peg_FAILED) {
500 $s6[] = $s7;
501 $s7 = $this->peg_currPos;
502 $s8 = $this->peg_currPos;
503 $this->peg_silentFails++;
504 $s9 = $this->peg_parseBlock();
505 $this->peg_silentFails--;
506 if ($s9 === $this->peg_FAILED) {
507 $s8 = null;
508 } else {
509 $this->peg_currPos = $s8;
510 $s8 = $this->peg_FAILED;
511 }
512 if ($s8 !== $this->peg_FAILED) {
513 if ($this->input_length > $this->peg_currPos) {
514 $s9 = $this->input_substr($this->peg_currPos, 1);
515 $this->peg_currPos++;
516 } else {
517 $s9 = $this->peg_FAILED;
518 if ($this->peg_silentFails === 0) {
519 $this->peg_fail($this->peg_c0);
520 }
521 }
522 if ($s9 !== $this->peg_FAILED) {
523 $s8 = array($s8, $s9);
524 $s7 = $s8;
525 } else {
526 $this->peg_currPos = $s7;
527 $s7 = $this->peg_FAILED;
528 }
529 } else {
530 $this->peg_currPos = $s7;
531 $s7 = $this->peg_FAILED;
532 }
533 }
534 if ($s6 !== $this->peg_FAILED) {
535 $s5 = $this->input_substr($s5, $this->peg_currPos - $s5);
536 } else {
537 $s5 = $s6;
538 }
539 if ($s5 !== $this->peg_FAILED) {
540 $this->peg_reportedPos = $s3;
541 $s4 = $this->peg_f0($s1, $s4, $s5);
542 $s3 = $s4;
543 } else {
544 $this->peg_currPos = $s3;
545 $s3 = $this->peg_FAILED;
546 }
547 } else {
548 $this->peg_currPos = $s3;
549 $s3 = $this->peg_FAILED;
550 }
551 }
552 if ($s2 !== $this->peg_FAILED) {
553 $s3 = $this->peg_currPos;
554 $s4 = array();
555 if ($this->input_length > $this->peg_currPos) {
556 $s5 = $this->input_substr($this->peg_currPos, 1);
557 $this->peg_currPos++;
558 } else {
559 $s5 = $this->peg_FAILED;
560 if ($this->peg_silentFails === 0) {
561 $this->peg_fail($this->peg_c0);
562 }
563 }
564 while ($s5 !== $this->peg_FAILED) {
565 $s4[] = $s5;
566 if ($this->input_length > $this->peg_currPos) {
567 $s5 = $this->input_substr($this->peg_currPos, 1);
568 $this->peg_currPos++;
569 } else {
570 $s5 = $this->peg_FAILED;
571 if ($this->peg_silentFails === 0) {
572 $this->peg_fail($this->peg_c0);
573 }
574 }
575 }
576 if ($s4 !== $this->peg_FAILED) {
577 $s3 = $this->input_substr($s3, $this->peg_currPos - $s3);
578 } else {
579 $s3 = $s4;
580 }
581 if ($s3 !== $this->peg_FAILED) {
582 $this->peg_reportedPos = $s0;
583 $s1 = $this->peg_f1($s1, $s2, $s3);
584 $s0 = $s1;
585 } else {
586 $this->peg_currPos = $s0;
587 $s0 = $this->peg_FAILED;
588 }
589 } else {
590 $this->peg_currPos = $s0;
591 $s0 = $this->peg_FAILED;
592 }
593 } else {
594 $this->peg_currPos = $s0;
595 $s0 = $this->peg_FAILED;
596 }
597
598 return $s0;
599 }
600
601 private function peg_parseBlock() {
602
603 $s0 = $this->peg_parseBlock_Void();
604 if ($s0 === $this->peg_FAILED) {
605 $s0 = $this->peg_parseBlock_Balanced();
606 }
607
608 return $s0;
609 }
610
611 private function peg_parseBlock_Void() {
612
613 $s0 = $this->peg_currPos;
614 if ($this->input_substr($this->peg_currPos, 4) === $this->peg_c1) {
615 $s1 = $this->peg_c1;
616 $this->peg_currPos += 4;
617 } else {
618 $s1 = $this->peg_FAILED;
619 if ($this->peg_silentFails === 0) {
620 $this->peg_fail($this->peg_c2);
621 }
622 }
623 if ($s1 !== $this->peg_FAILED) {
624 $s2 = $this->peg_parse__();
625 if ($s2 !== $this->peg_FAILED) {
626 if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c3) {
627 $s3 = $this->peg_c3;
628 $this->peg_currPos += 3;
629 } else {
630 $s3 = $this->peg_FAILED;
631 if ($this->peg_silentFails === 0) {
632 $this->peg_fail($this->peg_c4);
633 }
634 }
635 if ($s3 !== $this->peg_FAILED) {
636 $s4 = $this->peg_parseBlock_Name();
637 if ($s4 !== $this->peg_FAILED) {
638 $s5 = $this->peg_parse__();
639 if ($s5 !== $this->peg_FAILED) {
640 $s6 = $this->peg_currPos;
641 $s7 = $this->peg_parseBlock_Attributes();
642 if ($s7 !== $this->peg_FAILED) {
643 $s8 = $this->peg_parse__();
644 if ($s8 !== $this->peg_FAILED) {
645 $this->peg_reportedPos = $s6;
646 $s7 = $this->peg_f2($s4, $s7);
647 $s6 = $s7;
648 } else {
649 $this->peg_currPos = $s6;
650 $s6 = $this->peg_FAILED;
651 }
652 } else {
653 $this->peg_currPos = $s6;
654 $s6 = $this->peg_FAILED;
655 }
656 if ($s6 === $this->peg_FAILED) {
657 $s6 = null;
658 }
659 if ($s6 !== $this->peg_FAILED) {
660 if ($this->input_substr($this->peg_currPos, 4) === $this->peg_c5) {
661 $s7 = $this->peg_c5;
662 $this->peg_currPos += 4;
663 } else {
664 $s7 = $this->peg_FAILED;
665 if ($this->peg_silentFails === 0) {
666 $this->peg_fail($this->peg_c6);
667 }
668 }
669 if ($s7 !== $this->peg_FAILED) {
670 $this->peg_reportedPos = $s0;
671 $s1 = $this->peg_f3($s4, $s6);
672 $s0 = $s1;
673 } else {
674 $this->peg_currPos = $s0;
675 $s0 = $this->peg_FAILED;
676 }
677 } else {
678 $this->peg_currPos = $s0;
679 $s0 = $this->peg_FAILED;
680 }
681 } else {
682 $this->peg_currPos = $s0;
683 $s0 = $this->peg_FAILED;
684 }
685 } else {
686 $this->peg_currPos = $s0;
687 $s0 = $this->peg_FAILED;
688 }
689 } else {
690 $this->peg_currPos = $s0;
691 $s0 = $this->peg_FAILED;
692 }
693 } else {
694 $this->peg_currPos = $s0;
695 $s0 = $this->peg_FAILED;
696 }
697 } else {
698 $this->peg_currPos = $s0;
699 $s0 = $this->peg_FAILED;
700 }
701
702 return $s0;
703 }
704
705 private function peg_parseBlock_Balanced() {
706
707 $s0 = $this->peg_currPos;
708 $s1 = $this->peg_parseBlock_Start();
709 if ($s1 !== $this->peg_FAILED) {
710 $s2 = array();
711 $s3 = $this->peg_parseBlock();
712 if ($s3 === $this->peg_FAILED) {
713 $s3 = $this->peg_currPos;
714 $s4 = $this->peg_currPos;
715 $s5 = $this->peg_currPos;
716 $this->peg_silentFails++;
717 $s6 = $this->peg_parseBlock_End();
718 $this->peg_silentFails--;
719 if ($s6 === $this->peg_FAILED) {
720 $s5 = null;
721 } else {
722 $this->peg_currPos = $s5;
723 $s5 = $this->peg_FAILED;
724 }
725 if ($s5 !== $this->peg_FAILED) {
726 if ($this->input_length > $this->peg_currPos) {
727 $s6 = $this->input_substr($this->peg_currPos, 1);
728 $this->peg_currPos++;
729 } else {
730 $s6 = $this->peg_FAILED;
731 if ($this->peg_silentFails === 0) {
732 $this->peg_fail($this->peg_c0);
733 }
734 }
735 if ($s6 !== $this->peg_FAILED) {
736 $s5 = array($s5, $s6);
737 $s4 = $s5;
738 } else {
739 $this->peg_currPos = $s4;
740 $s4 = $this->peg_FAILED;
741 }
742 } else {
743 $this->peg_currPos = $s4;
744 $s4 = $this->peg_FAILED;
745 }
746 if ($s4 !== $this->peg_FAILED) {
747 $s3 = $this->input_substr($s3, $this->peg_currPos - $s3);
748 } else {
749 $s3 = $s4;
750 }
751 }
752 while ($s3 !== $this->peg_FAILED) {
753 $s2[] = $s3;
754 $s3 = $this->peg_parseBlock();
755 if ($s3 === $this->peg_FAILED) {
756 $s3 = $this->peg_currPos;
757 $s4 = $this->peg_currPos;
758 $s5 = $this->peg_currPos;
759 $this->peg_silentFails++;
760 $s6 = $this->peg_parseBlock_End();
761 $this->peg_silentFails--;
762 if ($s6 === $this->peg_FAILED) {
763 $s5 = null;
764 } else {
765 $this->peg_currPos = $s5;
766 $s5 = $this->peg_FAILED;
767 }
768 if ($s5 !== $this->peg_FAILED) {
769 if ($this->input_length > $this->peg_currPos) {
770 $s6 = $this->input_substr($this->peg_currPos, 1);
771 $this->peg_currPos++;
772 } else {
773 $s6 = $this->peg_FAILED;
774 if ($this->peg_silentFails === 0) {
775 $this->peg_fail($this->peg_c0);
776 }
777 }
778 if ($s6 !== $this->peg_FAILED) {
779 $s5 = array($s5, $s6);
780 $s4 = $s5;
781 } else {
782 $this->peg_currPos = $s4;
783 $s4 = $this->peg_FAILED;
784 }
785 } else {
786 $this->peg_currPos = $s4;
787 $s4 = $this->peg_FAILED;
788 }
789 if ($s4 !== $this->peg_FAILED) {
790 $s3 = $this->input_substr($s3, $this->peg_currPos - $s3);
791 } else {
792 $s3 = $s4;
793 }
794 }
795 }
796 if ($s2 !== $this->peg_FAILED) {
797 $s3 = $this->peg_parseBlock_End();
798 if ($s3 !== $this->peg_FAILED) {
799 $this->peg_reportedPos = $s0;
800 $s1 = $this->peg_f4($s1, $s2, $s3);
801 $s0 = $s1;
802 } else {
803 $this->peg_currPos = $s0;
804 $s0 = $this->peg_FAILED;
805 }
806 } else {
807 $this->peg_currPos = $s0;
808 $s0 = $this->peg_FAILED;
809 }
810 } else {
811 $this->peg_currPos = $s0;
812 $s0 = $this->peg_FAILED;
813 }
814
815 return $s0;
816 }
817
818 private function peg_parseBlock_Start() {
819
820 $s0 = $this->peg_currPos;
821 if ($this->input_substr($this->peg_currPos, 4) === $this->peg_c1) {
822 $s1 = $this->peg_c1;
823 $this->peg_currPos += 4;
824 } else {
825 $s1 = $this->peg_FAILED;
826 if ($this->peg_silentFails === 0) {
827 $this->peg_fail($this->peg_c2);
828 }
829 }
830 if ($s1 !== $this->peg_FAILED) {
831 $s2 = $this->peg_parse__();
832 if ($s2 !== $this->peg_FAILED) {
833 if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c3) {
834 $s3 = $this->peg_c3;
835 $this->peg_currPos += 3;
836 } else {
837 $s3 = $this->peg_FAILED;
838 if ($this->peg_silentFails === 0) {
839 $this->peg_fail($this->peg_c4);
840 }
841 }
842 if ($s3 !== $this->peg_FAILED) {
843 $s4 = $this->peg_parseBlock_Name();
844 if ($s4 !== $this->peg_FAILED) {
845 $s5 = $this->peg_parse__();
846 if ($s5 !== $this->peg_FAILED) {
847 $s6 = $this->peg_currPos;
848 $s7 = $this->peg_parseBlock_Attributes();
849 if ($s7 !== $this->peg_FAILED) {
850 $s8 = $this->peg_parse__();
851 if ($s8 !== $this->peg_FAILED) {
852 $this->peg_reportedPos = $s6;
853 $s7 = $this->peg_f2($s4, $s7);
854 $s6 = $s7;
855 } else {
856 $this->peg_currPos = $s6;
857 $s6 = $this->peg_FAILED;
858 }
859 } else {
860 $this->peg_currPos = $s6;
861 $s6 = $this->peg_FAILED;
862 }
863 if ($s6 === $this->peg_FAILED) {
864 $s6 = null;
865 }
866 if ($s6 !== $this->peg_FAILED) {
867 if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) {
868 $s7 = $this->peg_c7;
869 $this->peg_currPos += 3;
870 } else {
871 $s7 = $this->peg_FAILED;
872 if ($this->peg_silentFails === 0) {
873 $this->peg_fail($this->peg_c8);
874 }
875 }
876 if ($s7 !== $this->peg_FAILED) {
877 $this->peg_reportedPos = $s0;
878 $s1 = $this->peg_f5($s4, $s6);
879 $s0 = $s1;
880 } else {
881 $this->peg_currPos = $s0;
882 $s0 = $this->peg_FAILED;
883 }
884 } else {
885 $this->peg_currPos = $s0;
886 $s0 = $this->peg_FAILED;
887 }
888 } else {
889 $this->peg_currPos = $s0;
890 $s0 = $this->peg_FAILED;
891 }
892 } else {
893 $this->peg_currPos = $s0;
894 $s0 = $this->peg_FAILED;
895 }
896 } else {
897 $this->peg_currPos = $s0;
898 $s0 = $this->peg_FAILED;
899 }
900 } else {
901 $this->peg_currPos = $s0;
902 $s0 = $this->peg_FAILED;
903 }
904 } else {
905 $this->peg_currPos = $s0;
906 $s0 = $this->peg_FAILED;
907 }
908
909 return $s0;
910 }
911
912 private function peg_parseBlock_End() {
913
914 $s0 = $this->peg_currPos;
915 if ($this->input_substr($this->peg_currPos, 4) === $this->peg_c1) {
916 $s1 = $this->peg_c1;
917 $this->peg_currPos += 4;
918 } else {
919 $s1 = $this->peg_FAILED;
920 if ($this->peg_silentFails === 0) {
921 $this->peg_fail($this->peg_c2);
922 }
923 }
924 if ($s1 !== $this->peg_FAILED) {
925 $s2 = $this->peg_parse__();
926 if ($s2 !== $this->peg_FAILED) {
927 if ($this->input_substr($this->peg_currPos, 4) === $this->peg_c9) {
928 $s3 = $this->peg_c9;
929 $this->peg_currPos += 4;
930 } else {
931 $s3 = $this->peg_FAILED;
932 if ($this->peg_silentFails === 0) {
933 $this->peg_fail($this->peg_c10);
934 }
935 }
936 if ($s3 !== $this->peg_FAILED) {
937 $s4 = $this->peg_parseBlock_Name();
938 if ($s4 !== $this->peg_FAILED) {
939 $s5 = $this->peg_parse__();
940 if ($s5 !== $this->peg_FAILED) {
941 if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) {
942 $s6 = $this->peg_c7;
943 $this->peg_currPos += 3;
944 } else {
945 $s6 = $this->peg_FAILED;
946 if ($this->peg_silentFails === 0) {
947 $this->peg_fail($this->peg_c8);
948 }
949 }
950 if ($s6 !== $this->peg_FAILED) {
951 $this->peg_reportedPos = $s0;
952 $s1 = $this->peg_f6($s4);
953 $s0 = $s1;
954 } else {
955 $this->peg_currPos = $s0;
956 $s0 = $this->peg_FAILED;
957 }
958 } else {
959 $this->peg_currPos = $s0;
960 $s0 = $this->peg_FAILED;
961 }
962 } else {
963 $this->peg_currPos = $s0;
964 $s0 = $this->peg_FAILED;
965 }
966 } else {
967 $this->peg_currPos = $s0;
968 $s0 = $this->peg_FAILED;
969 }
970 } else {
971 $this->peg_currPos = $s0;
972 $s0 = $this->peg_FAILED;
973 }
974 } else {
975 $this->peg_currPos = $s0;
976 $s0 = $this->peg_FAILED;
977 }
978
979 return $s0;
980 }
981
982 private function peg_parseBlock_Name() {
983
984 $s0 = $this->peg_parseNamespaced_Block_Name();
985 if ($s0 === $this->peg_FAILED) {
986 $s0 = $this->peg_parseCore_Block_Name();
987 }
988
989 return $s0;
990 }
991
992 private function peg_parseNamespaced_Block_Name() {
993
994 $s0 = $this->peg_currPos;
995 $s1 = $this->peg_currPos;
996 $s2 = $this->peg_parseBlock_Name_Part();
997 if ($s2 !== $this->peg_FAILED) {
998 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c11) {
999 $s3 = $this->peg_c11;
1000 $this->peg_currPos++;
1001 } else {
1002 $s3 = $this->peg_FAILED;
1003 if ($this->peg_silentFails === 0) {
1004 $this->peg_fail($this->peg_c12);
1005 }
1006 }
1007 if ($s3 !== $this->peg_FAILED) {
1008 $s4 = $this->peg_parseBlock_Name_Part();
1009 if ($s4 !== $this->peg_FAILED) {
1010 $s2 = array($s2, $s3, $s4);
1011 $s1 = $s2;
1012 } else {
1013 $this->peg_currPos = $s1;
1014 $s1 = $this->peg_FAILED;
1015 }
1016 } else {
1017 $this->peg_currPos = $s1;
1018 $s1 = $this->peg_FAILED;
1019 }
1020 } else {
1021 $this->peg_currPos = $s1;
1022 $s1 = $this->peg_FAILED;
1023 }
1024 if ($s1 !== $this->peg_FAILED) {
1025 $s0 = $this->input_substr($s0, $this->peg_currPos - $s0);
1026 } else {
1027 $s0 = $s1;
1028 }
1029
1030 return $s0;
1031 }
1032
1033 private function peg_parseCore_Block_Name() {
1034
1035 $s0 = $this->peg_currPos;
1036 $s1 = $this->peg_currPos;
1037 $s2 = $this->peg_parseBlock_Name_Part();
1038 if ($s2 !== $this->peg_FAILED) {
1039 $s1 = $this->input_substr($s1, $this->peg_currPos - $s1);
1040 } else {
1041 $s1 = $s2;
1042 }
1043 if ($s1 !== $this->peg_FAILED) {
1044 $this->peg_reportedPos = $s0;
1045 $s1 = $this->peg_f7($s1);
1046 }
1047 $s0 = $s1;
1048
1049 return $s0;
1050 }
1051
1052 private function peg_parseBlock_Name_Part() {
1053
1054 $s0 = $this->peg_currPos;
1055 $s1 = $this->peg_currPos;
1056 if (Gutenberg_PEG_peg_char_class_test($this->peg_c13, $this->input_substr($this->peg_currPos, 1))) {
1057 $s2 = $this->input_substr($this->peg_currPos, 1);
1058 $this->peg_currPos++;
1059 } else {
1060 $s2 = $this->peg_FAILED;
1061 if ($this->peg_silentFails === 0) {
1062 $this->peg_fail($this->peg_c14);
1063 }
1064 }
1065 if ($s2 !== $this->peg_FAILED) {
1066 $s3 = array();
1067 if (Gutenberg_PEG_peg_char_class_test($this->peg_c15, $this->input_substr($this->peg_currPos, 1))) {
1068 $s4 = $this->input_substr($this->peg_currPos, 1);
1069 $this->peg_currPos++;
1070 } else {
1071 $s4 = $this->peg_FAILED;
1072 if ($this->peg_silentFails === 0) {
1073 $this->peg_fail($this->peg_c16);
1074 }
1075 }
1076 while ($s4 !== $this->peg_FAILED) {
1077 $s3[] = $s4;
1078 if (Gutenberg_PEG_peg_char_class_test($this->peg_c15, $this->input_substr($this->peg_currPos, 1))) {
1079 $s4 = $this->input_substr($this->peg_currPos, 1);
1080 $this->peg_currPos++;
1081 } else {
1082 $s4 = $this->peg_FAILED;
1083 if ($this->peg_silentFails === 0) {
1084 $this->peg_fail($this->peg_c16);
1085 }
1086 }
1087 }
1088 if ($s3 !== $this->peg_FAILED) {
1089 $s2 = array($s2, $s3);
1090 $s1 = $s2;
1091 } else {
1092 $this->peg_currPos = $s1;
1093 $s1 = $this->peg_FAILED;
1094 }
1095 } else {
1096 $this->peg_currPos = $s1;
1097 $s1 = $this->peg_FAILED;
1098 }
1099 if ($s1 !== $this->peg_FAILED) {
1100 $s0 = $this->input_substr($s0, $this->peg_currPos - $s0);
1101 } else {
1102 $s0 = $s1;
1103 }
1104
1105 return $s0;
1106 }
1107
1108 private function peg_parseBlock_Attributes() {
1109
1110 $this->peg_silentFails++;
1111 $s0 = $this->peg_currPos;
1112 $s1 = $this->peg_currPos;
1113 $s2 = $this->peg_currPos;
1114 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c18) {
1115 $s3 = $this->peg_c18;
1116 $this->peg_currPos++;
1117 } else {
1118 $s3 = $this->peg_FAILED;
1119 if ($this->peg_silentFails === 0) {
1120 $this->peg_fail($this->peg_c19);
1121 }
1122 }
1123 if ($s3 !== $this->peg_FAILED) {
1124 $s4 = array();
1125 $s5 = $this->peg_currPos;
1126 $s6 = $this->peg_currPos;
1127 $this->peg_silentFails++;
1128 $s7 = $this->peg_currPos;
1129 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) {
1130 $s8 = $this->peg_c20;
1131 $this->peg_currPos++;
1132 } else {
1133 $s8 = $this->peg_FAILED;
1134 if ($this->peg_silentFails === 0) {
1135 $this->peg_fail($this->peg_c21);
1136 }
1137 }
1138 if ($s8 !== $this->peg_FAILED) {
1139 $s9 = $this->peg_parse__();
1140 if ($s9 !== $this->peg_FAILED) {
1141 $s10 = $this->peg_c22;
1142 if ($s10 !== $this->peg_FAILED) {
1143 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c11) {
1144 $s11 = $this->peg_c11;
1145 $this->peg_currPos++;
1146 } else {
1147 $s11 = $this->peg_FAILED;
1148 if ($this->peg_silentFails === 0) {
1149 $this->peg_fail($this->peg_c12);
1150 }
1151 }
1152 if ($s11 === $this->peg_FAILED) {
1153 $s11 = null;
1154 }
1155 if ($s11 !== $this->peg_FAILED) {
1156 if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) {
1157 $s12 = $this->peg_c7;
1158 $this->peg_currPos += 3;
1159 } else {
1160 $s12 = $this->peg_FAILED;
1161 if ($this->peg_silentFails === 0) {
1162 $this->peg_fail($this->peg_c8);
1163 }
1164 }
1165 if ($s12 !== $this->peg_FAILED) {
1166 $s8 = array($s8, $s9, $s10, $s11, $s12);
1167 $s7 = $s8;
1168 } else {
1169 $this->peg_currPos = $s7;
1170 $s7 = $this->peg_FAILED;
1171 }
1172 } else {
1173 $this->peg_currPos = $s7;
1174 $s7 = $this->peg_FAILED;
1175 }
1176 } else {
1177 $this->peg_currPos = $s7;
1178 $s7 = $this->peg_FAILED;
1179 }
1180 } else {
1181 $this->peg_currPos = $s7;
1182 $s7 = $this->peg_FAILED;
1183 }
1184 } else {
1185 $this->peg_currPos = $s7;
1186 $s7 = $this->peg_FAILED;
1187 }
1188 $this->peg_silentFails--;
1189 if ($s7 === $this->peg_FAILED) {
1190 $s6 = null;
1191 } else {
1192 $this->peg_currPos = $s6;
1193 $s6 = $this->peg_FAILED;
1194 }
1195 if ($s6 !== $this->peg_FAILED) {
1196 if ($this->input_length > $this->peg_currPos) {
1197 $s7 = $this->input_substr($this->peg_currPos, 1);
1198 $this->peg_currPos++;
1199 } else {
1200 $s7 = $this->peg_FAILED;
1201 if ($this->peg_silentFails === 0) {
1202 $this->peg_fail($this->peg_c0);
1203 }
1204 }
1205 if ($s7 !== $this->peg_FAILED) {
1206 $s6 = array($s6, $s7);
1207 $s5 = $s6;
1208 } else {
1209 $this->peg_currPos = $s5;
1210 $s5 = $this->peg_FAILED;
1211 }
1212 } else {
1213 $this->peg_currPos = $s5;
1214 $s5 = $this->peg_FAILED;
1215 }
1216 while ($s5 !== $this->peg_FAILED) {
1217 $s4[] = $s5;
1218 $s5 = $this->peg_currPos;
1219 $s6 = $this->peg_currPos;
1220 $this->peg_silentFails++;
1221 $s7 = $this->peg_currPos;
1222 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) {
1223 $s8 = $this->peg_c20;
1224 $this->peg_currPos++;
1225 } else {
1226 $s8 = $this->peg_FAILED;
1227 if ($this->peg_silentFails === 0) {
1228 $this->peg_fail($this->peg_c21);
1229 }
1230 }
1231 if ($s8 !== $this->peg_FAILED) {
1232 $s9 = $this->peg_parse__();
1233 if ($s9 !== $this->peg_FAILED) {
1234 $s10 = $this->peg_c22;
1235 if ($s10 !== $this->peg_FAILED) {
1236 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c11) {
1237 $s11 = $this->peg_c11;
1238 $this->peg_currPos++;
1239 } else {
1240 $s11 = $this->peg_FAILED;
1241 if ($this->peg_silentFails === 0) {
1242 $this->peg_fail($this->peg_c12);
1243 }
1244 }
1245 if ($s11 === $this->peg_FAILED) {
1246 $s11 = null;
1247 }
1248 if ($s11 !== $this->peg_FAILED) {
1249 if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) {
1250 $s12 = $this->peg_c7;
1251 $this->peg_currPos += 3;
1252 } else {
1253 $s12 = $this->peg_FAILED;
1254 if ($this->peg_silentFails === 0) {
1255 $this->peg_fail($this->peg_c8);
1256 }
1257 }
1258 if ($s12 !== $this->peg_FAILED) {
1259 $s8 = array($s8, $s9, $s10, $s11, $s12);
1260 $s7 = $s8;
1261 } else {
1262 $this->peg_currPos = $s7;
1263 $s7 = $this->peg_FAILED;
1264 }
1265 } else {
1266 $this->peg_currPos = $s7;
1267 $s7 = $this->peg_FAILED;
1268 }
1269 } else {
1270 $this->peg_currPos = $s7;
1271 $s7 = $this->peg_FAILED;
1272 }
1273 } else {
1274 $this->peg_currPos = $s7;
1275 $s7 = $this->peg_FAILED;
1276 }
1277 } else {
1278 $this->peg_currPos = $s7;
1279 $s7 = $this->peg_FAILED;
1280 }
1281 $this->peg_silentFails--;
1282 if ($s7 === $this->peg_FAILED) {
1283 $s6 = null;
1284 } else {
1285 $this->peg_currPos = $s6;
1286 $s6 = $this->peg_FAILED;
1287 }
1288 if ($s6 !== $this->peg_FAILED) {
1289 if ($this->input_length > $this->peg_currPos) {
1290 $s7 = $this->input_substr($this->peg_currPos, 1);
1291 $this->peg_currPos++;
1292 } else {
1293 $s7 = $this->peg_FAILED;
1294 if ($this->peg_silentFails === 0) {
1295 $this->peg_fail($this->peg_c0);
1296 }
1297 }
1298 if ($s7 !== $this->peg_FAILED) {
1299 $s6 = array($s6, $s7);
1300 $s5 = $s6;
1301 } else {
1302 $this->peg_currPos = $s5;
1303 $s5 = $this->peg_FAILED;
1304 }
1305 } else {
1306 $this->peg_currPos = $s5;
1307 $s5 = $this->peg_FAILED;
1308 }
1309 }
1310 if ($s4 !== $this->peg_FAILED) {
1311 if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) {
1312 $s5 = $this->peg_c20;
1313 $this->peg_currPos++;
1314 } else {
1315 $s5 = $this->peg_FAILED;
1316 if ($this->peg_silentFails === 0) {
1317 $this->peg_fail($this->peg_c21);
1318 }
1319 }
1320 if ($s5 !== $this->peg_FAILED) {
1321 $s3 = array($s3, $s4, $s5);
1322 $s2 = $s3;
1323 } else {
1324 $this->peg_currPos = $s2;
1325 $s2 = $this->peg_FAILED;
1326 }
1327 } else {
1328 $this->peg_currPos = $s2;
1329 $s2 = $this->peg_FAILED;
1330 }
1331 } else {
1332 $this->peg_currPos = $s2;
1333 $s2 = $this->peg_FAILED;
1334 }
1335 if ($s2 !== $this->peg_FAILED) {
1336 $s1 = $this->input_substr($s1, $this->peg_currPos - $s1);
1337 } else {
1338 $s1 = $s2;
1339 }
1340 if ($s1 !== $this->peg_FAILED) {
1341 $this->peg_reportedPos = $s0;
1342 $s1 = $this->peg_f8($s1);
1343 }
1344 $s0 = $s1;
1345 $this->peg_silentFails--;
1346 if ($s0 === $this->peg_FAILED) {
1347 $s1 = $this->peg_FAILED;
1348 if ($this->peg_silentFails === 0) {
1349 $this->peg_fail($this->peg_c17);
1350 }
1351 }
1352
1353 return $s0;
1354 }
1355
1356 private function peg_parse__() {
1357
1358 $s0 = array();
1359 if (Gutenberg_PEG_peg_char_class_test($this->peg_c23, $this->input_substr($this->peg_currPos, 1))) {
1360 $s1 = $this->input_substr($this->peg_currPos, 1);
1361 $this->peg_currPos++;
1362 } else {
1363 $s1 = $this->peg_FAILED;
1364 if ($this->peg_silentFails === 0) {
1365 $this->peg_fail($this->peg_c24);
1366 }
1367 }
1368 if ($s1 !== $this->peg_FAILED) {
1369 while ($s1 !== $this->peg_FAILED) {
1370 $s0[] = $s1;
1371 if (Gutenberg_PEG_peg_char_class_test($this->peg_c23, $this->input_substr($this->peg_currPos, 1))) {
1372 $s1 = $this->input_substr($this->peg_currPos, 1);
1373 $this->peg_currPos++;
1374 } else {
1375 $s1 = $this->peg_FAILED;
1376 if ($this->peg_silentFails === 0) {
1377 $this->peg_fail($this->peg_c24);
1378 }
1379 }
1380 }
1381 } else {
1382 $s0 = $this->peg_FAILED;
1383 }
1384
1385 return $s0;
1386 }
1387
1388 public function parse($input) {
1389 $arguments = func_get_args();
1390 $options = count($arguments) > 1 ? $arguments[1] : array();
1391 $this->cleanup_state();
1392
1393 if (is_array($input)) {
1394 $this->input = $input;
1395 } else {
1396 preg_match_all("/./us", $input, $match);
1397 $this->input = $match[0];
1398 }
1399 $this->input_length = count($this->input);
1400
1401 $this->peg_FAILED = new stdClass;
1402 $this->peg_c0 = array("type" => "any", "description" => "any character" );
1403 $this->peg_c1 = "<!--";
1404 $this->peg_c2 = array( "type" => "literal", "value" => "<!--", "description" => "\"<!--\"" );
1405 $this->peg_c3 = "wp:";
1406 $this->peg_c4 = array( "type" => "literal", "value" => "wp:", "description" => "\"wp:\"" );
1407 $this->peg_c5 = "/-->";
1408 $this->peg_c6 = array( "type" => "literal", "value" => "/-->", "description" => "\"/-->\"" );
1409 $this->peg_c7 = "-->";
1410 $this->peg_c8 = array( "type" => "literal", "value" => "-->", "description" => "\"-->\"" );
1411 $this->peg_c9 = "/wp:";
1412 $this->peg_c10 = array( "type" => "literal", "value" => "/wp:", "description" => "\"/wp:\"" );
1413 $this->peg_c11 = "/";
1414 $this->peg_c12 = array( "type" => "literal", "value" => "/", "description" => "\"/\"" );
1415 $this->peg_c13 = array(array(97,122));
1416 $this->peg_c14 = array( "type" => "class", "value" => "[a-z]", "description" => "[a-z]" );
1417 $this->peg_c15 = array(array(97,122), array(48,57), array(95,95), array(45,45));
1418 $this->peg_c16 = array( "type" => "class", "value" => "[a-z0-9_-]", "description" => "[a-z0-9_-]" );
1419 $this->peg_c17 = array("type" => "other", "description" => "JSON-encoded attributes embedded in a block's opening comment" );
1420 $this->peg_c18 = "{";
1421 $this->peg_c19 = array( "type" => "literal", "value" => "{", "description" => "\"{\"" );
1422 $this->peg_c20 = "}";
1423 $this->peg_c21 = array( "type" => "literal", "value" => "}", "description" => "\"}\"" );
1424 $this->peg_c22 = "";
1425 $this->peg_c23 = array(array(32,32), array(9,9), array(13,13), array(10,10));
1426 $this->peg_c24 = array( "type" => "class", "value" => "[ \t\r\n]", "description" => "[ \t\r\n]" );
1427
1428 $peg_startRuleFunctions = array( 'Block_List' => array($this, "peg_parseBlock_List") );
1429 $peg_startRuleFunction = array($this, "peg_parseBlock_List");
1430 if (isset($options["startRule"])) {
1431 if (!(isset($peg_startRuleFunctions[$options["startRule"]]))) {
1432 throw new Exception("Can't start parsing from rule \"" + $options["startRule"] + "\".");
1433 }
1434
1435 $peg_startRuleFunction = $peg_startRuleFunctions[$options["startRule"]];
1436 }
1437
1438 /* BEGIN initializer code */
1439
1440 // The `maybeJSON` function is not needed in PHP because its return semantics
1441 // are the same as `json_decode`
1442
1443 // array arguments are backwards because of PHP
1444 if ( ! function_exists( 'peg_array_partition' ) ) {
1445 function peg_array_partition( $array, $predicate ) {
1446 $truthy = array();
1447 $falsey = array();
1448
1449 foreach ( $array as $item ) {
1450 call_user_func( $predicate, $item )
1451 ? $truthy[] = $item
1452 : $falsey[] = $item;
1453 }
1454
1455 return array( $truthy, $falsey );
1456 }
1457 }
1458
1459 if ( ! function_exists( 'peg_join_blocks' ) ) {
1460 function peg_join_blocks( $pre, $tokens, $post ) {
1461 $blocks = array();
1462
1463 if ( ! empty( $pre ) ) {
1464 $blocks[] = array(
1465 'blockName' => null,
1466 'attrs' => array(),
1467 'innerBlocks' => array(),
1468 'innerHTML' => $pre
1469 );
1470 }
1471
1472 foreach ( $tokens as $token ) {
1473 list( $token, $html ) = $token;
1474
1475 $blocks[] = $token;
1476
1477 if ( ! empty( $html ) ) {
1478 $blocks[] = array(
1479 'blockName' => null,
1480 'attrs' => array(),
1481 'innerBlocks' => array(),
1482 'innerHTML' => $html
1483 );
1484 }
1485 }
1486
1487 if ( ! empty( $post ) ) {
1488 $blocks[] = array(
1489 'blockName' => null,
1490 'attrs' => array(),
1491 'innerBlocks' => array(),
1492 'innerHTML' => $post
1493 );
1494 }
1495
1496 return $blocks;
1497 }
1498 }
1499
1500
1501 /* END initializer code */
1502
1503 $peg_result = call_user_func($peg_startRuleFunction);
1504
1505 if ($peg_result !== $this->peg_FAILED && $this->peg_currPos === $this->input_length) {
1506 $this->cleanup_state(); // Free up memory
1507 return $peg_result;
1508 } else {
1509 if ($peg_result !== $this->peg_FAILED && $this->peg_currPos < $this->input_length) {
1510 $this->peg_fail(array("type" => "end", "description" => "end of input" ));
1511 }
1512
1513 $exception = $this->peg_buildException(null, $this->peg_maxFailExpected, $this->peg_maxFailPos);
1514 $this->cleanup_state(); // Free up memory
1515 throw $exception;
1516 }
1517 }
1518
1519 };