I’m attempting to write a sublime-syntax description for a language which uses indent-based blocks (like python or coffeescript). One feature of this language is a comment-block. Here is the logic:
- It starts with a double hash (##)
- If the first non-blank line after that is indented more than the line the ## was on, that line defines the indent-level for the rest of the block.
- Every following, non-blank line that is indented >= the defined indent level is part of the block
- If a line is found with less indentation, the comment block ends (that line is not in the comment)
The regex below is very close to capturing the logic above. The only thing it misses is the “indented MORE than the line the ## started on.” I’d be happy if everything in the file that matched this regex was highlighted as a comment. It isn’t quite right, but it works for all “real-world” cases. The regex:
/##(?: *\n)+( *)([^ \n][^\n]*)(\n( *\n)*\1[^\n]*)*/
Last, here is an example of what should and should-not be highlighted:
while true
something ##
in comment
in comment
in comment
not.in.comment
not.in.comment
not.in.comment
while true
something ##
not.in.comment
while true
something ##
not.in.comment
I’ve been banging my head against this for a couple of hours now. Thanks in advance!