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