Support space-separated scopes in selector parser

This commit is contained in:
Kevin Sawicki 2013-04-17 17:28:49 -07:00
parent 3e5448b698
commit beeaa01d22
2 changed files with 25 additions and 1 deletions

View File

@ -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()

View File

@ -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;