Home Download Buy Blog Forum Support

[SOLVED] Syntax .tmLanguage and Indentation

[SOLVED] Syntax .tmLanguage and Indentation

Postby Pwipwi on Tue Feb 07, 2012 10:42 am

Is it me or it is not possible to match indentation levels in the syntax of a language ?

For instance, I have an indentation-based language like HaML that has the following form:

Code: Select all
@div.myclass Hello
    :css
        #mystuff { color: #fff }
    @div.morestuff
         More stuff here !


I would like to display the #mystuff part with css, which imposes-me to match a region starting by :css and ending at the next same-or-less indentation level.
I have tried stuff like begin: "(\s+):css" and end: "\1[^\s]", but it has numerous problems : it won't detect a sudden de-indent and the first letter of the next line is eaten by the matcher, preventing @div from being matched.

How can I achieve that ?
Last edited by Pwipwi on Tue Feb 07, 2012 4:12 pm, edited 1 time in total.
Pwipwi
 
Posts: 11
Joined: Tue Feb 07, 2012 10:31 am

Re: Syntax .tmLanguage and Indentation

Postby sublimator on Tue Feb 07, 2012 12:42 pm

I'm gathering from your other posts that you are coming from VIM?

Is what you are trying to do possible in VIM?
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: Syntax .tmLanguage and Indentation

Postby Pwipwi on Tue Feb 07, 2012 2:33 pm

I don't think I could have this particular exemple working in vim (it may be possible, I don't know), but the one of the other post is.
Pwipwi
 
Posts: 11
Joined: Tue Feb 07, 2012 10:31 am

Re: Syntax .tmLanguage and Indentation

Postby Pwipwi on Tue Feb 07, 2012 2:42 pm

Actually it would seem this is doable in vim : the haml syntax definition works for this :css thing.
Pwipwi
 
Posts: 11
Joined: Tue Feb 07, 2012 10:31 am

Re: Syntax .tmLanguage and Indentation

Postby Pwipwi on Tue Feb 07, 2012 4:09 pm

I confirm that the following construct works: I had tried with \1 in end, but not in the negative look-ahead form.

Code: Select all
"sassblock": {
      "begin": "(\\s*)(:)(s[ca]ss)\\s*",
      "end": "^(?!(\\1\\s+|\\s*$))",
      "patterns": [
        { "include": "source.sass" }
      ],
      "beginCaptures": {
        "2": { "name": "constant.other.niml" },
        "3": { "name": "constant.language.niml" }
      }
    },


This will colorize everything indented after ":sass" with the sass language.
Pwipwi
 
Posts: 11
Joined: Tue Feb 07, 2012 10:31 am

Re: [SOLVED] Syntax .tmLanguage and Indentation

Postby sublimator on Tue Feb 07, 2012 4:40 pm

Ah, cool stuff :) Thank god for lookaheads huh? Just been having some grammar "fun" myself.

I need to clean up/test some grammars for a package I'm working on and it's a royal PITA trying to read/write the xml with the dillion rules. So as one does, I thought to myself, why not a folding navigator for python source? haha

I'm thinking of something similar for firebug css integration. I was never really sold on the idea of folding but I'm glad Jon added it.
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


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 5 guests