Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 773
0.00% covered (danger)
0.00%
0 / 38
CRAP
0.00% covered (danger)
0.00%
0 / 1
MediaWiki\Extension\Math\WikiTexVC\chr_unicode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
MediaWiki\Extension\Math\WikiTexVC\ord_unicode
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
MediaWiki\Extension\Math\WikiTexVC\peg_regex_test
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
ParserIntent
0.00% covered (danger)
0.00%
0 / 758
0.00% covered (danger)
0.00%
0 / 35
60270
0.00% covered (danger)
0.00%
0 / 1
 cleanup_state
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 input_substr
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
 text
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 offset
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 line
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 column
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 expected
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 error
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 peg_advancePos
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
56
 peg_computePosDetails
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 peg_fail
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 peg_buildException_expectedComparator
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 peg_buildException
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
90
 peg_f0
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 peg_f1
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
 peg_f2
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 peg_f3
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 peg_f4
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 peg_f5
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 peg_f6
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 peg_f7
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 peg_parsestart
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
 peg_parseintent
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
42
 peg_parseconcept_or_literal
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
20
 peg_parsenumber
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 1
272
 peg_parsedigits
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
30
 peg_parsedigit
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
 peg_parsereference
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 1
56
 peg_parsestructure
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 1
930
 peg_parseapplication
0.00% covered (danger)
0.00%
0 / 107
0.00% covered (danger)
0.00%
0 / 1
1122
 peg_parsearguments
0.00% covered (danger)
0.00%
0 / 89
0.00% covered (danger)
0.00%
0 / 1
702
 peg_parsehint
0.00% covered (danger)
0.00%
0 / 78
0.00% covered (danger)
0.00%
0 / 1
930
 peg_parseNCName
0.00% covered (danger)
0.00%
0 / 54
0.00% covered (danger)
0.00%
0 / 1
272
 peg_parseWS
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
42
 parse
