-
Notifications
You must be signed in to change notification settings - Fork 4
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
[WIP] Embedding Jinja2 into more syntaxes #10
Conversation
* Move HTML embedding out of the main syntax, rendering Jinja.sublime-syntax to be a globally-applicable syntax. * Add YAMLMacros templates to automatically generate an embedding syntax.
A potential issue came to mind: Line statements in host languages that use I should also clarify that the dependency on YAMLMacros is purely on the dev side. AFAIK, clients don't need to have this installed, we should just make sure to build each syntax before pushing new versions. Of course, clients still need to have the host syntax installed, as usual. |
I wasn't expecting PR's this early in this project TBH but whatever :) As this is a significant PR, I'll need time to go through it. Hopefully, you don't mind :) A suggestion for naming convention for the generated syntax can be
I really doubt if we need line statements at all (I am not sure how many Anyways thanks for you work on this. It is really appreciated. |
Of course 👍 It is a WIP after all.
It pretty much exposes YAML macros and offers a build system to evaluate them, focusing heavily on Sublime syntax definitions. The main idea is to create YAML files containing macros (prefixed by The main idea of the YAML macros in this PR is that we create a base template for any syntax with embedded Jinja, and create another per-syntax YAML file with the appropriate macros to transform the base template into a usable syntax. Then we build the per-syntax I don't think it really is a dependency of the package, if anything, it's a dev dependency. Like I said, the idea is to generate the actual syntax and distribute those. The
Definitely a possibility.
If it's mentioned in the docs, it's probably a good idea to include them for completion's sake. I can probably disable them on a per-syntax basis with some macros. I personally have no experience with them either though. I've seen a TODO in the syntax regarding the negative lookbehinds to make sure they're on the start of a line, I'm wondering whether this can be resolved using a start-of-line match (something like |
* Docs for the custom macros. * A boilerplate macros file to instantiate for new languages. * Clarifications on the base template.
This comment was replicated in each generated syntax. The top-level ones aren't (thankfully).
- Change naming scheme from "Jinja (host)" to "host (Jinja2)" - Add option to !base_syntax macro to supply custom name for the host syntax, to be used when it would lead to an ugly syntax name. - Use a custom name for the bash syntax, going from "Bourne Again Shell (bash) (Jinja2)" to "bash (Jinja2)"
- Enable line statements by default - Add an override to disable line statements and line comments - Disable line statements and line comments for bash - Make the order of the keys in the file deterministic and follow the same order as the base template.
Is this PR/idea dead? I'd like to use this in a YAML based syntax plugin I am working on. |
No the PR/idea is not dead (Though I apologies for taking a long time to get to this). The PR was made when ST4 was still in beta period and ST3 was being used. In ST3, the only way (AFAIK) to reuse a syntax was to use yaml-macros. But now, we have inheritance as a feature in ST4. I have now gotten around to adding this to PC and restricting it to ST4 (Since ST4 has had a couple of stable releases & I don't want to go down the road for maintaining it for ST3). I am currently working on a |
Bash is not yet included in #22, but the overall strategy of that PR is what, we are planning to move forward with. |
Here's my proof-of-concept take on #7.
Changes
embed-base.yaml-macros
contains a base template for any embedding language, with macros to populate the necessary fields (file extensions, base scopes, name).embed.py
file contains custom macros to make this easier.Jinja *.sublime-syntax.yaml-macros
contain a small amount of boilerplate to instantiate a template from the syntax definition of the embedding language. Importantly, the!base_syntax
macro loads the embedding syntax (must be installed) and populates a couple of meta-variables used in the macros from that syntax definition.Jinja *.sublime-syntax
file is autogenerated.TODO
#
as the comment.Screenshots
HTML
JSON
(The orange highlight on L5 is because of a linter, not because of the syntax)
Shell
Generic