Home Download Buy Blog Forum Support

Changing syntax regex ?

Changing syntax regex ?

Postby zyzzyr on Thu Oct 18, 2012 9:46 pm

Hi,

Short: I'm trying to change a syntax definition so as to stop capturing string.quoted.single.c if the ' is preceded by a #

Description:
I am switching from Textmate to Sublime Text 2 for LPC programming. This uses mostly C syntax, with a notable exception: we have a 'closure' which has the format of:

#'func_name

The problem I'm having is that the ' in #' gets captured by the string.quoted.single.c bit of syntax highlighting.

I'd avoided this in Textmate using the following change in the syntax definition:

Code: Select all
      {   name = 'string.quoted.single.c';
         begin = "(?<!#)'";
         end = "'";
         beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.c'; }; };
         endCaptures = { 0 = { name = 'punctuation.definition.string.end.c'; }; };
         patterns = ( { include = '#string_escaped_char'; } );
      },


I tried altering both the C.tmlanguage file with the (?<!#) addition, but this ends in a parsing failure. I've tried editing the user specific syntax with a snippet to override string.quoted.single.c.

Code: Select all
{ "name": "LPC Single-Quote",
  "scopeName": "source.c",
  "fileTypes": ["c""h"],
  "patterns": [
    {"name": "string.quoted.single.c",
   "begin": "(?<!#)'",
   "beginCaptures": {
     "0" : { "name" : "punctuation.definition.string.begin.c" }
   },
   "endCaptures" : {
     "0" : { "name" : "punctuation.definition.string.end.c" }
   },
   "patterns" : [ { "include" : "#string_escaped_char"} ],
   "end" : "'"
}
  ],
  "uuid": "2aeaa0d9-69e2-46a5-b631-792d8e0d8182"
}


I've tried editing a new snippet with that as well. I've also tried creating a new snippet called string.closure.c which tried to match #' and capture that over the string.quoted.single.c and format it a different colour. I've tried placing this snippet in C.sublime-settings. None of these have been successful -- and I'm sure it's because I'm doing something wrong.

Can someone lend a hand? I just want sublime text "C" parser to ignore #' rather than thinking it's the beginning of a string.

Thanks

Zyzzyr
zyzzyr
 
Posts: 2
Joined: Thu Oct 18, 2012 9:35 pm

Re: Changing syntax regex ?

Postby zyzzyr on Thu Oct 18, 2012 11:04 pm

Ok, well after much hacking I finally got it to work.

I replaced the line

Code: Select all
         <string>'</string>


with

Code: Select all
         <string>(?&lt;!#)'</string>


which is essentially what I was doing in textmate, but I replaced the < for &lt; due to the use of xml.

I could still use some help if anyone has ideas, so that I can capture #' and highlight that differently.

Cheers

Zyzzyr
zyzzyr
 
Posts: 2
Joined: Thu Oct 18, 2012 9:35 pm

Re: Changing syntax regex ?

Postby nick. on Fri Oct 19, 2012 9:38 pm

You might be able to use AAAPackageDev to convert your custom Textmate syntax definition from JSON to XML.

If that doesn't work, you can still translate the change you made:
Code: Select all
<dict>
    <key>name</key>
    <string>string.quoted.single</string>
    <key>begin</key>
    <string>(?&lt;!#)'</string>
    <key>end</key>
    <string>'</string>
    <key>beginCaptures</key>
    <dict>
        <key>0</key>
        <dict>
            <key>name</key>
            <string>punctuation.definition.string.begin.c</string>
        </dict>
    </dict>
    <key>endCaptures</key>
    <dict>
        <key>0</key>
        <dict>
            <key>name</key>
            <string>punctuation.definition.string.end.c</string>
        </dict>
    </dict>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>#string_escaped_char</string>
        </dict>
    </array>
</dict>
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: Changing syntax regex ?

Postby abathur on Sat Feb 02, 2013 6:12 am

Another LDMud dev curious if you got this sorted already, Zyzzyr. Any luck?
abathur
 
Posts: 2
Joined: Sat Feb 02, 2013 6:09 am


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 21 guests