[TxMt] Re: Use begin marker of a scope to end the previous one

Allan Odgaard mailinglist at textmate.org
Thu Apr 16 09:49:33 UTC 2009


On 8 Apr 2009, at 23:11, Édouard Gilbert wrote:

> [...]
> Actually, ‘a’ opens a scope A, ‘b’ both closes A and opens another  
> scope B, which is then closed by ’c’.
> Note that while I’m interested in scopes, I’m even more interested  
> in grammars development.
>
> An actual example could help:
> <a # opens a scope for autocompletion of attributes of tag a
> 	
> > # closes the attributes scope and open a scope for autocompletion  
> of every possible child of a
>
> </a> # closes everything.
>
> Writing directly
> >
>
> </a>
> is of course meaningless.
>
> A third scope, which opens with <a and closes with </a> might also  
> be useful.

There are several ways to tackle this, but no ideal way, i.e. they all  
have pros/cons.

I’d probably approach it something like this:

     begin = "(?=<(\w+))"       # general tag
        begin = "<a\b"          # it was an <a …> tag
        end   = ">"             # we leave when seeing >
           include = #attr_rules

        begin = "(?!</)(?<=>)"  # we just left previous rule and is  
inside the actual tag content
        end   = "(?=</)"        # we leave when we see an end tag
           include = $self

     end   = "</$1>"            # leave the general tag

This is probably where you got a infinite loop, I made a negative look- 
ahead assertion on the second inner rule, as it would otherwise fail  
on data like: <a></b>.

I didn’t test this, and as said, this is just one approach to a  
problem that does not have an obvious solution, Michael Sheets  
probably can tell you a lot more about the pros/cons of the various  
approaches.






More information about the textmate mailing list