0.00% covered (danger)
0.00%
0 / 82
0.00% covered (danger)
0.00%
0 / 1
90
1<?php
2/*
3 * Generated by peggy 1.0.0 with phpeggy plugin
4 *
5 * https://peggyjs.org/
6 */
7
8namespace MediaWiki\Extension\Math\WikiTexVC;
9
10/* Useful functions: */
11
12/* chr_unicode - get unicode character from its char code */
13if (!function_exists("MediaWiki\\Extension\\Math\\WikiTexVC\\chr_unicode")) {
14    function chr_unicode($code) {
15        return html_entity_decode("&#$code;", ENT_QUOTES, "UTF-8");
16    }
17}
18/* ord_unicode - get unicode char code from string */
19if (!function_exists("MediaWiki\\Extension\\Math\\WikiTexVC\\ord_unicode")) {
20    function ord_unicode($character) {
21        if (strlen($character) === 1) {
22            return ord($character);
23        }
24        $json = json_encode($character);
25        $utf16_1 = hexdec(substr($json, 3, 4));
26        if (substr($json, 7, 2) === "\u") {
27            $utf16_2 = hexdec(substr($json, 9, 4));
28            return 0x10000 + (($utf16_1 & 0x3ff) << 10) + ($utf16_2 & 0x3ff);
29        } else {
30            return $utf16_1;
31        }
32    }
33}
34/* peg_regex_test - multibyte regex test */
35if (!function_exists("MediaWiki\\Extension\\Math\\WikiTexVC\\peg_regex_test")) {
36    function peg_regex_test($pattern, $string) {
37        if (substr($pattern, -1) == "i") {
38            return mb_eregi(substr($pattern, 1, -2), $string);
39        } else {
40            return mb_ereg(substr($pattern, 1, -1), $string);
41        }
42    }
43}
44
45class ParserIntent {
46    private $peg_currPos          = 0;
47    private $peg_reportedPos      = 0;
48    private $peg_cachedPos        = 0;
49    private $peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false );
50    private $peg_maxFailPos       = 0;
51    private $peg_maxFailExpected  = array();
52    private $peg_silentFails      = 0;
53    private $input                = array();
54    private $input_length         = 0;
55    public $peg_cache = array();
56
57    private function cleanup_state() {
58      $this->peg_currPos          = 0;
59      $this->peg_reportedPos      = 0;
60      $this->peg_cachedPos        = 0;
61      $this->peg_cachedPosDetails = array('line' => 1, 'column' => 1, 'seenCR' => false );
62      $this->peg_maxFailPos       = 0;
63      $this->peg_maxFailExpected  = array();
64      $this->peg_silentFails      = 0;
65      $this->input                = array();
66      $this->input_length         = 0;
67      $this->peg_cache = array();
68    }
69
70    private function input_substr($start, $length) {
71      if ($length === 1 && $start < $this->input_length) {
72        return $this->input[$start];
73      }
74      $substr = '';
75      $max = min($start + $length, $this->input_length);
76      for ($i = $start; $i < $max; $i++) {
77        $substr .= $this->input[$i];
78      }
79      return $substr;
80    }
81
82
83    private function text() {
84      return $this->input_substr($this->peg_reportedPos, $this->peg_currPos - $this->peg_reportedPos);
85    }
86
87    private function offset() {
88      return $this->peg_reportedPos;
89    }
90
91    private function line() {
92      $compute_pd = $this->peg_computePosDetails($this->peg_reportedPos);
93      return $compute_pd["line"];
94    }
95
96    private function column() {
97      $compute_pd = $this->peg_computePosDetails($this->peg_reportedPos);
98      return $compute_pd["column"];
99    }
100
101    private function expected($description) {
102      throw $this->peg_buildException(
103        null,
104        array(array("type" => "other", "description" => $description )),
105        $this->peg_reportedPos
106      );
107    }
108
109    private function error($message) {
110      throw $this->peg_buildException($message, null, $this->peg_reportedPos);
111    }
112
113    private function peg_advancePos(&$details, $startPos, $endPos) {
114      for ($p = $startPos; $p < $endPos; $p++) {
115        $ch = $this->input_substr($p, 1);
116        if ($ch === "\n") {
117          if (!$details["seenCR"]) { $details["line"]++; }
118          $details["column"] = 1;
119          $details["seenCR"] = false;
120        } else if ($ch === "\r" || $ch === "\u2028" || $ch === "\u2029") {
121          $details["line"]++;
122          $details["column"] = 1;
123          $details["seenCR"] = true;
124        } else {
125          $details["column"]++;
126          $details["seenCR"] = false;
127        }
128      }
129    }
130
131    private function peg_computePosDetails($pos) {
132      if ($this->peg_cachedPos !== $pos) {
133        if ($this->peg_cachedPos > $pos) {
134          $this->peg_cachedPos = 0;
135          $this->peg_cachedPosDetails = array( "line" => 1, "column" => 1, "seenCR" => false );
136        }
137        $this->peg_advancePos($this->peg_cachedPosDetails, $this->peg_cachedPos, $pos);
138        $this->peg_cachedPos = $pos;
139      }
140
141      return $this->peg_cachedPosDetails;
142    }
143
144    private function peg_fail($expected) {
145      if ($this->peg_currPos < $this->peg_maxFailPos) { return; }
146
147      if ($this->peg_currPos > $this->peg_maxFailPos) {
148        $this->peg_maxFailPos = $this->peg_currPos;
149        $this->peg_maxFailExpected = array();
150      }
151
152      $this->peg_maxFailExpected[] = $expected;
153    }
154
155    private function peg_buildException_expectedComparator($a, $b) {
156      if ($a["description"] < $b["description"]) {
157        return -1;
158      } else if ($a["description"] > $b["description"]) {
159        return 1;
160      } else {
161        return 0;
162      }
163    }
164
165    private function peg_buildException($message, $expected, $pos) {
166      $posDetails = $this->peg_computePosDetails($pos);
167      $found      = $pos < $this->input_length ? $this->input[$pos] : null;
168
169      if ($expected !== null) {
170        usort($expected, array($this, "peg_buildException_expectedComparator"));
171        $i = 1;
172        while ($i < count($expected)) {
173          if ($expected[$i - 1] === $expected[$i]) {
174            array_splice($expected, $i, 1);
175          } else {
176            $i++;
177          }
178        }
179      }
180
181      if ($message === null) {
182        $expectedDescs = array_fill(0, count($expected), null);
183
184        for ($i = 0; $i < count($expected); $i++) {
185          $expectedDescs[$i] = $expected[$i]["description"];
186        }
187
188        $expectedDesc = count($expected) > 1
189          ? join(", ", array_slice($expectedDescs, 0, -1))
190              . " or "
191              . $expectedDescs[count($expected) - 1]
192          : $expectedDescs[0];
193
194        $foundDesc = $found ? json_encode($found) : "end of input";
195
196        $message = "Expected " . $expectedDesc . " but " . $foundDesc . " found.";
197      }
198
199      return new SyntaxError(
200        $message,
201        $expected,
202        $found,
203        $pos,
204        $posDetails["line"],
205        $posDetails["column"]
206      );
207    }
208
209    private $peg_FAILED;
210    private $peg_c0;
211    private $peg_c1;
212    private $peg_c2;
213    private $peg_c3;
214    private $peg_c4;
215    private $peg_c5;
216    private $peg_c6;
217    private $peg_c7;
218    private $peg_c8;
219    private $peg_c9;
220    private $peg_c10;
221    private $peg_c11;
222    private $peg_c12;
223    private $peg_c13;
224    private $peg_c14;
225    private $peg_c15;
226    private $peg_c16;
227    private $peg_c17;
228    private $peg_c18;
229    private $peg_c19;
230    private $peg_c20;
231    private $peg_c21;
232    private $peg_c22;
233    private $peg_c23;
234    private $peg_c24;
235    private $peg_c25;
236    private $peg_c26;
237    private $peg_c27;
238    private $peg_c28;
239    private $peg_c29;
240    private $peg_c30;
241    private $peg_c31;
242    private $peg_c32;
243    private $peg_c33;
244    private $peg_c34;
245    private $peg_c35;
246    private $peg_c36;
247    private $peg_c37;
248    private $peg_c38;
249    private $peg_c39;
250    private $peg_c40;
251    private $peg_c41;
252    private $peg_c42;
253    private $peg_c43;
254    private $peg_c44;
255    private $peg_c45;
256    private $peg_c46;
257    private $peg_c47;
258    private $peg_c48;
259    private $peg_c49;
260    private $peg_c50;
261    private $peg_c51;
262    private $peg_c52;
263    private $peg_c53;
264
265    private function peg_f0() {
266        return $this->text();
267    }
268    private function peg_f1($sign, $intPart, $fracPart, $hint) {
269                $intPartS = implode($intPart ?? []);
270                $fracPartS = implode($fracPart[1] ?? []);
271                $value = $sign ?? "";
272                $value .= $intPartS;
273                $value .= isset($fracPart) ? ("." . $fracPartS ) : "";
274                return ["type" => "number", "value" => $value, "hint"=>$hint];
275            }
276    private function peg_f2() {
277        return substr($this->text(),1);
278    }
279    private function peg_f3($intent, $hint, $args) {
280        $argsF = [];
281        foreach ($args as $arg) {
282           $argsF[] = $arg[2];
283        }
284       $returnObj =  [
285             "type" => "application",
286             "intent" => $intent,
287             "hint" => isset($hint) ? $hint : null,
288             "arguments" => $argsF
289         ];
290       return $returnObj;
291    }
292    private function peg_f4($first, $rest) {
293          $args = [$first];
294          foreach ($rest as $arg) {
295              $args[] = $arg[2];
296          }
297          return $args;
298    }
299    private function peg_f5($hintType) {
300        return $hintType;
301    }
302    private function peg_f6() { return $this->text(); }
303    private function peg_f7() {return " "; }
304
305    private function peg_parsestart() {
306
307      $key = $this->peg_currPos * 13 + 0;
308      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
309
310      if ($cached) {
311        $this->peg_currPos = $cached["nextPos"];
312        return $cached["result"];
313      }
314
315      $s0 = $this->peg_parseapplication();
316      if ($s0 === $this->peg_FAILED) {
317        $s0 = $this->peg_parseintent();
318      }
319
320      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
321
322      return $s0;
323    }
324
325    private function peg_parseintent() {
326
327      $key = $this->peg_currPos * 13 + 1;
328      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
329
330      if ($cached) {
331        $this->peg_currPos = $cached["nextPos"];
332        return $cached["result"];
333      }
334
335      $s0 = $this->peg_parseconcept_or_literal();
336      if ($s0 === $this->peg_FAILED) {
337        $s0 = $this->peg_parsenumber();
338        if ($s0 === $this->peg_FAILED) {
339          $s0 = $this->peg_parsereference();
340          if ($s0 === $this->peg_FAILED) {
341            $s0 = $this->peg_parsestructure();
342          }
343        }
344      }
345
346      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
347
348      return $s0;
349    }
350
351    private function peg_parseconcept_or_literal() {
352
353      $key = $this->peg_currPos * 13 + 2;
354      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
355
356      if ($cached) {
357        $this->peg_currPos = $cached["nextPos"];
358        return $cached["result"];
359      }
360
361      $s0 = $this->peg_currPos;
362      $s1 = $this->peg_parseNCName();
363      if ($s1 !== $this->peg_FAILED) {
364        $this->peg_reportedPos = $s0;
365        $s1 = $this->peg_f0();
366      }
367      $s0 = $s1;
368
369      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
370
371      return $s0;
372    }
373
374    private function peg_parsenumber() {
375
376      $key = $this->peg_currPos * 13 + 3;
377      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
378
379      if ($cached) {
380        $this->peg_currPos = $cached["nextPos"];
381        return $cached["result"];
382      }
383
384      $s0 = $this->peg_currPos;
385      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c0) {
386        $s1 = $this->peg_c0;
387        $this->peg_currPos++;
388      } else {
389        $s1 = $this->peg_FAILED;
390        if ($this->peg_silentFails === 0) {
391            $this->peg_fail($this->peg_c1);
392        }
393      }
394      if ($s1 === $this->peg_FAILED) {
395        $s1 = null;
396      }
397      if ($s1 !== $this->peg_FAILED) {
398        $s2 = $this->peg_parsedigits();
399        if ($s2 !== $this->peg_FAILED) {
400          $s3 = $this->peg_currPos;
401          if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c2) {
402            $s4 = $this->peg_c2;
403            $this->peg_currPos++;
404          } else {
405            $s4 = $this->peg_FAILED;
406            if ($this->peg_silentFails === 0) {
407                $this->peg_fail($this->peg_c3);
408            }
409          }
410          if ($s4 !== $this->peg_FAILED) {
411            $s5 = $this->peg_parsedigits();
412            if ($s5 !== $this->peg_FAILED) {
413              $s4 = array($s4, $s5);
414              $s3 = $s4;
415            } else {
416              $this->peg_currPos = $s3;
417              $s3 = $this->peg_FAILED;
418            }
419          } else {
420            $this->peg_currPos = $s3;
421            $s3 = $this->peg_FAILED;
422          }
423          if ($s3 === $this->peg_FAILED) {
424            $s3 = null;
425          }
426          if ($s3 !== $this->peg_FAILED) {
427            $s4 = $this->peg_parsehint();
428            if ($s4 === $this->peg_FAILED) {
429              $s4 = null;
430            }
431            if ($s4 !== $this->peg_FAILED) {
432              $this->peg_reportedPos = $s0;
433              $s1 = $this->peg_f1($s1, $s2, $s3, $s4);
434              $s0 = $s1;
435            } else {
436              $this->peg_currPos = $s0;
437              $s0 = $this->peg_FAILED;
438            }
439          } else {
440            $this->peg_currPos = $s0;
441            $s0 = $this->peg_FAILED;
442          }
443        } else {
444          $this->peg_currPos = $s0;
445          $s0 = $this->peg_FAILED;
446        }
447      } else {
448        $this->peg_currPos = $s0;
449        $s0 = $this->peg_FAILED;
450      }
451
452      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
453
454      return $s0;
455    }
456
457    private function peg_parsedigits() {
458
459      $key = $this->peg_currPos * 13 + 4;
460      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
461
462      if ($cached) {
463        $this->peg_currPos = $cached["nextPos"];
464        return $cached["result"];
465      }
466
467      $s0 = array();
468      $s1 = $this->peg_parsedigit();
469      if ($s1 !== $this->peg_FAILED) {
470        while ($s1 !== $this->peg_FAILED) {
471          $s0[] = $s1;
472          $s1 = $this->peg_parsedigit();
473        }
474      } else {
475        $s0 = $this->peg_FAILED;
476      }
477
478      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
479
480      return $s0;
481    }
482
483    private function peg_parsedigit() {
484
485      $key = $this->peg_currPos * 13 + 5;
486      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
487
488      if ($cached) {
489        $this->peg_currPos = $cached["nextPos"];
490        return $cached["result"];
491      }
492
493      if (peg_regex_test($this->peg_c4, $this->input_substr($this->peg_currPos, 1))) {
494        $s0 = $this->input_substr($this->peg_currPos, 1);
495        $this->peg_currPos++;
496      } else {
497        $s0 = $this->peg_FAILED;
498        if ($this->peg_silentFails === 0) {
499            $this->peg_fail($this->peg_c5);
500        }
501      }
502
503      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
504
505      return $s0;
506    }
507
508    private function peg_parsereference() {
509
510      $key = $this->peg_currPos * 13 + 6;
511      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
512
513      if ($cached) {
514        $this->peg_currPos = $cached["nextPos"];
515        return $cached["result"];
516      }
517
518      $s0 = $this->peg_currPos;
519      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c6) {
520        $s1 = $this->peg_c6;
521        $this->peg_currPos++;
522      } else {
523        $s1 = $this->peg_FAILED;
524        if ($this->peg_silentFails === 0) {
525            $this->peg_fail($this->peg_c7);
526        }
527      }
528      if ($s1 !== $this->peg_FAILED) {
529        $s2 = $this->peg_parseNCName();
530        if ($s2 !== $this->peg_FAILED) {
531          $this->peg_reportedPos = $s0;
532          $s1 = $this->peg_f2();
533          $s0 = $s1;
534        } else {
535          $this->peg_currPos = $s0;
536          $s0 = $this->peg_FAILED;
537        }
538      } else {
539        $this->peg_currPos = $s0;
540        $s0 = $this->peg_FAILED;
541      }
542
543      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
544
545      return $s0;
546    }
547
548    private function peg_parsestructure() {
549
550      $key = $this->peg_currPos * 13 + 7;
551      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
552
553      if ($cached) {
554        $this->peg_currPos = $cached["nextPos"];
555        return $cached["result"];
556      }
557
558      $s0 = $this->peg_currPos;
559      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c8) {
560        $s1 = $this->peg_c8;
561        $this->peg_currPos++;
562      } else {
563        $s1 = $this->peg_FAILED;
564        if ($this->peg_silentFails === 0) {
565            $this->peg_fail($this->peg_c9);
566        }
567      }
568      if ($s1 !== $this->peg_FAILED) {
569        if ($this->input_substr($this->peg_currPos, 6) === $this->peg_c10) {
570          $s2 = $this->peg_c10;
571          $this->peg_currPos += 6;
572        } else {
573          $s2 = $this->peg_FAILED;
574          if ($this->peg_silentFails === 0) {
575              $this->peg_fail($this->peg_c11);
576          }
577        }
578        if ($s2 === $this->peg_FAILED) {
579          if ($this->input_substr($this->peg_currPos, 9) === $this->peg_c12) {
580            $s2 = $this->peg_c12;
581            $this->peg_currPos += 9;
582          } else {
583            $s2 = $this->peg_FAILED;
584            if ($this->peg_silentFails === 0) {
585                $this->peg_fail($this->peg_c13);
586            }
587          }
588          if ($s2 === $this->peg_FAILED) {
589            if ($this->input_substr($this->peg_currPos, 9) === $this->peg_c14) {
590              $s2 = $this->peg_c14;
591              $this->peg_currPos += 9;
592            } else {
593              $s2 = $this->peg_FAILED;
594              if ($this->peg_silentFails === 0) {
595                  $this->peg_fail($this->peg_c15);
596              }
597            }
598            if ($s2 === $this->peg_FAILED) {
599              if ($this->input_substr($this->peg_currPos, 6) === $this->peg_c16) {
600                $s2 = $this->peg_c16;
601                $this->peg_currPos += 6;
602              } else {
603                $s2 = $this->peg_FAILED;
604                if ($this->peg_silentFails === 0) {
605                    $this->peg_fail($this->peg_c17);
606                }
607              }
608              if ($s2 === $this->peg_FAILED) {
609                if ($this->input_substr($this->peg_currPos, 9) === $this->peg_c18) {
610                  $s2 = $this->peg_c18;
611                  $this->peg_currPos += 9;
612                } else {
613                  $s2 = $this->peg_FAILED;
614                  if ($this->peg_silentFails === 0) {
615                      $this->peg_fail($this->peg_c19);
616                  }
617                }
618                if ($s2 === $this->peg_FAILED) {
619                  if ($this->input_substr($this->peg_currPos, 16) === $this->peg_c20) {
620                    $s2 = $this->peg_c20;
621                    $this->peg_currPos += 16;
622                  } else {
623                    $s2 = $this->peg_FAILED;
624                    if ($this->peg_silentFails === 0) {
625                        $this->peg_fail($this->peg_c21);
626                    }
627                  }
628                  if ($s2 === $this->peg_FAILED) {
629                    if ($this->input_substr($this->peg_currPos, 16) === $this->peg_c22) {
630                      $s2 = $this->peg_c22;
631                      $this->peg_currPos += 16;
632                    } else {
633                      $s2 = $this->peg_FAILED;
634                      if ($this->peg_silentFails === 0) {
635                          $this->peg_fail($this->peg_c23);
636                      }
637                    }
638                    if ($s2 === $this->peg_FAILED) {
639                      if ($this->input_substr($this->peg_currPos, 17) === $this->peg_c24) {
640                        $s2 = $this->peg_c24;
641                        $this->peg_currPos += 17;
642                      } else {
643                        $s2 = $this->peg_FAILED;
644                        if ($this->peg_silentFails === 0) {
645                            $this->peg_fail($this->peg_c25);
646                        }
647                      }
648                    }
649                  }
650                }
651              }
652            }
653          }
654        }
655        if ($s2 !== $this->peg_FAILED) {
656          $this->peg_reportedPos = $s0;
657          $s1 = $this->peg_f2();
658          $s0 = $s1;
659        } else {
660          $this->peg_currPos = $s0;
661          $s0 = $this->peg_FAILED;
662        }
663      } else {
664        $this->peg_currPos = $s0;
665        $s0 = $this->peg_FAILED;
666      }
667
668      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
669
670      return $s0;
671    }
672
673    private function peg_parseapplication() {
674
675      $key = $this->peg_currPos * 13 + 8;
676      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
677
678      if ($cached) {
679        $this->peg_currPos = $cached["nextPos"];
680        return $cached["result"];
681      }
682
683      $s0 = $this->peg_currPos;
684      $s1 = $this->peg_parseintent();
685      if ($s1 !== $this->peg_FAILED) {
686        $s2 = $this->peg_parsehint();
687        if ($s2 === $this->peg_FAILED) {
688          $s2 = null;
689        }
690        if ($s2 !== $this->peg_FAILED) {
691          $s3 = array();
692          $s4 = $this->peg_currPos;
693          if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c26) {
694            $s5 = $this->peg_c26;
695            $this->peg_currPos++;
696          } else {
697            $s5 = $this->peg_FAILED;
698            if ($this->peg_silentFails === 0) {
699                $this->peg_fail($this->peg_c27);
700            }
701          }
702          if ($s5 !== $this->peg_FAILED) {
703            $s6 = $this->peg_parseWS();
704            if ($s6 === $this->peg_FAILED) {
705              $s6 = null;
706            }
707            if ($s6 !== $this->peg_FAILED) {
708              $s7 = $this->peg_parsearguments();
709              if ($s7 === $this->peg_FAILED) {
710                $s7 = null;
711              }
712              if ($s7 !== $this->peg_FAILED) {
713                $s8 = $this->peg_parseWS();
714                if ($s8 === $this->peg_FAILED) {
715                  $s8 = null;
716                }
717                if ($s8 !== $this->peg_FAILED) {
718                  if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c28) {
719                    $s9 = $this->peg_c28;
720                    $this->peg_currPos++;
721                  } else {
722                    $s9 = $this->peg_FAILED;
723                    if ($this->peg_silentFails === 0) {
724                        $this->peg_fail($this->peg_c29);
725                    }
726                  }
727                  if ($s9 !== $this->peg_FAILED) {
728                    $s5 = array($s5, $s6, $s7, $s8, $s9);
729                    $s4 = $s5;
730                  } else {
731                    $this->peg_currPos = $s4;
732                    $s4 = $this->peg_FAILED;
733                  }
734                } else {
735                  $this->peg_currPos = $s4;
736                  $s4 = $this->peg_FAILED;
737                }
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          } else {
747            $this->peg_currPos = $s4;
748            $s4 = $this->peg_FAILED;
749          }
750          if ($s4 !== $this->peg_FAILED) {
751            while ($s4 !== $this->peg_FAILED) {
752              $s3[] = $s4;
753              $s4 = $this->peg_currPos;
754              if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c26) {
755                $s5 = $this->peg_c26;
756                $this->peg_currPos++;
757              } else {
758                $s5 = $this->peg_FAILED;
759                if ($this->peg_silentFails === 0) {
760                    $this->peg_fail($this->peg_c27);
761                }
762              }
763              if ($s5 !== $this->peg_FAILED) {
764                $s6 = $this->peg_parseWS();
765                if ($s6 === $this->peg_FAILED) {
766                  $s6 = null;
767                }
768                if ($s6 !== $this->peg_FAILED) {
769                  $s7 = $this->peg_parsearguments();
770                  if ($s7 === $this->peg_FAILED) {
771                    $s7 = null;
772                  }
773                  if ($s7 !== $this->peg_FAILED) {
774                    $s8 = $this->peg_parseWS();
775                    if ($s8 === $this->peg_FAILED) {
776                      $s8 = null;
777                    }
778                    if ($s8 !== $this->peg_FAILED) {
779                      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c28) {
780                        $s9 = $this->peg_c28;
781                        $this->peg_currPos++;
782                      } else {
783                        $s9 = $this->peg_FAILED;
784                        if ($this->peg_silentFails === 0) {
785                            $this->peg_fail($this->peg_c29);
786                        }
787                      }
788                      if ($s9 !== $this->peg_FAILED) {
789                        $s5 = array($s5, $s6, $s7, $s8, $s9);
790                        $s4 = $s5;
791                      } else {
792                        $this->peg_currPos = $s4;
793                        $s4 = $this->peg_FAILED;
794                      }
795                    } else {
796                      $this->peg_currPos = $s4;
797                      $s4 = $this->peg_FAILED;
798                    }
799                  } else {
800                    $this->peg_currPos = $s4;
801                    $s4 = $this->peg_FAILED;
802                  }
803                } else {
804                  $this->peg_currPos = $s4;
805                  $s4 = $this->peg_FAILED;
806                }
807              } else {
808                $this->peg_currPos = $s4;
809                $s4 = $this->peg_FAILED;
810              }
811            }
812          } else {
813            $s3 = $this->peg_FAILED;
814          }
815          if ($s3 !== $this->peg_FAILED) {
816            $this->peg_reportedPos = $s0;
817            $s1 = $this->peg_f3($s1, $s2, $s3);
818            $s0 = $s1;
819          } else {
820            $this->peg_currPos = $s0;
821            $s0 = $this->peg_FAILED;
822          }
823        } else {
824          $this->peg_currPos = $s0;
825          $s0 = $this->peg_FAILED;
826        }
827      } else {
828        $this->peg_currPos = $s0;
829        $s0 = $this->peg_FAILED;
830      }
831
832      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
833
834      return $s0;
835    }
836
837    private function peg_parsearguments() {
838
839      $key = $this->peg_currPos * 13 + 9;
840      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
841
842      if ($cached) {
843        $this->peg_currPos = $cached["nextPos"];
844        return $cached["result"];
845      }
846
847      $s0 = $this->peg_currPos;
848      $s1 = $this->peg_parseWS();
849      if ($s1 === $this->peg_FAILED) {
850        $s1 = null;
851      }
852      if ($s1 !== $this->peg_FAILED) {
853        $s2 = $this->peg_parsestart();
854        if ($s2 !== $this->peg_FAILED) {
855          $s3 = $this->peg_parseWS();
856          if ($s3 === $this->peg_FAILED) {
857            $s3 = null;
858          }
859          if ($s3 !== $this->peg_FAILED) {
860            $s4 = array();
861            $s5 = $this->peg_currPos;
862            if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c30) {
863              $s6 = $this->peg_c30;
864              $this->peg_currPos++;
865            } else {
866              $s6 = $this->peg_FAILED;
867              if ($this->peg_silentFails === 0) {
868                  $this->peg_fail($this->peg_c31);
869              }
870            }
871            if ($s6 !== $this->peg_FAILED) {
872              $s7 = $this->peg_parseWS();
873              if ($s7 === $this->peg_FAILED) {
874                $s7 = null;
875              }
876              if ($s7 !== $this->peg_FAILED) {
877                $s8 = $this->peg_parsestart();
878                if ($s8 !== $this->peg_FAILED) {
879                  $s9 = $this->peg_parseWS();
880                  if ($s9 === $this->peg_FAILED) {
881                    $s9 = null;
882                  }
883                  if ($s9 !== $this->peg_FAILED) {
884                    $s6 = array($s6, $s7, $s8, $s9);
885                    $s5 = $s6;
886                  } else {
887                    $this->peg_currPos = $s5;
888                    $s5 = $this->peg_FAILED;
889                  }
890                } else {
891                  $this->peg_currPos = $s5;
892                  $s5 = $this->peg_FAILED;
893                }
894              } else {
895                $this->peg_currPos = $s5;
896                $s5 = $this->peg_FAILED;
897              }
898            } else {
899              $this->peg_currPos = $s5;
900              $s5 = $this->peg_FAILED;
901            }
902            while ($s5 !== $this->peg_FAILED) {
903              $s4[] = $s5;
904              $s5 = $this->peg_currPos;
905              if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c30) {
906                $s6 = $this->peg_c30;
907                $this->peg_currPos++;
908              } else {
909                $s6 = $this->peg_FAILED;
910                if ($this->peg_silentFails === 0) {
911                    $this->peg_fail($this->peg_c31);
912                }
913              }
914              if ($s6 !== $this->peg_FAILED) {
915                $s7 = $this->peg_parseWS();
916                if ($s7 === $this->peg_FAILED) {
917                  $s7 = null;
918                }
919                if ($s7 !== $this->peg_FAILED) {
920                  $s8 = $this->peg_parsestart();
921                  if ($s8 !== $this->peg_FAILED) {
922                    $s9 = $this->peg_parseWS();
923                    if ($s9 === $this->peg_FAILED) {
924                      $s9 = null;
925                    }
926                    if ($s9 !== $this->peg_FAILED) {
927                      $s6 = array($s6, $s7, $s8, $s9);
928                      $s5 = $s6;
929                    } else {
930                      $this->peg_currPos = $s5;
931                      $s5 = $this->peg_FAILED;
932                    }
933                  } else {
934                    $this->peg_currPos = $s5;
935                    $s5 = $this->peg_FAILED;
936                  }
937                } else {
938                  $this->peg_currPos = $s5;
939                  $s5 = $this->peg_FAILED;
940                }
941              } else {
942                $this->peg_currPos = $s5;
943                $s5 = $this->peg_FAILED;
944              }
945            }
946            if ($s4 !== $this->peg_FAILED) {
947              $this->peg_reportedPos = $s0;
948              $s1 = $this->peg_f4($s2, $s4);
949              $s0 = $s1;
950            } else {
951              $this->peg_currPos = $s0;
952              $s0 = $this->peg_FAILED;
953            }
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
967      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
968
969      return $s0;
970    }
971
972    private function peg_parsehint() {
973
974      $key = $this->peg_currPos * 13 + 10;
975      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
976
977      if ($cached) {
978        $this->peg_currPos = $cached["nextPos"];
979        return $cached["result"];
980      }
981
982      $s0 = $this->peg_currPos;
983      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c32) {
984        $s1 = $this->peg_c32;
985        $this->peg_currPos++;
986      } else {
987        $s1 = $this->peg_FAILED;
988        if ($this->peg_silentFails === 0) {
989            $this->peg_fail($this->peg_c33);
990        }
991      }
992      if ($s1 === $this->peg_FAILED) {
993        if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c8) {
994          $s1 = $this->peg_c8;
995          $this->peg_currPos++;
996        } else {
997          $s1 = $this->peg_FAILED;
998          if ($this->peg_silentFails === 0) {
999              $this->peg_fail($this->peg_c9);
1000          }
1001        }
1002      }
1003      if ($s1 !== $this->peg_FAILED) {
1004        if ($this->input_substr($this->peg_currPos, 6) === $this->peg_c34) {
1005          $s2 = $this->peg_c34;
1006          $this->peg_currPos += 6;
1007        } else {
1008          $s2 = $this->peg_FAILED;
1009          if ($this->peg_silentFails === 0) {
1010              $this->peg_fail($this->peg_c35);
1011          }
1012        }
1013        if ($s2 === $this->peg_FAILED) {
1014          if ($this->input_substr($this->peg_currPos, 5) === $this->peg_c36) {
1015            $s2 = $this->peg_c36;
1016            $this->peg_currPos += 5;
1017          } else {
1018            $s2 = $this->peg_FAILED;
1019            if ($this->peg_silentFails === 0) {
1020                $this->peg_fail($this->peg_c37);
1021            }
1022          }
1023          if ($s2 === $this->peg_FAILED) {
1024            if ($this->input_substr($this->peg_currPos, 7) === $this->peg_c38) {
1025              $s2 = $this->peg_c38;
1026              $this->peg_currPos += 7;
1027            } else {
1028              $s2 = $this->peg_FAILED;
1029              if ($this->peg_silentFails === 0) {
1030                  $this->peg_fail($this->peg_c39);
1031              }
1032            }
1033            if ($s2 === $this->peg_FAILED) {
1034              if ($this->input_substr($this->peg_currPos, 8) === $this->peg_c40) {
1035                $s2 = $this->peg_c40;
1036                $this->peg_currPos += 8;
1037              } else {
1038                $s2 = $this->peg_FAILED;
1039                if ($this->peg_silentFails === 0) {
1040                    $this->peg_fail($this->peg_c41);
1041                }
1042              }
1043              if ($s2 === $this->peg_FAILED) {
1044                if ($this->input_substr($this->peg_currPos, 6) === $this->peg_c42) {
1045                  $s2 = $this->peg_c42;
1046                  $this->peg_currPos += 6;
1047                } else {
1048                  $s2 = $this->peg_FAILED;
1049                  if ($this->peg_silentFails === 0) {
1050                      $this->peg_fail($this->peg_c43);
1051                  }
1052                }
1053                if ($s2 === $this->peg_FAILED) {
1054                  if ($this->input_substr($this->peg_currPos, 13) === $this->peg_c44) {
1055                    $s2 = $this->peg_c44;
1056                    $this->peg_currPos += 13;
1057                  } else {
1058                    $s2 = $this->peg_FAILED;
1059                    if ($this->peg_silentFails === 0) {
1060                        $this->peg_fail($this->peg_c45);
1061                    }
1062                  }
1063                  if ($s2 === $this->peg_FAILED) {
1064                    if ($this->input_substr($this->peg_currPos, 15) === $this->peg_c46) {
1065                      $s2 = $this->peg_c46;
1066                      $this->peg_currPos += 15;
1067                    } else {
1068                      $s2 = $this->peg_FAILED;
1069                      if ($this->peg_silentFails === 0) {
1070                          $this->peg_fail($this->peg_c47);
1071                      }
1072                    }
1073                  }
1074                }
1075              }
1076            }
1077          }
1078        }
1079        if ($s2 !== $this->peg_FAILED) {
1080          $this->peg_reportedPos = $s0;
1081          $s1 = $this->peg_f5($s2);
1082          $s0 = $s1;
1083        } else {
1084          $this->peg_currPos = $s0;
1085          $s0 = $this->peg_FAILED;
1086        }
1087      } else {
1088        $this->peg_currPos = $s0;
1089        $s0 = $this->peg_FAILED;
1090      }
1091
1092      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
1093
1094      return $s0;
1095    }
1096
1097    private function peg_parseNCName() {
1098
1099      $key = $this->peg_currPos * 13 + 11;
1100      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
1101
1102      if ($cached) {
1103        $this->peg_currPos = $cached["nextPos"];
1104        return $cached["result"];
1105      }
1106
1107      $s0 = $this->peg_currPos;
1108      $s1 = $this->peg_currPos;
1109      $this->peg_silentFails++;
1110      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c8) {
1111        $s2 = $this->peg_c8;
1112        $this->peg_currPos++;
1113      } else {
1114        $s2 = $this->peg_FAILED;
1115        if ($this->peg_silentFails === 0) {
1116            $this->peg_fail($this->peg_c9);
1117        }
1118      }
1119      $this->peg_silentFails--;
1120      if ($s2 === $this->peg_FAILED) {
1121        $s1 = null;
1122      } else {
1123        $this->peg_currPos = $s1;
1124        $s1 = $this->peg_FAILED;
1125      }
1126      if ($s1 !== $this->peg_FAILED) {
1127        if (peg_regex_test($this->peg_c48, $this->input_substr($this->peg_currPos, 1))) {
1128          $s2 = $this->input_substr($this->peg_currPos, 1);
1129          $this->peg_currPos++;
1130        } else {
1131          $s2 = $this->peg_FAILED;
1132          if ($this->peg_silentFails === 0) {
1133              $this->peg_fail($this->peg_c49);
1134          }
1135        }
1136        if ($s2 !== $this->peg_FAILED) {
1137          $s3 = array();
1138          if (peg_regex_test($this->peg_c50, $this->input_substr($this->peg_currPos, 1))) {
1139            $s4 = $this->input_substr($this->peg_currPos, 1);
1140            $this->peg_currPos++;
1141          } else {
1142            $s4 = $this->peg_FAILED;
1143            if ($this->peg_silentFails === 0) {
1144                $this->peg_fail($this->peg_c51);
1145            }
1146          }
1147          while ($s4 !== $this->peg_FAILED) {
1148            $s3[] = $s4;
1149            if (peg_regex_test($this->peg_c50, $this->input_substr($this->peg_currPos, 1))) {
1150              $s4 = $this->input_substr($this->peg_currPos, 1);
1151              $this->peg_currPos++;
1152            } else {
1153              $s4 = $this->peg_FAILED;
1154              if ($this->peg_silentFails === 0) {
1155                  $this->peg_fail($this->peg_c51);
1156              }
1157            }
1158          }
1159          if ($s3 !== $this->peg_FAILED) {
1160            $this->peg_reportedPos = $s0;
1161            $s1 = $this->peg_f6();
1162            $s0 = $s1;
1163          } else {
1164            $this->peg_currPos = $s0;
1165            $s0 = $this->peg_FAILED;
1166          }
1167        } else {
1168          $this->peg_currPos = $s0;
1169          $s0 = $this->peg_FAILED;
1170        }
1171      } else {
1172        $this->peg_currPos = $s0;
1173        $s0 = $this->peg_FAILED;
1174      }
1175
1176      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
1177
1178      return $s0;
1179    }
1180
1181    private function peg_parseWS() {
1182
1183      $key = $this->peg_currPos * 13 + 12;
1184      $cached = isset($this->peg_cache[$key]) ? $this->peg_cache[$key] : null;
1185
1186      if ($cached) {
1187        $this->peg_currPos = $cached["nextPos"];
1188        return $cached["result"];
1189      }
1190
1191      $s0 = $this->peg_currPos;
1192      if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c52) {
1193        $s1 = $this->peg_c52;
1194        $this->peg_currPos++;
1195      } else {
1196        $s1 = $this->peg_FAILED;
1197        if ($this->peg_silentFails === 0) {
1198            $this->peg_fail($this->peg_c53);
1199        }
1200      }
1201      if ($s1 !== $this->peg_FAILED) {
1202        $this->peg_reportedPos = $s0;
1203        $s1 = $this->peg_f7();
1204      }
1205      $s0 = $s1;
1206
1207      $this->peg_cache[$key] = array ("nextPos" => $this->peg_currPos, "result" => $s0 );
1208
1209      return $s0;
1210    }
1211
1212  public function parse($input) {
1213    $arguments = func_get_args();
1214    $options = count($arguments) > 1 ? $arguments[1] : array();
1215    $this->cleanup_state();
1216
1217    if (is_array($input)) {
1218        $this->input = $input;
1219    } else {
1220        preg_match_all("/./us", $input, $match);
1221        $this->input = $match[0];
1222    }
1223    $this->input_length = count($this->input);
1224
1225    $old_regex_encoding = mb_regex_encoding();
1226    mb_regex_encoding("UTF-8");
1227
1228    $this->peg_FAILED = new \stdClass;
1229    $this->peg_c0 = "-";
1230    $this->peg_c1 = array( "type" => "literal", "value" => "-", "description" => "\"-\"" );
1231    $this->peg_c2 = ".";
1232    $this->peg_c3 = array( "type" => "literal", "value" => ".", "description" => "\".\"" );
1233    $this->peg_c4 = "/^[0-9]/";
1234    $this->peg_c5 = array( "type" => "class", "value" => "[0-9]", "description" => "[0-9]" );
1235    $this->peg_c6 = "$";
1236    $this->peg_c7 = array( "type" => "literal", "value" => "$", "description" => "\"$\"" );
1237    $this->peg_c8 = ":";
1238    $this->peg_c9 = array( "type" => "literal", "value" => ":", "description" => "\":\"" );
1239    $this->peg_c10 = "common";
1240    $this->peg_c11 = array( "type" => "literal", "value" => "common", "description" => "\"common\"" );
1241    $this->peg_c12 = "structure";
1242    $this->peg_c13 = array( "type" => "literal", "value" => "structure", "description" => "\"structure\"" );
1243    $this->peg_c14 = "chemistry";
1244    $this->peg_c15 = array( "type" => "literal", "value" => "chemistry", "description" => "\"chemistry\"" );
1245    $this->peg_c16 = "matrix";
1246    $this->peg_c17 = array( "type" => "literal", "value" => "matrix", "description" => "\"matrix\"" );
1247    $this->peg_c18 = "equations";
1248    $this->peg_c19 = array( "type" => "literal", "value" => "equations", "description" => "\"equations\"" );
1249    $this->peg_c20 = "chemical-element";
1250    $this->peg_c21 = array( "type" => "literal", "value" => "chemical-element", "description" => "\"chemical-element\"" );
1251    $this->peg_c22 = "chemical-formula";
1252    $this->peg_c23 = array( "type" => "literal", "value" => "chemical-formula", "description" => "\"chemical-formula\"" );
1253    $this->peg_c24 = "chemical-equation";
1254    $this->peg_c25 = array( "type" => "literal", "value" => "chemical-equation", "description" => "\"chemical-equation\"" );
1255    $this->peg_c26 = "(";
1256    $this->peg_c27 = array( "type" => "literal", "value" => "(", "description" => "\"(\"" );
1257    $this->peg_c28 = ")";
1258    $this->peg_c29 = array( "type" => "literal", "value" => ")", "description" => "\")\"" );
1259    $this->peg_c30 = ",";
1260    $this->peg_c31 = array( "type" => "literal", "value" => ",", "description" => "\",\"" );
1261    $this->peg_c32 = "@";
1262    $this->peg_c33 = array( "type" => "literal", "value" => "@", "description" => "\"@\"" );
1263    $this->peg_c34 = "prefix";
1264    $this->peg_c35 = array( "type" => "literal", "value" => "prefix", "description" => "\"prefix\"" );
1265    $this->peg_c36 = "infix";
1266    $this->peg_c37 = array( "type" => "literal", "value" => "infix", "description" => "\"infix\"" );
1267    $this->peg_c38 = "postfix";
1268    $this->peg_c39 = array( "type" => "literal", "value" => "postfix", "description" => "\"postfix\"" );
1269    $this->peg_c40 = "function";
1270    $this->peg_c41 = array( "type" => "literal", "value" => "function", "description" => "\"function\"" );
1271    $this->peg_c42 = "silent";
1272    $this->peg_c43 = array( "type" => "literal", "value" => "silent", "description" => "\"silent\"" );
1273    $this->peg_c44 = "decimal-comma";
1274    $this->peg_c45 = array( "type" => "literal", "value" => "decimal-comma", "description" => "\"decimal-comma\"" );
1275    $this->peg_c46 = "thousands-comma";
1276    $this->peg_c47 = array( "type" => "literal", "value" => "thousands-comma", "description" => "\"thousands-comma\"" );
1277    $this->peg_c48 = "/^[a-zA-Z_]/";
1278    $this->peg_c49 = array( "type" => "class", "value" => "[a-zA-Z_]", "description" => "[a-zA-Z_]" );
1279    $this->peg_c50 = "/^[a-zA-Z0-9._-]/";
1280    $this->peg_c51 = array( "type" => "class", "value" => "[a-zA-Z0-9._-]", "description" => "[a-zA-Z0-9._-]" );
1281    $this->peg_c52 = " ";
1282    $this->peg_c53 = array( "type" => "literal", "value" => " ", "description" => "\" \"" );
1283
1284    $peg_startRuleFunctions = array( 'start' => array($this, "peg_parsestart") );
1285    $peg_startRuleFunction  = array($this, "peg_parsestart");
1286    if (isset($options["startRule"])) {
1287      if (!(isset($peg_startRuleFunctions[$options["startRule"]]))) {
1288        throw new \Exception("Can't start parsing from rule \"" . $options["startRule"] . "\".");
1289      }
1290
1291      $peg_startRuleFunction = $peg_startRuleFunctions[$options["startRule"]];
1292    }
1293    $peg_result = call_user_func($peg_startRuleFunction);
1294
1295    $this->peg_cache = array();
1296
1297    mb_regex_encoding($old_regex_encoding);
1298
1299    if ($peg_result !== $this->peg_FAILED && $this->peg_currPos === $this->input_length) {
1300      $this->cleanup_state(); // Free up memory
1301      return $peg_result;
1302    } else {
1303      if ($peg_result !== $this->peg_FAILED && $this->peg_currPos < $this->input_length) {
1304        $this->peg_fail(array("type" => "end", "description" => "end of input" ));
1305      }
1306
1307      $exception = $this->peg_buildException(null, $this->peg_maxFailExpected, $this->peg_maxFailPos);
1308      $this->cleanup_state(); // Free up memory
1309      throw $exception;
1310    }
1311  }
1312
1313};