# encoding: utf-8 # frozen_string_literal: true module Carbon module Compiler class Parser module Root # Parses a struct. module Struct protected def parse_struct start = expect :struct expect :do elements = [] elements << parse_struct_element until peek?(:end) stop = expect :end Node::Definition::Struct.new(elements, components: [start, stop]) end def parse_struct_element name = parse_name expect :":" type = parse_type expect :";" Node::Definition::Struct::Element.new([name, type]) end end end end end end