[TxMt] RegExp n00b

Andreas Wahlin andreaswahlin at bredband.net
Tue Sep 13 19:35:09 UTC 2005


(CHAIN OF THOUGH, PROBABLY DEPRECATED)
Thanks for all the RegExp help ... I'm getting closer but it seems  
far from a cigar.
I tried to add this, after the normal tag declaration (that is,  
almost first in the language)

         {    name = "declaration.tag.html";
             match = "<(img)[^>]*(>)";
             captures =
             {    1 = { name = "entity.name.tag.img.html"; };
                 2 = { name = "meta.scope.between-tag-pair.html"; };
             };
         },

It's a modified version of the first code, since no image tags have  
closing </img> things, but rather <img ... > I removed the \\b and  
the </(\\1)> parts. Also the removed the last capture. Now this does  
indeed make the scope catch entity.name.tag.img.html (is that the  
correct syntax?) but it does not capture any of the attributes in  
between. Now from looking at this it seems the only thing that would  
be captured as meta.scope.between-tag-pair.html would be the final >  
from the code above, but I tried some other stuff and I always got  
stuck with either having img tags or attributes, not both :(
I also do not really get the inital (?i:( part of the original tag  
catching code, shouldn't ?'s be used after something to mean 1 or 0  
occurrences of that very thing? (I also suppose : is some xml  
thingie) Just noted that (?:subexp) means "not captured group", but  
that wouldn't apply here since there's an "i" in between?
It feels quite hard after all, since it's difficult to read and  
understand the underlying ideas with all capture rules.
(END CHAIN OF THOUGHT)

DID SOME MORE RESEARCH and found out that perhaps I should rather  
have edited further down and popped in something like
         {    name = "declaration.tag.html";
             begin = "<(img)";
             end = ">";
             captures = { 1 = { name = "entity.name.img.tag.html"; }; };
             patterns = ( { include = "#tag-stuff"; } );
         },

which makes sense given the repository and the tag-stuff, but this  
doesn't seem to do anything either, and if this is the place where  
tags are caught (which seems likely since it worked rather fine even  
when i removed the code mentioned above), what does the
         {    name = "declaration.tag.html";
             match = "<(?i:(head|table|thead|tbody|tfoot|tr|td|div| 
fieldset|style|script|ul|ol|li|form|dl))\\b[^>]*(>)</(\\1)>";
             captures =
             {    1 = { name = "entity.name.tag.html"; };
                 2 = { name = "meta.scope.between-tag-pair.html"; };
                 3 = { name = "entity.name.tag.html"; };
             };
         },

part do?

Lots of questions, I know. Hate to be a bother and all that but I've  
spent quite some time trying to get my head around this and it would  
be nice to get to the bottom of it. I hope I haven't overlooked any  
obvious source that tells me all the answers. I have looked in the  
TextMate blog and also on the RegExp that textmate is said to follow  
(though not overly studied either source). Hope I'm not being overly  
lazy by posting all these questions instead of fighting it out like a  
man with a big manual.

hehe, as a final, light note, I entered the word bar in a file and  
then tried to a regexp find for both bar\\w bar\w (bar)\w (bar)\\w  
but neither found it, what was wrong with that?

Andreas 



More information about the textmate mailing list