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

Inline comment before semicolon not in AST #802

Open
pableu opened this issue Aug 10, 2021 · 0 comments
Open

Inline comment before semicolon not in AST #802

pableu opened this issue Aug 10, 2021 · 0 comments

Comments

@pableu
Copy link

pableu commented Aug 10, 2021

Steps to reproduce:

Create a simple PHP file like this:

<?php
echo 'foo' /* bar */ ;

The comment between the end of the function and the ; is crucial. It's also reproducible with code like $x = str_contains('abcde', 'a') /* test */; or $x = 7 /* seven */;.

Parse it:

$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$ast = $parser->parse(file_get_contents('sample.php');
print_r($ast);

Actual Result

array(1) {
  [0]=>
  object(PhpParser\Node\Stmt\Echo_)#9202 (2) {
    ["exprs"]=>
    array(1) {
      [0]=>
      object(PhpParser\Node\Scalar\String_)#9206 (2) {
        ["value"]=>
        string(3) "foo"
        ["attributes":protected]=>
        array(3) {
          ["startLine"]=>
          int(2)
          ["endLine"]=>
          int(2)
          ["kind"]=>
          int(1)
        }
      }
    }
    ["attributes":protected]=>
    array(2) {
      ["startLine"]=>
      int(2)
      ["endLine"]=>
      int(2)
    }
  }
}

Expected Result

I'd like to see to "bar" comment to show up somewhere in the AST. As an attribute of the Stmt\Echo_ most likely.

Use Case

We use this in our internal translation system to annotate calls to our translation engine.

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

1 participant