Home Download Buy Blog Forum Support

Column matching for syntax highlighting?

Column matching for syntax highlighting?

Postby Smotricz on Sun Jun 17, 2012 9:23 pm

I'm planning to use ST to edit (mostly) "punch-card FORTRAN" using The TextMate FORTRAN bundle. I'm almost happy with this, but there's a disconnect between this strictly column-oriented language and regexp-based expression matching. I would like to highlight
  • Line continuation characters (any character in column 6 in a non-comment line); and
  • Line sequence numbers (in columns 73-80)
Vim offers the special column-matching construct %nc to match column n. I had been hoping to accomplish something like this using look-behinds:
Code: Select all
(?<=^.{72})\S

but this doesn't work and makes ST angry: syntax highlighting stops working until I restart ST.

Any helpful ideas of how to accomplish this with Oniguruma regexp's, or any chance of getting a feature implemented for this?
Smotricz
 
Posts: 3
Joined: Sun Jun 17, 2012 8:54 pm

Re: Column matching for syntax highlighting?

Postby agibsonsw on Sun Jun 17, 2012 10:12 pm

I'm not sure where you're using your regex, but if within a syntax file then you'll need to entity-encode the less than < symbol:

Code: Select all
(?&lt;=^.{72})\S

You might also try an explicit capture, although it's not generally necessary:
Code: Select all
(?&lt;=^.{72})(\S)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Column matching for syntax highlighting?

Postby Smotricz on Mon Jun 18, 2012 8:46 am

Thanks for your quick response! I directly modified the XML, and yes, I did the entity encoding, just left it out in this post for clarity. There's a very explicit error message when your XML isn't well-formed.

I can try the explicit capture later today. I may also try directly matching the text to be marked rather than trying to define a begin and end match. I'll report back!
Smotricz
 
Posts: 3
Joined: Sun Jun 17, 2012 8:54 pm

Re: Column matching for syntax highlighting?

Postby Smotricz on Wed Jun 20, 2012 11:57 am

After that encouragement, I managed to implement sensible solutions; thanks again!

To share with other folks in a similar predicament, I solved the problem by matching the whole target rather than a "begin" and "end." This also benefits from a simpler syntax in the definition. Here's my solution for the junk beyond column 72:

Code: Select all
<key>comment</key>
<string>FORTRAN sequence numbers past column 73</string>
<key>match</key>
<string>(?&lt;=^.{72})\s*\S.*?(?=\s*$)</string>
<key>name</key>
<string>comment.fortran</string>


As planned, I eat the 72 chars from the line's beginning in a lookbehind on 72 characters. I don't care about trailing blanks, so I swallow those with a lookahead expression.

Similar technique to highlight any nonblank in column 6 that's not in a comment:

Code: Select all
<key>comment</key>
<string>FORTRAN continuation char in column 6</string>
<key>match</key>
<string>(?&lt;=^.{5})\S</string>
<key>name</key>
<string>invalid.deprecated.fortran</string>
Smotricz
 
Posts: 3
Joined: Sun Jun 17, 2012 8:54 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 33 guests