Sublime Forum

[SOLVED] Syntax .tmLanguage and Indentation

#1

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:

@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 ?

0 Likes

#2

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

Is what you are trying to do possible in VIM?

0 Likes

#3

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.

0 Likes

#4

Actually it would seem this is doable in vim : the haml syntax definition works for this :css thing.

0 Likes

#5

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

"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.

0 Likes

#6

Ah, cool stuff :smile: 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.

0 Likes