Beispiel #1
0
 public function build(OutputInterface &$output)
 {
     $style = new OutputFormatterStyle('red', null, array('bold', 'blink'));
     $output->getFormatter()->setStyle('fire', $style);
     // Disable output.
     ini_set('implicit_flush', false);
     // Lemon takes arguments on the command line.
     $_SERVER['argv'] = $argv = array('-s', ROOT . $this->source);
     $output->writeln("<fg=green>Attempting to build \"{$this->target}\" from \"{$this->source}\"</fg=green>");
     $output->writeln("This could take a few minutes...");
     // The -q flag doesn't seem to work but we can catch the output in a
     // buffer (only want to display the errors).
     ob_start();
     $lemon = new \PHP_ParserGenerator();
     $lemon->main();
     $reply = explode("\n", ob_get_contents());
     ob_end_clean();
     $errors = array();
     $conflicts = 0;
     foreach ($reply as $i => $line) {
         // Errors are prefixed with the grammar file path.
         if (strpos($line, $argv[1]) === 0) {
             $errors[] = str_replace($argv[1], basename($argv[1]), $line);
         }
         if ($i === count($reply) - 2) {
             if (preg_match('/^(\\d+).+/', $line, $m)) {
                 $conflicts = intval($m[1]);
             }
         }
     }
     if ($errors) {
         $output->writeln("<fire>" . implode("\n", $errors) . "</fire>");
     }
     // Build was a success!
     if (!file_exists(ROOT . $this->target) || @unlink(ROOT . $this->target)) {
         $content = file_get_contents(ROOT . 'parser.php');
         // Add namespace declaration.
         $content = strtr($content, array('<?php' => "<?php\n\n" . "namespace Rodchyn\\ElephantLang\\Parser;\n\n" . "use \\ArrayAccess as ArrayAccess;\n\n" . "use Rodchyn\\ElephantLang\\Init as Init;\n\n" . "Init::init();\n\n" . ""));
         // Write.
         file_put_contents(ROOT . $this->target, $content);
         $output->writeln("Parser builded!");
         // Clean up.
         unlink(ROOT . 'parser.php');
         if ($conflicts) {
             $output->writeln("but <fire>{$conflicts} parsing conflicts occurred (see {$this->source}.out).</fire>");
         } else {
             unlink(ROOT . 'parser.out');
         }
         return 0;
     } else {
         // Bad permissions.
         $output->writeln("<fire>Failed!</fire>");
         $output->writeln("<fire>Couldn't remove {$this->target}. Check your permissions.</fire>");
         return 1;
     }
 }
Beispiel #2
0
function make()
{
    require 'vendor/ParserGenerator/ParserGenerator.php';
    $source = 'grammar';
    $target = 'src/CoffeeScript/Parser.php';
    // Lemon takes arguments on the command line.
    $_SERVER['argv'] = $argv = array('-s', ROOT . $source . '.y');
    echo "Attempting to build \"{$target}\" from \"{$source}.y\".\n";
    echo "This could take a few minutes...\n";
    // The -q flag doesn't seem to work but we can catch the output in a
    // buffer (only want to display the errors).
    ob_start();
    $lemon = new PHP_ParserGenerator();
    $lemon->main();
    $reply = explode("\n", ob_get_contents());
    ob_end_clean();
    $errors = array();
    $conflicts = 0;
    foreach ($reply as $i => $line) {
        // Errors are prefixed with the grammar file path.
        if (strpos($line, $argv[1]) === 0) {
            $errors[] = str_replace($argv[1], basename($argv[1]), $line);
        }
        if ($i === count($reply) - 2) {
            if (preg_match('/^(\\d+).+/', $line, $m)) {
                $conflicts = intval($m[1]);
            }
        }
    }
    if ($errors) {
        exit(implode("\n", $errors));
    }
    // Build was a success!
    if (!file_exists(ROOT . $target) || @unlink(ROOT . $target)) {
        $content = file_get_contents(ROOT . $source . '.php');
        // Add namespace declaration.
        $content = strtr($content, array('<?php' => "<?php\n" . "namespace CoffeeScript;\n" . "use \\ArrayAccess as ArrayAccess;\n" . "Init::init();\n"));
        // Write.
        file_put_contents(ROOT . $target, $content);
        echo "Success!\n";
        // Clean up.
        unlink(ROOT . $source . '.php');
        if ($conflicts) {
            echo "{$conflicts} parsing conflicts occurred (see {$source}.out).\n";
        } else {
            unlink(ROOT . $source . '.out');
        }
        exit(0);
    } else {
        // Bad permissions.
        echo "Failed!\n";
        echo "Couldn't remove {$target}. Check your permissions.\n";
        exit(1);
    }
}
Beispiel #3
0
<?php

require_once 'PHP/ParserGenerator.php';
$me = new PHP_ParserGenerator();
$me->main();
<?php

