Sublime Forum

Text highlight regex not matching new line

#1

I’m making a file format for my own use and I wanted to have proper highlighting.

I want to be able to match next line in regex, but that doesn’t seem to be working in Sublime Text 3. I read in some forum post that everything is matched line by line to improve performance. Is it possible to tell sublime that I want to match with next line also?

%YAML 1.2
---
name: View Object Notation
file_extensions: [von]
scope: scope

contexts:
  main:

    - match: 'TEST\sBACK'
      scope: entity.name.tag

Other regex tools show me a match, but in Sublime it doesn’t work if I put new line character between TEST and BACK

TEST
BACK
1 Like

#2

The other posts didn’t lie. You can not match multiple lines in a single regular expression in syntax definitions.

You can, however, push a context on the stack when matching the text on the first line where you search for the text on the second line and immediately pop the context. The second pattern in that context should match the first character (or sequence) in a look-ahead group to not consume the characters and also pop the context.

I would prepare a simple example, but I’m on mobile right now and some details about the match aren’t clear (and I cba to ask for all of them).

1 Like

#3

What I’m trying to do is:

ObjectTag {
	Type SomeObjectType
}

AnotherObjectTag {
	SomeParameter 100.0
}

I’m trying to give ObjectTag a different scope based on the next line. If next line has ‘Type’, then I want to give one scope, and if it isn’t type, I want to give it another scope.

# (this is the line that opens object with '{' )
if nextLine==Type
	scope = scope.Tag
else 
	scope = scope.Object
0 Likes

#4

I don’t think you can: since it is line by line, the scope for ObjectTag and AnotherObjectTag have to be assigned before the next line is read.

1 Like

#5

Not possible, as @Clams mentioned.

0 Likes