       i += 1
     throw new Error "SyntaxError: Unterminated ${levels.pop()[0]} starting on line ${@line + 1}" if levels.length
     return false if i is 0
-    return @chunk.substring(0, i)
+    return str.substring(0, i)
+
+  # Matches a balanced string within the token's contents.
+  balanced_token: (delimited...) ->
+    @balanced_string @chunk, delimited...
 
   # Matches and conumes comments.
   comment_token: ->


  # Matches a balanced group such as a single or double-quoted string. Pass in
  # a series of delimiters, all of which must be balanced correctly within the
  # token's contents.
  balanced_token: (delimited...) ->
    levels: []
    i: 0
    while i < @chunk.length
      for pair in delimited
        [open, close]: pair
        if levels.length and starts @chunk, '\\', i
          i += 1
          break
        else if levels.length and starts(@chunk, close, i) and levels[levels.length - 1] is pair
          levels.pop()
          i += close.length - 1
          i += 1 unless levels.length
          break
        else if starts @chunk, open, i
          levels.push(pair)
          i += open.length - 1
          break

      lexer:  new Lexer()
      tokens: []
      quote:  str.substring(0, 1)
      i:      1
      last_i: i
      while i < str.length - 1
        if starts str, '\\', i
          i += 1
        else
          match: str.substring(i).match INTERPOLATION
          if match
            [group, interp]: match
            interp: "this.${ interp.substring(1) }" if starts interp, '@'
            tokens.push ['STRING', "$quote${ str.substring(last_i, i) }$quote"] if last_i < i
            tokens.push ['IDENTIFIER', interp]
            i += group.length - 1
            last_i: i + 1
          else
            expression: @balanced_string str.substring(i), ['${', '}']
            if expression and expression.length > 3
              inner: expression.substring(2, expression.length - 1)
              nested: lexer.tokenize "($inner)", {rewrite: no, line: @line}
              nested.pop()
              tokens.push ['STRING', "$quote${ str.substring(last_i, i) }$quote"] if last_i < i
              tokens.push ['TOKENS', nested]
              i += expression.length - 1
              last_i: i + 1
        i += 1
      tokens.push ['STRING', "$quote${ str.substring(last_i, i) }$quote"] if last_i < i and last_i < str.length - 1
      if tokens.length > 1
        for i in [tokens.length - 1..1]
          [prev, tok]: [tokens[i - 1], tokens[i]]
