Why does `captures` not work in tmLanguage when the capture groups are too complex?

94 Views Asked by At

I'm wondering why captures isn't able to determine the capture groups when they get too complex.

I have created the following regex, and it only matches the first group.

(type)(((( |\t))|((\/\*(([^\*\/])+)?\*\/))|((\/\/(([^\n])+)?\n))))+(\&)?(\$|\_|[a-zA-Z])((\$|\_|[a-zA-Z0-9])+)?((((( |\t))|((\/\*(([^\*\/])+)?\*\/))|((\/\/(([^\n])+)?\n))))+)?(=)

When I change it to the following regex, the captures can be applied to the appropriate scopes in captures:

(type)(\s+)([a-zA-Z0-9]+)(\s+)(=)

Is this happening because it is a simplified regex, or because something is wrong with my capture groups?

Breakdown of regex

1: Find the type keyword

(type)

2: Whitespace or a comment

(((( |\t))|((\/\*(([^\*\/])+)?\*\/))|((\/\/(([^\n])+)?\n))))+

3: Variable name

(\&)?(\$|\_|[a-zA-Z])((\$|\_|[a-zA-Z0-9])+)?

4: Whitespace or a comment

(((( |\t))|((\/\*(([^\*\/])+)?\*\/))|((\/\/(([^\n])+)?\n))))+
  1. Equal sign
(=)

EDIT

I noticed my regex is a bit messy, so here's a better one that also doesn't work:

/(type)((\/\*([^\*\/]+)?\*\/)|(\/\/([^\n]+)?\n)| |\t)+((\$|\_|[a-zA-Z])((\$|\_|[a-zA-Z0-9])+)?)((\/\*([^\*\/]+)?\*\/)|(\/\/([^\n]+)?\n)| |\t)+(=)/
0

There are 0 best solutions below