Sublime Forum

Regex works in the find bar but not in syntax definition. Help?

#1

I’m trying to create a syntax definition for the Creole wiki markup language. I’m having trouble creating a regex to recognise preformatted blocks. The section of the syntax definition pertaining to these, as well as to inline preoformatted section is as follows:

    # Nowiki
    - match: '^({{{)\s*(?=\n(?:.*\n)*}}})'
      captures: 
        1: punctuation.definition.raw.creole
      push: nowiki-block
    - match: '({{{)(?=.*}}})'
      captures: 
        1: punctuation.definition.raw.creole
      push: nowiki-inline

Inline sections are recognised perfectly well but blocks are not. The strange thing is that the regex for blocks appears to work as expected if used in the find bar. Any help would be much appreciated.

0 Likes

#2

The syntax highlight works line by line, so a regex trying to capture multiple line won’t work.
In your case if feels like this should be easy to fix: just match the start {{{, push a context that will pop when matching the end pattern }}}

0 Likes

#3

Thanks for the reply. As it happens I got a reply on the IRC channel. I’ve done as you suggested. It doesn’t disallow incorrect formatting as I’d like it to but such is life.

It seems that the old tmLanguage format had some sort of multiline capability. Do you know if that’s making a return at all?

0 Likes

#4

I don’t think so but I’m not jps!

IMHO it’s better to provide correct syntax highlighting even when their is a missing closing bracket. I really hate when IDE turn all my code to red because I accidentally deleted a bracket while writing.

In your case I think it would still be obvious for the user that he didn’t close one ‘no-wiki’ block because all the rest of the file would be strangely highlighted.

0 Likes

#5

It did not. Unless you are referring to the “begin-end-patterns”, which the new format supports as well by explicitly pushing a context instead.

0 Likes