class SyntaxTree::Parser

def on_begin(bodystmt)

on_begin: (untyped bodystmt) -> Begin | PinnedBegin
:call-seq:
def on_begin(bodystmt)
  pin = find_operator(:^)
  if pin && pin.location.start_char < bodystmt.location.start_char
    tokens.delete(pin)
    consume_token(LParen)
    rparen = consume_token(RParen)
    location = pin.location.to(rparen.location)
    PinnedBegin.new(statement: bodystmt, location: location)
  else
    keyword = consume_keyword(:begin)
    end_location =
      if bodystmt.else_clause
        bodystmt.location
      else
        consume_keyword(:end).location
      end
    bodystmt.bind(
      self,
      find_next_statement_start(keyword.location.end_char),
      keyword.location.end_column,
      end_location.end_char,
      end_location.end_column
    )
    location = keyword.location.to(end_location)
    Begin.new(bodystmt: bodystmt, location: location)
  end
end