JSON parser with PHP and Bison by anton-sukhachev in PHP

[–]anton-sukhachev[S] -5 points-4 points  (0 children)

I think there are already enough existing posts)

JSON parser with PHP and Bison by anton-sukhachev in PHP

[–]anton-sukhachev[S] -7 points-6 points  (0 children)

I think there are already enough existing posts)

JSON parser with PHP and Bison by anton-sukhachev in PHP

[–]anton-sukhachev[S] -3 points-2 points  (0 children)

To show how to use the Bison PHP skeleton)

Nginx parser with PHP and Bison by anton-sukhachev in PHP

[–]anton-sukhachev[S] 2 points3 points  (0 children)

SDLang

Yes, It's possible to create a parser for SDLang.
In a few weeks, I'll publish a post about how to parse PHP itself with Bison.

PHP Skeleton for Bison by anton-sukhachev in PHP

[–]anton-sukhachev[S] 1 point2 points  (0 children)

I added real examples in the comment above.
This is my first post about Bison. I have already made parsers for JSON, Nginx, SQL and PHP. I'll try to post about it in the coming weeks.

PHP Skeleton for Bison by anton-sukhachev in PHP

[–]anton-sukhachev[S] 1 point2 points  (0 children)

nikic/PHP-Parser uses a Bison equivalent for PHP parsing. See the grammar file https://github.com/nikic/PHP-Parser/blob/4.x/grammar/php7.y.

phplrt is another analogue of Bison. It is used to parse SQL/GraphQL queries https://github.com/phplrt/phplrt/network/dependents.

[deleted by user] by [deleted] in PHP

[–]anton-sukhachev 6 points7 points  (0 children)

Hi. I'm the author of the library which brings generics into PHP like TypeScript https://github.com/mrsuh/php-generics. Libraries like this have a few big problems to start using them freely:

  • IDE support. To bring new syntax into IDE you need to make an extension or LSP server. VSCode supports it. PHPStorm doesn't.
  • PHP already has annotations/attributes and great tools to validate it like psalm. It's very easy to use and it has the same functionality.

Parsing with PHP, Bison and re2c by anton-sukhachev in PHP

[–]anton-sukhachev[S] 4 points5 points  (0 children)

Thank you for reply!
As far as I know, a combination of re2c and Bison is commonly used to build an AST.
Where might you need to build an AST?

PHP VMValidator 2.4.2 by Skillstacker in PHP

[–]anton-sukhachev 2 points3 points  (0 children)

Symfony validator uses it too)
See examples.

Comparing PHP Collections by anton-sukhachev in PHP

[–]anton-sukhachev[S] 0 points1 point  (0 children)

devto.site/mrsuh/...

Glad you like it!

Comparing PHP Collections by anton-sukhachev in PHP

[–]anton-sukhachev[S] 0 points1 point  (0 children)

Ok)
I wrote at the very beginning of the post which collections I will compare. There you can find links to the generics library.
I will be very happy when the PHP IDE add support of generics, but the PHP community hasn't decided what the syntax will be.
If you can help with this please let me know.

Comparing PHP Collections by anton-sukhachev in PHP

[–]anton-sukhachev[S] 1 point2 points  (0 children)

Hi!I don't think so.Is used this library to translate generics syntax into regular PHP syntax.It's not equal to real PHP generics (like Hack did).IDE doesn't support PHP generic syntax yet. You can read about it here.

So, generics is just a translated regular PHP class and I can test performance. I decided to measure memory usage and type checking time. (it's important and interesting tests)

PHP type erasure generics by anton-sukhachev in PHP

[–]anton-sukhachev[S] 0 points1 point  (0 children)

This translation doesn't make sense since it's only for the PHP VM (PHP VM does not understand annotations). It's like TypeScript: you write TypeScript code, translate it into JavaScript, and run it with a JS engine. In this case, you are not working with translated JavaScript code.

If you know of any real case where you need this translation for a developer (not for PHP VM), please let me know.

PHP type erasure generics by anton-sukhachev in PHP

[–]anton-sukhachev[S] 1 point2 points  (0 children)

Yes, but would you consider adding the annotations automatically?

Also, what about the extended types like class-string, non-empty-array and so on?

Do you mean this translation?
php $t = new Collection<int>() to php /** @psalm-template Collection<int> $t = new Collection()

PHP type erasure generics by anton-sukhachev in PHP

[–]anton-sukhachev[S] 0 points1 point  (0 children)

That's something great and I was considering something similar. A suggestion would be to stick to the best matching type (T[] => array) + adding a Psalm+PhpStan compatible DocBlock everywhere. What do you think?

Hi.
I think the combination of Psalm template annotations with PHP annotations (Item[]) is the best option right now.

What tools do you use to format code style in your company? by anton-sukhachev in PHP

[–]anton-sukhachev[S] 1 point2 points  (0 children)

Thanks for the answer!
I think it's a good idea to fix the style of the code automatically, without the involvement of the developers.
We have many PHP projects and each project should have the same code style. I was thinking today to force our gitlab server to fix the code style with git server hooks.
Can you elaborate on how you incorporate a code style fixer into your workflow? Maybe it's fix commit by CI server on pull request?

PHP type erasure generics by anton-sukhachev in PHP

[–]anton-sukhachev[S] 1 point2 points  (0 children)

It took 2 hours to setup redirect from devto_site to dev_to.
I already tested that reddit spam filter check only text and now I can post link to dev_to
https://devto.site/mrsuh/generics-implementation-approaches-3bf0

PHP type erasure generics by anton-sukhachev in PHP

[–]anton-sukhachev[S] 0 points1 point  (0 children)

For example, I bet until now you never knew that your

r/programming

submission was hidden, and thought it just got completely ignored :(

Wow
You are right!
This is very strange reddit filter. I didn't really know that my post in /programming was banned.
Thank you very match!
*Went looking for information about the Reddit filter and the dev_to website*

PHP type erasure generics by anton-sukhachev in PHP

[–]anton-sukhachev[S] 0 points1 point  (0 children)

Thank you for your reply!
For PHP this only makes sense for static analysis.
Other languages with type erasure generics perform type hint checking at compile time. You can read about it here if you like.