class Crass::Parser

def discard_block(input)

deeply nested construct can't exhaust the Ruby stack.
(tracking nested blocks and functions with an explicit stack) so that a
exceeded. It iteratively consumes tokens up to the matching closing token
This is reached only when the configured maximum nesting depth is

`{`, `[`, `(`, or function token).
returns an `:error` node. Assumes `input.current` is the opening token (a
Discards an over-nested simple block or function without recursing, then
def discard_block(input)
  opening = input.current
  stack = [opening[:node] == :function ? :')' : BLOCK_END_TOKENS[opening[:node]]]
  tokens = [opening] # Non-standard. Used for serialization.
  tokens.concat(input.collect do
    until stack.empty?
      break unless token = input.consume
      case token[:node]
      when :'{', :'[', :'('
        stack.push(BLOCK_END_TOKENS[token[:node]])
      when :function
        stack.push(:')')
      when stack.last
        stack.pop
      end
    end
  end)
  create_node(:error, :value => 'maximum-depth-exceeded', :tokens => tokens)
end