Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update leaf syntax to leaf 4 #3794

Merged
merged 8 commits into from
Jul 25, 2023
Merged

Update leaf syntax to leaf 4 #3794

merged 8 commits into from
Jul 25, 2023

Conversation

dannflor
Copy link
Contributor

@dannflor dannflor commented May 26, 2023

Changes

Overhauled the leaf syntax to match the new leaf 4 grammar
https://docs.vapor.codes/leaf/overview

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

src/languages/leaf.js Outdated Show resolved Hide resolved
src/languages/leaf.js Outdated Show resolved Hide resolved
src/languages/leaf.js Outdated Show resolved Hide resolved
@joshgoebel
Copy link
Member

Thanks, but it looks like this whole grammar is super old and using very old conventions - we have nicer ways to do a lot of this now. I'll try to pull this down and make a pass at cleaning it up then toss it back.

Is there a list of official helpers/keywords in Leaf (loop, for, etc)? If so we should build them in so they can be highlighted as built-in perhaps...

@dannflor
Copy link
Contributor Author

https://docs.vapor.codes/leaf/overview is basically all you have to work off of. Anyone can define any tag though, so it doesn't really make sense to distinguish between built-in and user defined. The only built in tag that has any different syntax from an arbitrarily user defined one is for requiring an in in the parameter body. But you could also mark every one of the tags that is on that page as built-in.

@joshgoebel
Copy link
Member

joshgoebel commented May 26, 2023

Screen Shot 2023-05-25 at 10 00 55 PM

Pretty sure if/else/etc should all match though... ie, they are a single scope... I think likely we just want to say they are all keywords?

@dannflor
Copy link
Contributor Author

Sounds good to me. We've been living without syntax highlighting on those specific keywords for a couple of years now so I don't know if there are any strong opinions lol

@dannflor
Copy link
Contributor Author

I updated the expected markup to match what we want to generate. There's only one thing missing, which is tag functions can nest inside each other (nested functions omit the # at the beginning). I believe they can nest to an arbitrary depth, but I know regular expressions can't do that (though maybe you have some way around that). I'm not sure how to implement that in your current system for defining the grammar

@joshgoebel
Copy link
Member

which is tag functions can nest inside each other (nested functions omit the # at the beginning)

Give me a few actual examples please.

@dannflor
Copy link
Contributor Author

dannflor commented May 27, 2023

Sorry, I put it in the markup test. It's basically something like:
#if(count(arbitaryFunction(variable)) == 0):

@joshgoebel
Copy link
Member

Regex doesn't support infinite nesting, but the parser does... for something like one rule immediately inside another we have a shortcut "self"... for less-direct looping you have to create the objects separate then link them together as the grammar is executed. IE:

  • a
    • b
      • c

Where a contains b which contains c, etc... but there is nothing to stop C from containing A... and it can go as deep as necessary....

@dannflor
Copy link
Contributor Author

Hey, it works! LGTM

@dannflor
Copy link
Contributor Author

dannflor commented Jul 21, 2023

@joshgoebel Is there something remaining to be done here holding up merging?

@joshgoebel
Copy link
Member

Yeah, just need to update the changelog :)

@dannflor
Copy link
Contributor Author

Done

@joshgoebel joshgoebel merged commit 7fb52a2 into highlightjs:main Jul 25, 2023
15 checks passed
@joshgoebel
Copy link
Member

Thanks!

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.

None yet

2 participants