function buildParser($parser)
 {
     $class = 'Parser' . sha1($parser);
     echo ParserCompiler::compile("class {$class} extends \\PhpPeg\\Parser {\n {$parser}\n}") . "\n\n\n";
     eval(ParserCompiler::compile("class {$class} extends \\PhpPeg\\Parser {\n {$parser}\n}"));
     return new ParserTestWrapper($this, $class);
 }
Пример #2
0
<?php

require 'Compiler.php';
ParserCompiler::cli($_SERVER['argv']);
Пример #3
0
 static function create_parser($match)
 {
     /* We allow indenting of the whole rule block, but only to the level of the comment start's indent */
     $indent = $match[1];
     /* Get the parser name for this block */
     if ($class = trim($match[2])) {
         self::$currentClass = $class;
     } elseif (self::$currentClass) {
         $class = self::$currentClass;
     } else {
         $class = self::$currentClass = 'Anonymous Parser';
     }
     /* Check for pragmas */
     if (strpos($class, '!') === 0) {
         switch ($class) {
             case '!silent':
                 // NOP - dont output
                 return '';
             case '!insert_autogen_warning':
                 return $indent . implode(PHP_EOL . $indent, array('/*', 'WARNING: This file has been machine generated. Do not edit it, or your changes will be overwritten next time it is compiled.', '*/')) . PHP_EOL;
             case '!debug':
                 self::$debug = true;
                 return '';
         }
         throw new Exception("Unknown pragma {$class} encountered when compiling parser");
     }
     if (!isset(self::$parsers[$class])) {
         self::$parsers[$class] = new RuleSet();
     }
     return self::$parsers[$class]->compile($indent, $match[3]);
 }