Sublime Forum

[Syntax Highlight] How to match already matched text

#1

Hi,

I want to add highlight to some variation of Assembler. It looks like this:

.data
tabA:	.space	1040
sumB:	.double	0.0

.text
	sgei	r30, r1, #1040
	bnez	r30, ExitA

.data
wspB:	.double	2.2

.text
    	addi	r1, r1, #8

The definitions: .data, and .text are starting sections where there are special rules inside.

I define following rules to get section of data and section of text

- comment: data section
  name: entity.section
  begin: ^\.data$
  end: ^\.text$
  patterns:
    # rules related to data section
- comment: text section
  name: entity.section
  begin: ^\.text$
  end: ^\.data$
  patterns:
    # rules related to text section

Unfortunately it does not highlight .text section because begin: ^\.text$ is already consumed by end: ^\.text$ of previous section.

How to rematch end regexp in next rules.

0 Likes

#2

You can surround your end pattern with (?: ) to have a matching regexp that does not consume the text (lookahead).

0 Likes

#3

While using look ahead groups is indeed the solution to this, the actual syntax is ^(?=\.text$).

(?:) is a non-capturing group. Non-capturing groups do not create a capture, but they do consume characters and cause them to not get matched again.

1 Like

#4

@FichteFoll Thank you. It works!

0 Likes