ini_set('max_execution_time', 300);
ini_set('xdebug.max_nesting_level', 300);
// Create Lexer
require_once './LexerGenerator.php';
$lex = new PHP_LexerGenerator('Lexer.plex');
$contents = file_get_contents('Lexer.php');
$contents = str_replace(array('SMARTYldel', 'SMARTYrdel'), array('".$this->ldel."', '".$this->rdel."'), $contents);
file_put_contents('Lexer.php', $contents);
// Create Parser
require_once './ParserGenerator.php';
$me = new PHP_ParserGenerator();
$me->main('Parser.y');
$contents = file_get_contents('Parser.php');
$contents = '<?php
/**
 * Brainy Internal Plugin Templateparser
 *
 * This is the template parser.
 * It is generated from the Parser.y file
 * @package Brainy
 * @subpackage Compiler
 * @author Uwe Tews
 * @author Matt Basta
 */

namespace Box\\Brainy\\Compiler;

' . substr($contents, 6);
file_put_contents('Parser.php', $contents);
Beispiel #5
0
<?php

if ($argc != 2) {
    exit("Usage: php " . $argv[0] . " <file>\n");
}
require_once 'PHP/ParserGenerator.php';
$a = new PHP_ParserGenerator();
$_SERVER['argv'] = array('lemon', '-s', $argv[1]);
$a->main();
<?php

ini_set('max_execution_time', 300);
ini_set('xdebug.max_nesting_level', 300);
$smartyPath = '../smarty/libs/sysplugins/';
$lexerPath = '../smarty/lexer/';
if (!is_dir($lexerPath)) {
    echo '<br><br>Fatal error: Missing lexer / parser definition folder \'lexer\' in distribution <br>';
    exit(1);
}
copy("{$smartyPath}smarty_internal_templatelexer.php", "{$lexerPath}smarty_internal_templatelexer.php.bak");
copy("{$smartyPath}smarty_internal_templateparser.php", "{$lexerPath}smarty_internal_templateparser.php.bak");
// Create Lexer
require_once './LexerGenerator.php';
$lex = new PHP_LexerGenerator("{$lexerPath}smarty_internal_templatelexer.plex");
unset($lex);
$content = file_get_contents("{$lexerPath}smarty_internal_templatelexer.php");
$content = str_replace(array('SMARTYldel', 'SMARTYrdel'), array('".$this->ldel."', '".$this->rdel."'), $content);
file_put_contents("{$lexerPath}smarty_internal_templatelexer.php", $content);
// Create Parser
require_once './ParserGenerator.php';
$parser = new PHP_ParserGenerator();
$parser->main("{$lexerPath}smarty_internal_templateparser.y");
unset($parser);
$content = file_get_contents("{$lexerPath}smarty_internal_templateparser.php");
$content = preg_replace(array('#/\\*\\s*\\d+\\s*\\*/#', "#'lhs'#", "#'rhs'#"), array('', 0, 1), $content);
file_put_contents("{$lexerPath}smarty_internal_templateparser.php", $content);
copy("{$lexerPath}smarty_internal_templatelexer.php", "{$smartyPath}smarty_internal_templatelexer.php");
copy("{$lexerPath}smarty_internal_templateparser.php", "{$smartyPath}smarty_internal_templateparser.php");
<?php

$smartyPath = '../smarty/libs/sysplugins/';
$lexerPath = '../smarty/lexer/';
if (!is_dir($lexerPath)) {
    echo '<br><br>Fatal error: Missing lexer / parser definition folder \'lexer\' in distribution <br>';
    exit(1);
}
copy("{$smartyPath}smarty_internal_configfilelexer.php", "{$lexerPath}smarty_internal_configfilelexer.php.bak");
copy("{$smartyPath}smarty_internal_configfileparser.php", "{$lexerPath}smarty_internal_configfileparser.php.bak");
// Create Lexer
require_once './LexerGenerator.php';
$lex = new PHP_LexerGenerator("{$lexerPath}smarty_internal_configfilelexer.plex");
unset($lex);
// Create Parser
require_once './ParserGenerator.php';
$parser = new PHP_ParserGenerator();
$parser->main("{$lexerPath}smarty_internal_configfileparser.y");
unset($parser);
$content = file_get_contents("{$lexerPath}smarty_internal_configfileparser.php");
$content = preg_replace(array('#/\\*\\s*\\d+\\s*\\*/#', "#'lhs'#", "#'rhs'#"), array('', 0, 1), $content);
file_put_contents("{$lexerPath}smarty_internal_configfileparser.php", $content);
copy("{$lexerPath}smarty_internal_configfilelexer.php", "{$smartyPath}smarty_internal_configfilelexer.php");
copy("{$lexerPath}smarty_internal_configfileparser.php", "{$smartyPath}smarty_internal_configfileparser.php");