PhpPeg\ParserCompiler::create_parser PHP Метод

create_parser() статический публичный Метод

static public create_parser ( $match )
    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, ['/*', '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]);
    }