Skip to content

Implement PHP support#520

Draft
Jeckerson wants to merge 18 commits intoskvadrik:masterfrom
Jeckerson:master
Draft

Implement PHP support#520
Jeckerson wants to merge 18 commits intoskvadrik:masterfrom
Jeckerson:master

Conversation

@Jeckerson
Copy link

No description provided.

Copy link
Owner

@skvadrik skvadrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the port!

A minor thing, but can you put all PHP entries sorted alphabetically, between OCaml and Python?

Also, please rebase on top of master.

This is a partial review. I'll do the full review as soon as I can, but I broke my arm a few days ago, and I'm slower than usual.

@Jeckerson
Copy link
Author

@skvadrik I adjusted alphabetically the implementation. There are still work in examples/ and I'll need your help in some already made examples, especially with null ([\x00]) value. As in PHP it must be generated like that: case "\0": and not case 0x00:.

@skvadrik
Copy link
Owner

skvadrik commented Dec 30, 2024

I adjusted alphabetically the implementation.

Thanks!

There are still work in examples/ and I'll need your help in some already made examples, especially with null ([\x00]) value. As in PHP it must be generated like that: case "\0": and not case 0x00:.

I think you should use re2c:yych:literals = hex;, similar to Python that also has no character type (single-quoted literals are strings, as in PHP).

Copy link
Owner

@skvadrik skvadrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments.

single_quoted_strings = 1;
indentation_sensitive = 0;
wrap_blocks_in_braces = 1;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a new configuration special_escapes that needs to go here, see other syntax files.

@@ -0,0 +1,16 @@
<?php
// re2php $INPUT -o $OUTPUT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should always be the first line of the file (as expected by run_tests.py).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impossible, as <?php must be on 1st line.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then I suggest adding some sed magic in examples/php/__run_all.sh that will cut off the comments in the temporary file (this one and the one autogenerated by re2php).

supported_api_styles = ["free-form"];
supported_code_models = ["loop-switch"];
supported_targets = ["code", "dot"];
supported_features = ["nested-ifs", "bitmaps", "tags", "captures", "captvars"];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all supported and unsupported features there must be a test. Tags, captures and captvars are covered by examples, and for the rest see tests in test/codegen/<language>.

"java" end { *lang = Lang::JAVA; goto opt; }
"js" end { *lang = Lang::JS; goto opt; }
"ocaml" end { *lang = Lang::OCAML; goto opt; }
"php" end { *lang = Lang::PHP; goto opt; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to the error message on line 249 as well.

@skvadrik
Copy link
Owner

So I downloaded the patch and tried to build some of the problematic examples, but it seems that the .php files are not generated from the current syntax file (it was copied from javascript without modification). Please let me know when you update it (or if you have any questions).

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

Successfully merging this pull request may close these issues.

2 participants