 
     injected = false
     patterns = @getIncludedPatterns(baseGrammar)
-    scopes = scopesFromStack(ruleStack)
-    for injection in @injections
-      if injection.matcher.matches(scopes)
-        patterns.push(injection.patterns...)
-        injected = true
+    @injections?.getPatterns(ruleStack, patterns)
 
     scanner = @createScanner(patterns, firstLine, position)
     unless scanner.anchored or injected

    for name, data of repository
      data = {patterns: [data], tempName: name} if data.begin? or data.match?
      @repository[name] = new Rule(this, data)

  parseInjections: (injections={}) ->
    parsedInjections = []
    for injectionKey, injectionValue of injections
      continue unless injectionValue?.patterns?.length > 0
      injectionPatterns = []
      for pattern in injectionValue.patterns
        injectionPatterns.push(new Pattern(this, pattern))
      parsedInjections.push
        patterns: injectionPatterns
        matcher: new TextMateScopeSelector(injectionKey)
    parsedInjections

  getScore: (path, contents) ->
    contents = fsUtils.read(path) if not contents? and fsUtils.isFile(path)

  createEndPattern: null
  anchorPosition: -1

  constructor: (@grammar, {@scopeName, patterns, @injections, @endPattern}) ->
    patterns ?= []
    @patterns = patterns.map (pattern) => new Pattern(grammar, pattern)
    @patterns.unshift(@endPattern) if @endPattern and !@endPattern.hasBackReferences
    @scannersByBaseGrammarName = {}
