Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add child combinator for scope selector #125

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/scope-selector-matchers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,33 @@ class PathMatcher
constructor: (prefix, first, others) ->
@prefix = prefix?[0]
@matchers = [first]
@matchers.push(matcher[1]) for matcher in others
@children = [false]
for matcher in others
@children.push(matcher[1]?)
@matchers.push(matcher[3])

matches: (scopes) ->
index = 0
matcher = @matchers[index]
for scope in scopes
matcher = @matchers[++index] if matcher.matches(scope)
if matcher.matches(scope)
matcher = @matchers[++index]
else
return false if @children[index]
return true unless matcher?
false

getPrefix: (scopes) -> @prefix if @matches(scopes)

toCssSelector: ->
@matchers.map((matcher) -> matcher.toCssSelector()).join(' ')
@matchers.map((matcher, index) =>
(if @children[index] then "> " else "") + matcher.toCssSelector()
).join(' ')

toCssSyntaxSelector: ->
@matchers.map((matcher) -> matcher.toCssSyntaxSelector()).join(' ')
@matchers.map((matcher, index) =>
(if @children[index] then "> " else "") + matcher.toCssSyntaxSelector()
).join(' ')

class OrMatcher
constructor: (@left, @right) ->
Expand Down
2 changes: 1 addition & 1 deletion src/scope-selector-parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ scope
}

path
= prefix:([LRB]":")? first:scope others:(_ scope)* {
= prefix:([LRB]":")? first:scope others:(_ ">"? _ scope)* {
return new matchers.PathMatcher(prefix, first, others);
}

Expand Down