phpdoc-parser icon indicating copy to clipboard operation
phpdoc-parser copied to clipboard

Add README

Open jasny opened this issue 5 years ago • 9 comments

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

jasny avatar Sep 09 '18 18:09 jasny

Check out PHPStan’s codebase, namely the PHPStan\PhpDoc namespace.

On Sun, 9 Sep 2018 at 20:52, Arnold Daniels [email protected] wrote:

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

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/phpstan/phpdoc-parser/issues/19, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuHnhoXLJeuEeeHo-mwN2OjP9efSYks5uZWNPgaJpZM4WgZmY .

--

Ondřej Mirtes

ondrejmirtes avatar Sep 09 '18 20:09 ondrejmirtes

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.

jasny avatar Sep 10 '18 08:09 jasny

What exactly do you need it to parse and what output do you expect? Show a few examples.

On Mon, 10 Sep 2018 at 10:39, Arnold Daniels [email protected] wrote:

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.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/phpstan/phpdoc-parser/issues/19#issuecomment-419833822, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuEPcFEv56fT3OD_Nt0-5yOnd_T-Gks5uZiVVgaJpZM4WgZmY .

--

Ondřej Mirtes

ondrejmirtes avatar Sep 10 '18 09:09 ondrejmirtes

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")"
      }
    }
  }
}

JanTvrdik avatar Sep 10 '18 11:09 JanTvrdik

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.

jasny avatar Sep 15 '18 20:09 jasny

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

VincentLanglet avatar Dec 31 '19 15:12 VincentLanglet

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

JanTvrdik avatar Dec 31 '19 19:12 JanTvrdik

@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.

VincentLanglet avatar Jan 01 '20 01:01 VincentLanglet

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

icanhazstring avatar May 04 '20 11:05 icanhazstring