Conversation
This comment has been minimized.
This comment has been minimized.
|
I just want to thank you @cfroystad and @maxbrunsfeld for doing all the work here. I have no idea how all this parsing stuff works, but you make my day job A LOT easier ❤️ |
This comment has been minimized.
This comment has been minimized.
|
I see you took option two, very nice! One trip-up I should have mentioned when branching off values in the |
|
Thanks for yet another helpful insight! Since the main grammar is in the internal parser, I suppose it's correct to do as you've done in your code: Hand control back from the external scanner and rather have the main parser call it again if it should find it useful. |
|
One idea I had was to add a token |
|
Okay I just tested it and it works, see here: https://github.com/tlaplus-community/tree-sitter-tlaplus/blob/11c65d44e60a4086556b4819037499399b903a8d/src/scanner.cc#L1619 You need to make the change on your grammar's side too, like here: https://github.com/tlaplus-community/tree-sitter-tlaplus/blob/4c05e1c54e1e26624b5f9cccc840159ab8bb924b/grammar.js#L84 |
|
Brilliant! That made the detection less brittle to future changes! Thanks 🙂 |
src/scanner.cc
Outdated
| } | ||
| } | ||
|
|
||
| bool is_escapable_sequence(TSLexer *lexer) { |
There was a problem hiding this comment.
Should this be marked as static/private?
|
|
Also, braces can be escaped with a backslash. The following is valid in PHP but gives an error with tree-sitter in this branch:
Edit: maybe it's not true that braces can be escaped. If you run |
|
Thank you for testing and identifying some of the things I've missed. I'll look into fixing them when I get home from work. Most of them look like they'll be easy to fix (although slightly embarrassing 😄) |
|
All review comments have been addressed in the last commit. Thank you both for identifying bugs and suggesting good improvements. With regard to escaping |
|
Nice work. It seems I was mistaken about dynamic variable names. I also found some more edge cases that fail to parse:
|
|
Nice work. It seems I was mistaken about dynamic variable names. I also found some more edge cases that fail to parse:
|
|
Thanks for testing! I've fixed the two first items, but might need some guidance on the last one. With the current implementation, I'd need to have two candidate mark_end (which as far as I understand is not supported): This might all be a consequence of me doing too much in the external scanner due to not having found a way to solve them in the main parser. Any pointers/ideas on how to handle this would be greatly appreciated! (one option is of course to wait until Hack is done ironing out the same bugs, and try to adopt their approach) |
|
I guess the lexer needs to scan both However, this is really an exceptional edge case, so it would also be fine to merge this PR and leave it for now, in my opinion. |
|
Thank you, @Sjord! That was the pointer I needed (in combination with driving along the coast of Norway, having loads of time while on ferries). The last edge case is no fixed - even though slightly hackish. The edge case |
|
There's a conflict. You probably need to merge master in your branch (or rebase). |
|
Thanks! I forgot to update the branch after merging another PR earlier. However, the conflict is only in the generated parser and should thus not be a blocker for final review (my merging powers for tree-sitter-php doesn't include changes as complex and wide-reaching as this) I'll try to find a few minutes to rebase when I get home from work in a few hours 🙂 |
…the documentation
…er and adds relevant documentation to the escape_sequence rule
|
Rebased |
See #34
After some blood, sweat and tears, I proudly present interpolated strings for PHP!
If the code can be improved in any way or there is an edge case I've missed, please educate me!
Big thanks to @ahelwer for helping me get unstuck on this issue!
Added nodes:
Examples:
"This is {$great}";
"This works: {$arr['key']}";
"Hello $people, you're awesome!";
"$people->john drank some $juices[0] juice.".PHP_EOL;
Checklist: