From eacc5dbe190857ac1f7fa9bc94821f558b35f7ea Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 19 Oct 2019 15:24:38 +0200 Subject: [PATCH] Default to using php-yacc to generate the parsers --- composer.json | 3 ++- grammar/README.md | 10 ++++++---- grammar/rebuildParsers.php | 10 ++-------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index b99182e..df6f2ea 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "ext-tokenizer": "*" }, "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0", + "ircmaxell/php-yacc": "0.0.4" }, "extra": { "branch-alias": { diff --git a/grammar/README.md b/grammar/README.md index 90988cf..4bae11d 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -21,8 +21,10 @@ applied to it: Building the parser =================== -In order to rebuild the parser, you need [moriyoshi's fork of kmyacc](https://github.com/moriyoshi/kmyacc-forked). -After you compiled/installed it, run the `rebuildParsers.php` script. +Run `php grammar/rebuildParsers.php` to rebuild the parsers. Additional options: -By default only the `Parser.php` is built. If you want to additionally emit debug symbols and create `y.output`, run the -script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`. + * The `KMYACC` environment variable can be used to specify an alternative `kmyacc` binary. + By default the `phpyacc` dev dependency will be used. To use the original `kmyacc`, you + need to compile [moriyoshi's fork](https://github.com/moriyoshi/kmyacc-forked). + * The `--debug` option enables emission of debug symbols and creates the `y.output` file. + * The `--keep-tmp-grammar` option preserves the preprocessed grammar file. diff --git a/grammar/rebuildParsers.php b/grammar/rebuildParsers.php index ce155e2..c36699c 100644 --- a/grammar/rebuildParsers.php +++ b/grammar/rebuildParsers.php @@ -15,14 +15,8 @@ $tokensResultsFile = $resultDir . '/Tokens.php'; $kmyacc = getenv('KMYACC'); if (!$kmyacc) { - // Check for kmyacc binary in this directory, otherwise fall back to global name - if (file_exists(__DIR__ . '/kmyacc.exe')) { - $kmyacc = __DIR__ . '/kmyacc.exe'; - } else if (file_exists(__DIR__ . '/kmyacc')) { - $kmyacc = __DIR__ . '/kmyacc'; - } else { - $kmyacc = 'kmyacc'; - } + // Use phpyacc from dev dependencies by default. + $kmyacc = PHP_BINARY . ' ' . __DIR__ . '/../vendor/bin/phpyacc'; } $options = array_flip($argv);