# encoding: utf-8 # frozen_string_literal: true module Carbon module Compiler class Parser module Statements # Parses a try statement. module Try protected def parse_statement_try expect :try body = parse_statement continued = parse_statement_try_continued Node::Statement::Try.new([body, continued]) end def parse_statement_try_continued case peek.type when :catch then parse_statement_try_catch when :finally then parse_statement_try_finally end end def parse_statement_try_catch expect :catch expect :"(" name = parse_name expect :":" type = parse_type expect :")" body = parse_statement follow = parse_statement_try_continued Node::Statement::Catch.new([name, type, body, follow]) end def parse_statement_try_finally expect :finally Node::Statement::Finally.new([parse_statement]) end end end end end end