Skip to content
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

Support for PHP 7 #2908

Closed
plugowski opened this issue Feb 23, 2016 · 12 comments
Closed

Support for PHP 7 #2908

plugowski opened this issue Feb 23, 2016 · 12 comments

Comments

@plugowski
Copy link

Hi,

Editor didn't understand php 7 constructs and mark it as incorrect;

<?php declare(strict_types=1);

show message: Syntax error, unexpected '=', expecting ')'

function foobar(): int {}

show message: Syntax error, unexpected ':', expecting '{'

function test(int ...$i) {
    return $i;
}

show message: show message: Syntax error, unexpected ':', expecting T_VARIABLE

$username = $_GET['user'] ?? 'nobody';

show message: show message: Syntax error, unexpected '?'

echo 1 <=> 2;

show message: show message: Syntax error, unexpected '>'

$app->setLogger(new class implements Logger {
    public function log(string $msg) {
        echo $msg;
    }
});

show message: show message: Syntax error, unexpected T_CLASS, expecting ')'

http://php.net/manual/en/migration70.new-features.php

@SjonHortensius
Copy link
Contributor

I've been staring really hard at https://github.com/ajaxorg/ace/blob/36e6744a5f40df0da52ff22b3bc729657c056e09/lib/ace/mode/php/php.js, but I cannot figure out how to add support for various php7 features.
Should this be done manually, or is it possible to recreate this file using the current php parser?

@nightwing
Copy link
Member

that file was taken from https://github.com/niklasvh/php.js, which seems to not be maintained anymore.
we need to find some other php parser in js or maybe use http://lakhin.com/projects/papa-carlo/

@adamjimenez
Copy link
Contributor

PHP.js hasn't been actively maintained. It was created as a proof-of-concept. But the maintainer does merge pull requests for those looking to contribute.

@SjonHortensius
Copy link
Contributor

I also noticed niklasvh/php.js#69, but ACE only needs the parser; not the actual implementation. It seems the parser is 'simply' a converted yacc parser, but I cannot find the instructions to redo this with a the new parser from php7

@plugowski
Copy link
Author

I tried to find other JavaScript parser for PHP, but with no results...

@adamjimenez
Copy link
Contributor

Uses kmyacc

trim(shell_exec('kmyacc -l -m kmyacc.js.parser ' . TMP_FILE . ' 2>&1')),

From:
https://github.com/niklasvh/php.js/blob/master/grammar/rebuildParser.php#L40

@plugowski
Copy link
Author

I installed kmyacc on my mac, but when I try to run rebuildParser.php I got some Exception, because zend_language_parser.y - https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y - has got different structure than previous one so script throws Exception: Unknown macro "sizeof" :/

@adamjimenez
Copy link
Contributor

presumably we need another if statement in resolveMacros:
https://github.com/niklasvh/php.js/blob/master/grammar/rebuildParser.php#L82

@nikic
Copy link
Contributor

nikic commented Oct 1, 2016

The php.js parser is based on https://github.com/nikic/PHP-Parser. To make it work with PHP 7 one would have to update it to use (a modified version of) the grammar definition at https://github.com/nikic/PHP-Parser/blob/master/grammar/php7.y. As the grammar in php.js contains changes and the PHP-Parser has diverged quite a bit in the last 4 years, this will probably not be a simple update.

@nikic
Copy link
Contributor

nikic commented Oct 1, 2016

From a quick look it seems like ace does not actually need any of the AST construction logic -- it uses the parser only for syntax checking. If all the semantic actions from the grammar are simply discarded, generating a new parser would probably be much simpler.

@nikic
Copy link
Contributor

nikic commented Oct 1, 2016

PR up at #3107.

@SjonHortensius
Copy link
Contributor

@nikic awesome work; I've used your branch to create a new worker & mode which I've deployed on https://3v4l.org and it works great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants