# encoding: utf-8 # frozen_string_literal: true module Carbon module Compiler class Parser module Root # Parses a trait. module Trait protected # TODO: fix def parse_trait expect :trait expect :do elements = [] elements << parse_trait_element until peek?(:end) expect :end Node.new(:trait, [Node.new(:trait_elements, elements)]) end def parse_trait_element name = parse_name arguments = [] expect :"(" until peek? :")" arguments << parse_type break unless peek? :"," expect :"," end expect :")" expect :":" ret = parse_type expect :";" Node.new(:trait_element, [name, arguments, ret]) end end end end end end