Home Download Buy Blog Forum Support

BracketHighlighter2 BETA Branch

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Fri Oct 26, 2012 5:32 am

iamntz wrote:Thanks! Works... partially :)

because it also match if(){} expressions (and it shouldn't)

what i came up is this pattern:
Code: Select all
            "open": "^\\s*(if|foreach|while).*:$",
            "close": "^\\s*(endif|endforeach|endwhile;$)"


Thing is... while in regexbuddy works just fine, in editor it doesn't. Most likely i do some escaping wrong. Any idea which is that? Thanks!

Btw, i noticed that if there is an error somewhere in the config file, the plugin stop to works until i restart ST. It's a bug, a feature or a bit of both? :D


I need to think about this. Basically the open regex and close regex occur on separate passes. So for "if():" the open regex gobbles up "(" and ")", but the close pass finds ")". So when the brackets get resolved, it can't pair up ")", because the open got gobbled up in "if():".

Basically, the this is a case where the open regex intersects with the close. I need time to think how to resolve this issue.

As for the plugin stopping working on bad settings file? I will have to think about how to gracefully handle that as well.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Fri Oct 26, 2012 5:59 am

@iamntz
I need to change the algorithm to do opening and closing in one pass. I have it working on my computer, but I need to stream line it. I guess it will actually be a little quicker this way.

I will let you know when it is done, maybe sometime in the next couple of days.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby iamntz on Fri Oct 26, 2012 6:08 am

I will let you know when it is done, maybe sometime in the next couple of days.

I survived about 4-5 years without that highlight, I guess i'll handle it few more days! :mrgreen:

Thanks!
iamntz
 
Posts: 911
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: BracketHighlighter2 Alpha Branch

Postby sublimator on Fri Oct 26, 2012 1:14 pm

Dunno what you doing exactly but look ahead / behinds?
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Fri Oct 26, 2012 2:17 pm

castles_made_of_sand wrote:Dunno what you doing exactly but look ahead / behinds?

Yes lookaheads will help him because they won't capture, and can allow things like "()" to be used twice, but regardless it is probably better to do find opening and closing in one shot to limit confusion.

With the current implementation of processing opening and closing separately, it is easy for a user to not really understand what is happening. They expect if they capture something in opening, it shouldn't be captured in closing.

I should have a fix posted in a couple of minutes. I will also post a solution for your problem @imantz using lookaheads.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Fri Oct 26, 2012 2:22 pm

Fix is in on the alpha branch.

Based on your earlier config, try this (I am not entirely sure what you are looking for, so I have just adapted your earlier post):

        {
"name": "php_keywords",
"open": "^\\s*\\b(if|foreach|while)\\b(?=.*:$)",
"close": "^\\s*\\b(endif\\b|endforeach\\b|endwhile(?=;$))",
"icon": "dot",
"color": "brackethighlighter.tag",
"style": "underline",
"language_filter": "whitelist",
"scope_exclude": ["string", "comment"],
"language_list": ["HTML", "HTML 5", "XML", "PHP", "HTML+CFML", "ColdFusion", "ColdFusionCFC"],
"plugin_library": "User.phpkeywords",
"enabled": true
},


A much simplier phpkeywords.py now:
def compare(name, first, second, bfr):
return "end" + bfr[first.begin:first.end].lower() == bfr[second.begin:second.end].lower()


Just to be safe, restart ST2 when you update BH to the latest commit.

Edit: The regex is a little sloppy and can be cleaned up, but it is fine for a starting point.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby vitaLee on Fri Oct 26, 2012 2:29 pm

Yes, lookaheads might help but the problem is they won't capture.
The consequence of that will be if later you'd like to take advantage of other features like "select between brackets", "remove brackets", "go to opening/closing bracket" you'll have problems with leftovers that were't captured, etc..
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Fri Oct 26, 2012 2:41 pm

vitaLee wrote:Yes, lookaheads might help but the problem is they won't capture.
The consequence of that will be if later you'd like to take advantage of other features like "select between brackets", "remove brackets", "go to opening/closing bracket" you'll have problems with leftovers that were't captured, etc..


Yes, there will be a tradeoff. If you use lookaheads, "select between brackets" will grab the "()" brackets which may not be desirable. If you don't use the lookaheads. BH will not match the "()". The good news is I fixed the issue where BH would find the closing bracket twice, now it will just ignore it.

The tradeoff is a limitation of BH. The needed complexity of recursive bracket matching to overcome this I don't think is worth it, but it could be a possibility in the future if it is really required, but I will push back on it for now.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby facelessuser on Fri Oct 26, 2012 2:45 pm

oh @iamntz, you can use the old PHP configuration if you want to capture the round brackets. BH supports that now. I just posted the other because @castles_made_of_sand mentioned the lookaheads. It is a good example of how you can workaround certain scenarios.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: BracketHighlighter2 Alpha Branch

Postby iamntz on Fri Oct 26, 2012 3:31 pm

You rock! Works beautiful. Thanks a lot!
iamntz
 
Posts: 911
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 9 guests