diff --git a/spec/app/text-mate-scope-selector-spec.coffee b/spec/app/text-mate-scope-selector-spec.coffee index b3348c371..a189fdc21 100644 --- a/spec/app/text-mate-scope-selector-spec.coffee +++ b/spec/app/text-mate-scope-selector-spec.coffee @@ -33,3 +33,9 @@ describe "TextMateScopeSelector", -> expect(new TextMateScopeSelector('(a,b) | (c, d)').matches(['c'])).toBeTruthy() expect(new TextMateScopeSelector('(a,b) | (c, d)').matches(['d'])).toBeTruthy() expect(new TextMateScopeSelector('(a,b) | (c, d)').matches(['e'])).toBeFalsy() + + it "matches paths", -> + expect(new TextMateScopeSelector('a b').matches(['a', 'b'])).toBeTruthy() + expect(new TextMateScopeSelector('a b').matches(['b', 'a'])).toBeFalsy() + expect(new TextMateScopeSelector('a c').matches(['a', 'b', 'c', 'd', 'e'])).toBeTruthy() + expect(new TextMateScopeSelector('a b e').matches(['a', 'b', 'c', 'd', 'e'])).toBeTruthy() diff --git a/src/app/text-mate-scope-selector-pattern.pegjs b/src/app/text-mate-scope-selector-pattern.pegjs index 7b5285b1d..c92993b9e 100644 --- a/src/app/text-mate-scope-selector-pattern.pegjs +++ b/src/app/text-mate-scope-selector-pattern.pegjs @@ -39,8 +39,26 @@ scope } } +path + = first:scope others:(_ scope)* { + return function(scopes) { + var scopeMatchers = [first]; + for (var i = 0; i < others.length; i++) + scopeMatchers.push(others[i][1]); + + var matcher = scopeMatchers.shift(); + for (var i = 0; i < scopes.length; i++) { + if (matcher(scopes[i])) + matcher = scopeMatchers.shift(); + if (!matcher) + return true; + } + return false; + } + } + expression - = scope + = path / "(" _ selector:selector _ ")" { return selector;