EmranMR / tree-sitter-blade

tree-sitter grammar for Laravel blade files
MIT License
186 stars 8 forks source link

Classic raw rule bug #12

Closed EmranMR closed 1 year ago

EmranMR commented 1 year ago

There is bug that the parser does not pick up $._classic_raw

<?php

echo 'test'

?>
calebdw commented 1 year ago

I don't think this parser should worry about raw PHP tags...anything that uses raw php can be updated to use what blade uses:

@php(...)

// or

@php
...
@endphp
EmranMR commented 1 year ago

I don't think this parser should worry about raw PHP tags...anything that uses raw php can be updated to use what blade uses:

@php(...)

// or

@php
...
@endphp

@CalebDW I do agree with you , but considering that technically it is possible to still write php inside <?php ?> in the .blade.php, I thought to just add the support anyways to cover all the bases.

As much as I hope no one ever need to use this feature, you never know what people get up to out there 😂 🤷‍♂️

calebdw commented 1 year ago

I see your point, but at the same time 1) I think it's going to add unnecessary complexity and 2) this a Blade parser and the Blade templating engine does not do anything with raw php.

Once you open that can of worms then you would also need to support echo tags (<?= ?>), and short tags (<? ?>)

The best thing would probably be to update the html node to just be text (like the php parser) and then update the injection to inject php instead of html, the php parser will take care of parsing the tags and html:

((html) @injection.content
    (#set! injection.combined)
    (#set! injection.language html))

; would be

((text) @injection.content
    (#set! injection.combined)
    (#set! injection.language php))

It's up to you, but I would not support it myself...

EmranMR commented 1 year ago

I see your point, but at the same time 1) I think it's going to add unnecessary complexity and 2) this a Blade parser and the Blade templating engine does not do anything with raw php.

Once you open that can of worms then you would also need to support echo tags (<?= ?>), and short tags (<? ?>)

The best thing would probably be to update the html node to just be text (like the php parser) and then update the injection to inject php instead of html, the php parser will take care of parsing the tags and html:

((html) @injection.content
    (#set! injection.combined)
    (#set! injection.language html))

; would be

((text) @injection.content
    (#set! injection.combined)
    (#set! injection.language php))

It's up to you, but I would not support it myself...

@CalebDW That is actually a superb idea!! 🙏
Never thought about it this way, I am still stuck confused with the idea of html vs php injection!

The beauty is we can even go ahead and just do this, while waiting for the split parser.

EmranMR commented 1 year ago

merging to #16