diff --git a/Python/Embeddings/RegExp (for Python).sublime-syntax b/Python/Embeddings/RegExp (for Python).sublime-syntax index ee204ab096..52d092f11d 100644 --- a/Python/Embeddings/RegExp (for Python).sublime-syntax +++ b/Python/Embeddings/RegExp (for Python).sublime-syntax @@ -13,6 +13,10 @@ variables: deactivate_x_mode: (?:\?[imsLua]*-[imsLua]*x[imxsLua]*) other_modifiers: \?(?:[ixmsLua]*-)?[ixmsLua]+ + # capture group identifiers + capture_group_name: (?:[[:alpha:]_]\w*) + capture_group: (?:[1-9][0-9]*|{{capture_group_name}}) + contexts: base: - meta_prepend: true @@ -25,21 +29,30 @@ contexts: group-start: - meta_prepend: true - - match: (\?P=)([a-zA-Z_][a-zA-Z_0-9]*\w*)(?=\)) + - match: (\?P=)({{capture_group_name}})(?=\)) captures: 1: keyword.other.back-reference.named.regexp 2: variable.other.backref-and-recursion.regexp - - match: (\?P)(<)([a-z]\w*)(>) + - match: (\?P)(<)({{capture_group_name}})(>) captures: 1: keyword.other.backref-and-recursion.regexp 2: punctuation.definition.capture-group-name.begin.regexp 3: entity.name.capture-group.regexp 4: punctuation.definition.capture-group-name.end.regexp - - match: (\?)(\()([1-9][0-9]?|[a-zA-Z_][a-zA-Z_0-9]*)(\)) - # We can make this more sophisticated to match the | character that separates - # yes-pattern from no-pattern, but it's not really necessary. + # We can make this more sophisticated to match the | character that separates + # yes-pattern from no-pattern, but it's not really necessary. + - match: (\?)(\()({{capture_group}})(\)) captures: 1: keyword.other.backref-and-recursion.conditional.regexp 2: punctuation.definition.group.begin.assertion.conditional.regexp 3: variable.other.back-reference.regexp 4: punctuation.definition.group.end.assertion.conditional.regexp + + backrefs: + - meta_prepend: true + - match: \\g(<)({{capture_group}})(>) + scope: keyword.other.backref-and-recursion.regexp + captures: + 1: punctuation.definition.capture-group-name.begin.regexp + 2: variable.other.backref-and-recursion.regexp + 3: punctuation.definition.capture-group-name.end.regexp diff --git a/Python/tests/syntax_test_python_strings.py b/Python/tests/syntax_test_python_strings.py index cbf8ec5f77..eb378885e2 100644 --- a/Python/tests/syntax_test_python_strings.py +++ b/Python/tests/syntax_test_python_strings.py @@ -102,8 +102,8 @@ # ^ constant.character.escape.python regex = r'\b ([fobar]*){1}(?:a|b)?' -# ^ meta.string.python keyword.control.anchor.regexp -# ^ keyword.operator.quantifier.regexp +# ^^ meta.string.python keyword.control.anchor.regexp +# ^^^ keyword.operator.quantifier.regexp regex = r'.* # Not a comment (yet)' # ^^^^^^^^^^^^^^^^^^^^^ - comment @@ -115,6 +115,43 @@ # ^ punctuation.definition.string.end.python - comment # ^ - invalid +regex = r"(backref) \1 " +# ^^ keyword.other.backref-and-recursion.regexp +# ^ variable.other.backref-and-recursion.regexp +# ^ - keyword + +regex = r'(?P[\'"]).*?(?P=quote)' +# ^^ keyword.other.backref-and-recursion.regexp +# ^ punctuation.definition.capture-group-name.begin.regexp +# ^^^^^ entity.name.capture-group.regexp - invalid +# ^ punctuation.definition.capture-group-name.end.regexp +# ^^^ keyword.other.back-reference.named.regexp +# ^^^^^ variable.other.backref-and-recursion.regexp - invalid + +regex = r'(?P[\'"]).*?(?P=Quote)' +# ^^ keyword.other.backref-and-recursion.regexp +# ^ punctuation.definition.capture-group-name.begin.regexp +# ^^^^^ entity.name.capture-group.regexp - invalid +# ^ punctuation.definition.capture-group-name.end.regexp +# ^^^ keyword.other.back-reference.named.regexp +# ^^^^^ variable.other.backref-and-recursion.regexp - invalid + +regex = r'(?P[\'"]).*?\g' +# ^^ keyword.other.backref-and-recursion.regexp +# ^ punctuation.definition.capture-group-name.begin.regexp +# ^^^^^ entity.name.capture-group.regexp - invalid +# ^ punctuation.definition.capture-group-name.end.regexp +# ^^ keyword.other.backref-and-recursion.regexp +# ^^^^^ variable.other.backref-and-recursion.regexp - invalid + +regex = r'(?P[\'"]).*?\g' +# ^^ keyword.other.backref-and-recursion.regexp +# ^ punctuation.definition.capture-group-name.begin.regexp +# ^^^^^ entity.name.capture-group.regexp - invalid +# ^ punctuation.definition.capture-group-name.end.regexp +# ^^ keyword.other.backref-and-recursion.regexp +# ^^^^^ variable.other.backref-and-recursion.regexp - invalid + regex = r'''\b ([fobar]*){1}(?:a|b)?''' # ^ keyword.control.anchor.regexp # ^ keyword.operator.quantifier.regexp