     position = 0
 
     loop
-      scopes = _.pluck(stack, "scopeName")
+      scopes = scopesFromStack(stack)
 
       if line.length == 0
         tokens = [{value: "", scopes: scopes}]

      { match: @regex.getCaptureIndices(line, position), pattern: this }

  handleMatch: (stack, line, captureIndices) ->
    scopes = _.pluck(stack, "scopeName")
    scopes.push(@scopeName) if @scopeName and not @popRule

    if @captures

shiftCapture = (captureIndices) ->
  [captureIndices.shift(), captureIndices.shift(), captureIndices.shift()]

scopesFromStack = (stack) ->
  _.compact(_.pluck(stack, "scopeName"))

