     else
       [this]
 
-  compileRegex: ->
-    @pushRule?.compileRegex()
-
   getNextMatch: (line, position) ->
     if @include
       rule = @grammar.ruleForInclude(@include)

    @patterns = []
    @patterns.push(@endPattern) if @endPattern
    @patterns.push((patterns.map (pattern) => new Pattern(grammar, pattern))...)

  compileRegex: ->
    regexComponents = []
    @patternsByCaptureIndex = {}
    currentCaptureIndex = 1
    for pattern in @getAllPatterns()
      regexComponents.push(pattern.regex.source)
      @patternsByCaptureIndex[currentCaptureIndex] = pattern
      currentCaptureIndex += 1 + pattern.regex.getCaptureCount()
    @regex = new OnigRegExp('(' + regexComponents.join(')|(') + ')')

    pattern.compileRegex() for pattern in @patterns

  getAllPatterns: (included=[]) ->
    return [] if _.include(included, this)


    for name, data of repository
      @repository[name] = new Rule(this, data)

  getLineTokens: (line, stack=[@initialRule]) ->
    stack = new Array(stack...)
