 
 # Import the helpers we need.
 {include}: helpers
+
+# Helper method to check if the given stream of tokens matches the exit conditions
+exits: (prev, token, post, cond) ->
+  length: 0
+  match:  0
+  args:   {prev, token, post}
+  for k, v of args when k in cond
+    length: + 1
+    for pair in cond[k]
+      match: + 1 if v[0] is pair[0] and v[1] is pair[1]
+  return match is length
 
 # The **Rewriter** class is used by the [Lexer](lexer.html), directly against
 # its internal array of tokens.

      @tokens.splice i, 1
      return 0

  # Ensure that all listed pairs of tokens are correctly balanced throughout
  # the course of the token stream.
  ensure_balance: (pairs) ->

    @close_open_calls_and_indexes()
    @add_implicit_indentation()
    @add_implicit_parentheses()
    @rewrite_object_keys()
    @ensure_balance BALANCED_PAIRS
    @rewrite_closing_parens()
    @tokens
