Support scope selectors with dashes in segments

Previously dashes were only interpreted as negation which
wasn't correct.

Segments should be able to contain a dash as long as it isn't at
the very beginning of the segment.
This commit is contained in:
Kevin Sawicki
2013-08-06 12:18:36 -07:00
parent 8b55c4981d
commit da7cbeddc7
3 changed files with 9 additions and 2 deletions

View File

@@ -13,6 +13,8 @@ describe "TextMateScopeSelector", ->
expect(new TextMateScopeSelector('a').matches(['a.b'])).toBeTruthy()
expect(new TextMateScopeSelector('a.b').matches(['a.b.c'])).toBeTruthy()
expect(new TextMateScopeSelector('a').matches(['abc'])).toBeFalsy()
expect(new TextMateScopeSelector('a.b-c').matches(['a.b-c.d'])).toBeTruthy()
expect(new TextMateScopeSelector('a.b').matches(['a.b-d'])).toBeFalsy()
it "matches disjunction", ->
expect(new TextMateScopeSelector('a | b').matches(['b'])).toBeTruthy()
@@ -22,6 +24,9 @@ describe "TextMateScopeSelector", ->
it "matches negation", ->
expect(new TextMateScopeSelector('a - c').matches(['a', 'b'])).toBeTruthy()
expect(new TextMateScopeSelector('a-b').matches(['a', 'b'])).toBeFalsy()
expect(new TextMateScopeSelector('a -b').matches(['a', 'b'])).toBeFalsy()
expect(new TextMateScopeSelector('a -c').matches(['a', 'b'])).toBeTruthy()
expect(new TextMateScopeSelector('a-c').matches(['a', 'b'])).toBeFalsy()
it "matches conjunction", ->
expect(new TextMateScopeSelector('a & b').matches(['b', 'a'])).toBeTruthy()

View File

@@ -1,8 +1,10 @@
_ = require 'underscore'
### Internal ###
class SegmentMatcher
constructor: (segment) ->
@segment = segment.join('')
@segment = _.flatten(segment).join('')
matches: (scope) ->
scope is @segment

View File

@@ -7,7 +7,7 @@ start = _ selector:(selector) _ {
}
segment
= _ segment:[a-zA-Z0-9]+ _ {
= _ segment:([a-zA-Z0-9]+[a-zA-Z0-9-]*) _ {
return new matchers.SegmentMatcher(segment);
}