   getMaxTokensPerLine: ->
     @maxTokensPerLine
 
+class Injections
+  @injections: null
+
+  constructor: (grammar, injections={}) ->
+    @injections = []
+    for selector, values of injections
+      continue unless values?.patterns?.length > 0
+      patterns = []
+      for pattern in values.patterns
+        patterns.push(new Pattern(grammar, pattern))
+      @injections.push
+        selector: new TextMateScopeSelector(selector)
+        patterns: patterns
+
+  getPatterns: (ruleStack, patterns) ->
+    if @injections.length > 0
+      scopes = scopesFromStack(ruleStack)
+      for injection in @injections
+        if injection.selector.matches(scopes)
+          patterns.push(injection.patterns...)
+    patterns
+
 class Rule
   grammar: null
   scopeName: null

  maxTokensPerLine: 100

  constructor: ({ @name, @fileTypes, @scopeName, injections, patterns, repository, @foldingStopMarker, firstLineMatch}) ->
    injections = @parseInjections(injections)
    @initialRule = new Rule(this, {@scopeName, patterns, injections})
    @repository = {}
    @firstLineRegex = new OnigRegExp(firstLineMatch) if firstLineMatch


    injected = false
    patterns = @getIncludedPatterns(baseGrammar)
    @injections?.getPatterns(ruleStack, patterns)

    scanner = @createScanner(patterns, firstLine, position)
    unless scanner.anchored or injected
