From 0080e090658ca916100cb43a113f41a4da6987c6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sun, 24 Mar 2013 23:15:26 -0400 Subject: [PATCH] Only check for back references in end patterns Back references can occur in match values but should not be treated differently when present there since they refer to groups inside the match. Close #370 --- spec/app/text-mate-grammar-spec.coffee | 6 ++++++ src/app/text-mate-grammar.coffee | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee index 8d421b142..80d2a8df1 100644 --- a/spec/app/text-mate-grammar-spec.coffee +++ b/spec/app/text-mate-grammar-spec.coffee @@ -268,3 +268,9 @@ describe "TextMateGrammar", -> expect(tokens[0].value).toBe "a" expect(tokens[1].value).toBe "bc" expect(console.error).toHaveBeenCalled() + + describe "when a grammar has a pattern that has back references in the match value", -> + it "does not special handle the back references and instead allows oniguruma to resolve them", -> + grammar = syntax.selectGrammar("style.scss") + {tokens} = grammar.tokenizeLine("@mixin x() { -moz-selector: whatever; }") + expect(tokens[9]).toEqual value: "-moz-selector", scopes: ["source.css.scss", "meta.property-list.scss", "meta.property-name.scss"] diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee index 94a6c0ff4..93fe9559f 100644 --- a/src/app/text-mate-grammar.coffee +++ b/src/app/text-mate-grammar.coffee @@ -159,10 +159,10 @@ class Pattern backReferences: null anchored: false - constructor: (@grammar, { name, contentName, @include, match, begin, end, captures, beginCaptures, endCaptures, patterns, @popRule, hasBackReferences}) -> + constructor: (@grammar, { name, contentName, @include, match, begin, end, captures, beginCaptures, endCaptures, patterns, @popRule, @hasBackReferences}) -> @scopeName = name ? contentName # TODO: We need special treatment of contentName if match - if @hasBackReferences = hasBackReferences ? /\\\d+/.test(match) + if (end or @popRule) and @hasBackReferences ?= /\\\d+/.test(match) @match = match else @regexSource = match