-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for PHP 7 #3107
Add support for PHP 7 #3107
Conversation
Drop contents of semantics actions. ACE does not use the generated AST and updating this would be too much work.
I noticed a discrepancy on https://3v4l.org/mo9V4 where PHP accepts a syntax and the worker doesn't: $obj = (Factory::Generate('MyObj'))($someData); throws Syntax error, unexpected ??? Same thing happens on https://3v4l.org/WThln var_dump( DateTimeZone::listIdentifiers()); throws Syntax error, unexpected ???, expecting ',' or ')' |
I found some other code it doesn't like:
|
Drop special handling of T_DOUBLE_COLON, always use T_PAAMAYIM_NEKUDOTAYIM instead.
@SjonHortensius Thanks for testing! Handling of The issue was that the lexer used the |
Thanks; that fixes all three indeed 👍 |
Thanks, this is working great so far. |
Seeing as you're on a roll, here's something else that throws an error when it shouldn't:
Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING These are also still bust: |
var_dump(`ls`); throws Syntax error, unexpected $EOF. Maybe these should be reported as separate issues btw; it is not caused by this PR. This PR fixes 99% of all php7 issues that were in the previous syntax-checker. |
I started working on a lexer update that should fix these issues, but it will take a while. I'll send a separate PR. |
Drop semantic actions entirely instead of just emptying them.
Forgot to link, new lexer is at https://gist.github.com/nikic/91ee0bc7ac74659366a8ae90b8f2d15e. |
Not sure if (or why not) you committed this on a branch somewhere but I manually inserted your lexer in the existing php.js and it seems to work fine. It does fix indeed all mentioned issues 👍 |
@nikic I think you should include the Lexer changes in this PR as well. Also; I guess you'll need to sign the CLA here and then this should be ready to be pulled and included in a release Can you confirm @nightwing ? |
Pulled in the lexer updates, this fixes the issues above as well as #2232, #2285. The lexer is modeled after PHP's own lexer and tested against token_get_all() for a wide range of inputs -- some unimportant distinctions (LNUMBER/DNUMBER, COMMENT/DOC_COMMENT) and certain error behavior notwithstanding. |
Any news here? |
Will be nice if that pull request will be merged into ajaxorg/ace :) |
Thanks for awesome work! Merging. |
this repeats ajaxorg#3107, but for 7.4, instead of the kmyacc binary I used https://github.com/ircmaxell/PHP-Yacc
this repeats ajaxorg#3107, but for 7.4, instead of the kmyacc binary I used https://github.com/ircmaxell/PHP-Yacc
this repeats ajaxorg#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"; ```
this repeats ajaxorg#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"; ```
Update the parser tables for PHP 7, add lexer support for new tokens. This includes support for PHP 7.1.
I have removed the AST node definitions and emptied the semantic actions of the parser. ACE does not use the AST and porting the semantic actions to JS would be way too much work.
For future reference, this is the
rebuildParser.php
I used:The skeleton file is https://github.com/niklasvh/php.js/blob/master/grammar/kmyacc.js.parser. The grammar and token files are from https://github.com/nikic/PHP-Parser/tree/master/grammar.