Hello all,
I'm not sure if this is where I'm supposed to ask or not, but I thought I'd ask anyway.
I'm making a bundle for ExpressionEngine (http://www.pmachine.com/). So far, I've got a bunch of snippets which are working out really nice. I'd like to have a language definition file though so the EE tags can be highlighted and folded. I can't wrap my head around how these language files are put together though, so I thought I'd ask if there was a wizard out there who could make it for me?
Some example EE tags:
Single Tag: {assign_variable:variable_name="variable_replacement"}
or
{path='weblog/comments'}
Tag Pairs: {exp:comment:entries sort="asc" limit="20"} {comment} <p>By {name} on {comment_date format="%Y %m %d"}</p> {/exp:comment:entries}
or
{exp:weblog:month_links weblog="news" limit="50"} {month}, {year}<br /> {/exp:weblog:month_links}
Conditionals: {if username == "joe"} <h1>Hi Joe!</h1> {/if}
Tags are normally used inside of XHTML/HTML, but can be used within other languages like XML, CSS, JavaScript, etc. All tag pairs will always begin with {exp:*} and end with {/exp:*}. You can see examples of EE variables inside of the tag pairs. A lot of tag pairs have parameters, but not all of them. Sometimes people use double quotes, other times single quotes.
I'm not sure what else to add. If someone would be willing to help me out on this I'd really appreciate it.
Thanks, Chris
Making it work in non-html files would be a good bit of work, however from first glance the syntax of the tags looks close enough to smarty for that to work for the HTML part. You could just duplicate the html syntax file and change a few lines (namely the file extensions captured and renaming smarty to EE). Might not be perfect but it will get you a lot closer pretty quick. (Make sure to make a new language file from within TextMate so it gets a unique scope)
When I see regular expressions, I scream like a frightened little girl. I've tried creating some for the code-folding bits of the language file by using TextMate help, but I get nowhere with it.
Chris
On Aug 24, 2005, at 3:06 PM, Allan Odgaard wrote:
On 24/08/2005, at 5.26, Chris Ruzin wrote:
[...] I can't wrap my head around how these language files are put together though
Asking out of interest to document this better: are you familiar with regular expressions?
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
I can answer on that as well; no, unfortunately not. Though I'm almost feeling inclined to learn since so many settings and stuff in TextMate and other programs rely on it. Also, I suppose it might one day make a complex task really easy. Any good suggestions on where to start? Is there a good "cover all" tutorial somewhere?
Andreas
On Aug 24, 2005, at 22:06 , Allan Odgaard wrote:
On 24/08/2005, at 5.26, Chris Ruzin wrote:
[...] I can't wrap my head around how these language files are put together though
Asking out of interest to document this better: are you familiar with regular expressions?
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Just to give everyone an update, I've now got a really basic language definition working. It folds code where it's supposed to and highlights EE tags and strings. It will only do this if I choose ExpressionEngine as the language though. What I'm wanting is to have EE tags folded and colorized even when HTML is the language.
My definition is small, so I've copied it below for others to critique. Keep in mind I don't know what the hell I'm doing.
--- { scopeName = "source.ee"; fileTypes = ( "html", "htm", "php" ); foldingStartMarker = "\{(exp:([a-zA-Z0-9:]+)|if)\b.*?\}"; foldingStopMarker = "\{/(exp:([a-zA-Z0-9:]+)|if)\}"; patterns = ( { name = "constant.tag.ee"; begin = "\{/?([-a-zA-Z0-9_:]+)"; end = "\}"; captures = { 1 = { name = "entity.name.tag.html"; }; }; patterns = ( { name = "declaration.attribute-with-value.id.ee"; match = " (id)=(("|')(.*?)\3)"; captures = { 1 = { name = "entity.parameter.attribute.tag.id.html"; }; 2 = { name = "string.html"; }; 4 = { name = "value.html"; }; }; }, { name = "entity.parameter.attribute.tag.ee"; match = " ([a-zA-Z-:]+)"; }, { name = "string.double-quoted.ee"; begin = """; end = """; }, { name = "string.single-quoted.ee"; begin = "'"; end = "'"; }, ); } ); } ---
I defined EE tags as constants because I wanted them to stand out within HTML code. If you see things I'm doing wrong (which I'm sure I am), please give me some advice/tips/help.
Thanks, Chris
On 25/08/2005, at 8.40, Chris Ruzin wrote:
[...] What I'm wanting is to have EE tags folded and colorized even when HTML is the language.
What you should do is include the HTML language from your EE grammar. That way, it will, in addition to your rules, use all the rules of the HTML language, and thus colorize HTML as well (see below).
My definition is small, so I've copied it below for others to critique. Keep in mind I don't know what the hell I'm doing.
{ scopeName = "source.ee";
Since this is embedded in HTML (as I understand), you probably want to name the scope something like “text.html.ee” -- that way, all snippets/commands etc. which have their scope set to “text.html” will also work when in EE files.
fileTypes = ( "html", "htm", "php" ); foldingStartMarker = "\\{(exp:([a-zA-Z0-9:]+)|if)\\b.*?\\}"; foldingStopMarker = "\\{/(exp:([a-zA-Z0-9:]+)|if)\\}"; patterns = ( { name = "constant.tag.ee"; begin = "\\{/?([-a-zA-Z0-9_:]+)"; end = "\\}"; captures = { 1 = { name = "entity.name.tag.html"; }; }; patterns = ( [...] { name = "string.single-quoted.ee"; begin = "'"; end = "'"; },
Here you add:
{ include = "text.html.basic"; },
); } );
}
I defined EE tags as constants because I wanted them to stand out within HTML code. If you see things I'm doing wrong (which I'm sure I am), please give me some advice/tips/help.
I'd suggest two other approaches, 1) name them source.ee.embedded instead -- there's a style which set the background color of source in text, and thus, the tags will stand out (this assumes though, that they are source), 2) name them meta.ee-tag or something like that, and just add the style you want for that name in Fonts & Colors preferences.
But ultimately, the choice is of course yours! :)
Thanks for the help, Allan. I tried adding in the include where you mentioned, but it doesn't work. The EE tags are highlighted and folded, but not the HTML.
Also, EE tags can be used in more than HTML. They can be used in XML, PHP, JavaScript, CSS and others. Will that mean I need to add all those other languages too, or will text.html.basic work for all of those?
I've also renamed the scope to "text.html.ee", like you suggested.
Thanks, Chris
On Aug 25, 2005, at 2:06 AM, Allan Odgaard wrote:
Since this is embedded in HTML (as I understand), you probably want to name the scope something like “text.html.ee” -- that way, all snippets/commands etc. which have their scope set to “text.html” will also work when in EE files.
fileTypes = ( "html", "htm", "php" ); foldingStartMarker = "\\{(exp:([a-zA-Z0-9:]+)|if)\\b.*?\\}"; foldingStopMarker = "\\{/(exp:([a-zA-Z0-9:]+)|if)\\}"; patterns = ( { name = "constant.tag.ee"; begin = "\\{/?([-a-zA-Z0-9_:]+)"; end = "\\}"; captures = { 1 = { name = "entity.name.tag.html"; }; }; patterns = ( [...] { name = "string.single-quoted.ee"; begin = "'"; end = "'"; },
Here you add:
{ include = "text.html.basic"; },
); } );
}
On 25/08/2005, at 19.06, Chris Ruzin wrote:
Thanks for the help, Allan. I tried adding in the include where you mentioned, but it doesn't work. The EE tags are highlighted and folded, but not the HTML.
Sorry, I placed it wrong. I made it a child of “constant.tag.ee” rule, when it should have been a sibling.
Also, EE tags can be used in more than HTML. They can be used in XML, PHP, JavaScript, CSS and others. Will that mean I need to add all those other languages too, or will text.html.basic work for all of those?
hmm, that's a little problematic, because while the HTML language will take care of embedded PHP, CSS, and JavaScript, it will use a special set of (included) patterns for these subsets of the document, which doesn't include the EE rules.
So for this to really work, you'd have to duplicate the HTML syntax, and add the EE rules to that (the EE rules can be added to the repository part, and included from the 4 contexts (plain HTML, JS, CSS, and PHP), much like PHP is currently included in the CSS and JS sub-contexts.
fileTypes = ( "html", "htm", "php" ); foldingStartMarker = "\\{(exp:([a-zA-Z0-9:]+)|if)\\b.*?\\}"; foldingStopMarker = "\\{/(exp:([a-zA-Z0-9:]+)|if)\\}"; patterns = ( { name = "constant.tag.ee"; begin = "\\{/?([-a-zA-Z0-9_:]+)"; end = "\\}"; captures = { 1 = { name = "entity.name.tag.html"; }; }; patterns = ( [...] { name = "string.single-quoted.ee"; begin = "'"; end = "'"; },
Here you add:
{ include = "text.html.basic"; },
); }
Should have been here. Add a comma after the bracket above and insert: { include = "text.html.basic"; },
);
}