Sha256: 591235e6d4cf7e5a139b05d94dcd3433541831c0742e00bf5ef585bdbbca8eeb

Contents?: true

Size: 955 Bytes

Versions: 1

Compression:

Stored size: 955 Bytes

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carbon-compiler-0.2.0 lib/carbon/compiler/parser/root/trait.rb