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

Add README #19

Open
jasny opened this issue Sep 9, 2018 · 9 comments
Open

Add README #19

jasny opened this issue Sep 9, 2018 · 9 comments

Comments

@jasny
Copy link

jasny commented Sep 9, 2018

Please add a README.md showing how the parser can be used.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Sep 9, 2018 via email

@jasny
Copy link
Author

jasny commented Sep 10, 2018

I'm more interested in how to use the parser outside of PHPStan. To be precise; Can it be used to collect metadata as an alternative to Doctrine\Annotations?

I have a hard time deducing that from the code. It only seems to be concerned with variable types at first glance.

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Sep 10, 2018 via email

@JanTvrdik
Copy link
Collaborator

Can it be used to collect metadata as an alternative to Doctrine\Annotations?

@jasny Probably not. Depends on what metadata do you have in mind. Currently it for example does not allow backslash in annotation name.

Even if we allow backslash in annotation name, it will not understand doctrine value syntax, i.e. the following code

$input = '/**
 * @ORM\Table(name="product")
 */';


$lexer = new Lexer();
$typeParser = new TypeParser();
$constExprParser = new ConstExprParser();
$phpDocParser = new PhpDocParser($typeParser, $constExprParser);

$tokens = $lexer>tokenize($input);
$tokenIterator = new TokenIterator($tokens);
$phpDocNode = $phpDocParser ->parse($tokens);
var_dump($phpDocNode);

will result in

object(PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode)#10 (1) {
  ["children"]=>
  array(1) {
    [0]=>
    object(PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode)#9 (2) {
      ["name"]=>
      string(10) "@ORM\Table"
      ["value"]=>
      object(PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode)#8 (1) {
        ["value"]=>
        string(16) "(name="product")"
      }
    }
  }
}

@jasny
Copy link
Author

jasny commented Sep 15, 2018

I don't use the doctrine style notation, from the looks of it, it may be useful as I'm currently just using regular expressions to extract tags and information.

This example helps a bit. Still, a good README with such examples would help.

@VincentLanglet
Copy link
Contributor

Where can we find all the phpDoc supported syntax ? Wouldn't the README perfect for this ?

Union types, intersections type, @method types, array types (since [] is actually not alway supported), closure types (is there a way to type the param and the return), value type (is there a way to type 'A'|'B', int(0...10), ...)...
A full list would be great

@JanTvrdik
Copy link
Collaborator

@VincentLanglet https://github.com/phpstan/phpdoc-parser/blob/master/doc/grammars/type.abnf may help (but is not fully up to date i think)

@VincentLanglet
Copy link
Contributor

@VincentLanglet https://github.com/phpstan/phpdoc-parser/blob/master/doc/grammars/type.abnf may help (but is not fully up to date i think)

It helps indeed, but the reader need to know the abnf syntax.
I think giving example for Type and Constant would be great.

@icanhazstring
Copy link
Contributor

icanhazstring commented May 4, 2020

README.md added with #43. Should be improved tho :)

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