Sha256: 55a5e16160a4d58ff05bd555b19626a3b31a8929f12e906ae60d9dcc896eb2ee

Contents?: true

Size: 899 Bytes

Versions: 1

Compression:

Stored size: 899 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Carbon
  module Compiler
    class Parser
      module Statements
        # Parses a match statement.
        module Match
        protected

          # TODO: Fix

          def parse_statement_match
            expect :match
            expect :"("
            source = parse_expression
            expect :")"
            expect :do
            children = []
            children << parse_match_element until peek? :end
            expect :end

            elements = Node.new(:statement_match_elements, children)
            Node.new(:statement_match, [source, elements])
          end

          def parse_match_element
            pattern = parse_expression
            expect :"=>"
            body = parse_statement

            Node.new(:statement_match_element, [pattern, body])
          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/statements/match.rb