Sha256: e0e88a009714867ee9a7bc6c63dc39b99754b758a17c9da82fe0ee74ae6fa039

Contents?: true

Size: 745 Bytes

Versions: 1

Compression:

Stored size: 745 Bytes

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

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