EmranMR / tree-sitter-blade

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

Enhancement: Custom_if statement matching for parser #9

Closed EmranMR closed 1 year ago

EmranMR commented 1 year ago

I am not sure if this is possible using external scanners but it would be nice to be able to match the start_directive and end_directive dynamically. This could even help with #8

This would allow parser to give errors if the directives dont match such:

@test
    code
@endtest
@example
    code
@endexample

currently the regex will match the whatever that follows the @end[a-z] which is not very explicit but it works.

You could possibly maybe improve this so that your editor signals you that there is a matching error using the predicates when highlighting if your editor supports them such as #match?. Basically only highlight when the capture from directive_start matches the directive_end regex

calebdw commented 1 year ago

Forcing start and end directives to match will not work for everything:

https://laravel.com/docs/9.x/blade#section-directives

EmranMR commented 1 year ago

Hi @CalebDW all the built-in ones, including directives such as @section with unusual oddities are hardcoded. They also get higher lexical precedence for that same reason when the engine parses the blade.

Now as far as I am aware looking at the docs, the Custom If Statements follow the @start and @endstart convention? 🤔

Can the Laravel devs do stuff like the @hasSection; writing their own unconventional @endtag?? If so could you please drop in an example or a link to the docs/implementation?

All and all, I might close this issue in the future as unresolved. I am not sure if it is worth the hassle? I will see if any bugs or issues arises from people who use the custom directive in the coming months/year. 😊 So far it seem to have been ok as it is? 🤞, again I am not sure how many users are using this repo? so we shall see!

calebdw commented 1 year ago

@EmranMR, yes you're right, the custom if statements have their own @end* tag. As long as the non-standard blade tags are supported then this issue can probably be closed.