     @repository = null
     @initialRule = null
 
+    if injectionSelector?
+      @injectionSelector = new ScopeSelector(injectionSelector)
+    else
+      @injectionSelector = null
+
+    if firstLineMatch
+      @firstLineRegex = new OnigRegExp(firstLineMatch)
+    else
+      @firstLineRegex = null
+
+    @fileTypes ?= []
+    @includedGrammarScopes = []
+
     @rawPatterns = patterns
     @rawRepository = repository
-
-    if injectionSelector?
-      @injectionSelector = new ScopeSelector(injectionSelector)
-    else
-      @injectionSelector = null
-
-    if firstLineMatch
-      @firstLineRegex = new OnigRegExp(firstLineMatch)
-    else
-      @firstLineRegex = null
-
-    @fileTypes ?= []
-    @includedGrammarScopes = []
-
-    if injections
-      recalculate = => @injections = new Injections(this, injections)
-      @registry.onDidAddGrammar recalculate
-      @registry.onDidUpdateGrammar recalculate
-      @registry.onDidRemoveGrammar recalculate
+    @rawInjections = injections
+
+    @updateRules()
 
   ###
   Section: Event Subscription

    @registration?.dispose()
    @registration = null

  clearRules: ->
    @initialRule = null
    @repository = null

  getInitialRule: ->
    @initialRule ?= @createRule({@scopeName, patterns: @rawPatterns})

  getRepository: ->
    @repository ?= do =>
      repository = {}
      for name, data of @rawRepository
        data = {patterns: [data], tempName: name} if data.begin? or data.match?
        repository[name] = @createRule(data)
      repository

  addIncludedGrammarScope: (scope) ->
    @includedGrammarScopes.push(scope) unless _.include(@includedGrammarScopes, scope)

  grammarUpdated: (scopeName) ->
    return false unless _.include(@includedGrammarScopes, scopeName)
    @clearRules()
    @registry.grammarUpdated(@scopeName)
    @emit 'grammar-updated' if Grim.includeDeprecatedAPIs
    @emitter.emit 'did-update'

          openScopeTags.push(@registry.startIdForScope(contentScopeName)) if contentScopeName
    else
      openScopeTags = [] if compatibilityMode
      {scopeName, contentScopeName} = @initialRule
      ruleStack = [{rule: @initialRule, scopeName, contentScopeName}]
      tags.push(@startIdForScope(@initialRule.scopeName)) if scopeName
      tags.push(@startIdForScope(@initialRule.contentScopeName)) if contentScopeName

    initialRuleStackLength = ruleStack.length
    position = 0
