Skip to content

Commit

Permalink
Support PHP 7.4 syntax
Browse files Browse the repository at this point in the history
this repeats #3107, but for 7.4, instead of the kmyacc binary
I used https://github.com/ircmaxell/PHP-Yacc

here is the rebuildParser that I used:

```
<?php

const GRAMMAR_REPO  = 'https://raw.githubusercontent.com/nikic/PHP-Parser';
const PARSER_REPO  = 'https://raw.githubusercontent.com/niklasvh/php.js';

const GRAMMAR_FILE = GRAMMAR_REPO .'/master/grammar/php7.y';
const TOKENS_FILE  = GRAMMAR_REPO .'/master/grammar/tokens.y';
const TMP_FILE     = './tmp_parser.jsy';
const RESULT_FILE  = './tmp_parser.js';

file_put_contents('kmyacc.js.parser', file_get_contents(PARSER_REPO .'/master/grammar/kmyacc.js.parser'));

$tokens = file_get_contents(TOKENS_FILE);
$grammarCode = file_get_contents(GRAMMAR_FILE);
$grammarCode = str_replace('%tokens', $tokens, $grammarCode);

file_put_contents(TMP_FILE, $grammarCode);

echo 'Building parser. Output: "',
     trim(shell_exec('./PHP-Yacc/bin/phpyacc -m kmyacc.js.parser ' . TMP_FILE . ' 2>&1')),
     '"', "\n";

preg_match_all('/T_\w+/', $tokens, $matches);
foreach ($matches[0] as $match)
    echo '"' . $match . '",';

echo "\n". str_repeat('-', 45). "\n";
foreach ($matches[0] as $match)
        if (NULL != constant($match))
            echo 'PHP.Constants.' . $match . ' = ' . constant($match) . "\n";
```
  • Loading branch information
SjonHortensius committed Jun 8, 2020
1 parent cf661f9 commit 5834d8f
Showing 1 changed file with 841 additions and 772 deletions.
Loading

0 comments on commit 5834d8f

Please sign in to comment.