mirror of
https://github.com/atom/atom.git
synced 2026-02-17 01:51:54 -05:00
31 lines
849 B
CoffeeScript
31 lines
849 B
CoffeeScript
PEG = require 'pegjs'
|
|
fsUtils = require 'fs-utils'
|
|
|
|
# Public: Test a stack of scopes to see if they match a scope selector.
|
|
module.exports =
|
|
class TextMateScopeSelector
|
|
@parser: null
|
|
|
|
@createParser: ->
|
|
unless TextMateScopeSelector.parser?
|
|
patternPath = require.resolve('text-mate-scope-selector-pattern.pegjs')
|
|
TextMateScopeSelector.parser = PEG.buildParser(fsUtils.read(patternPath))
|
|
TextMateScopeSelector.parser
|
|
|
|
source: null
|
|
matcher: null
|
|
|
|
# Public: Create a new scope selector.
|
|
#
|
|
# source - A {String} to parse as a scope selector.
|
|
constructor: (@source) ->
|
|
@matcher = TextMateScopeSelector.createParser().parse(@source)
|
|
|
|
# Public: Check if this scope selector matches the scopes.
|
|
#
|
|
# scopes - An {Array} of {String}s.
|
|
#
|
|
# Return a {Boolean}.
|
|
matches: (scopes) ->
|
|
@matcher.matches(scopes)
|