Sha256: 6dec229548b59aa7c10ec9fd2f42f3d790959047cd3c7f55a54cbef14334659e

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

module Antelope
  module Ace
    class Grammar

      # Defines a production.
      class Production < Struct.new(:label, :items, :block, :prec, :id)
        # @!attribute [rw] label
        #   The label (or left-hand side) of the production.  This
        #   should be a nonterminal.
        #
        #   @return [Symbol]
        # @!attribute [rw] items
        #   The body (or right-hand side) of the production.  This can
        #   be array of terminals and nonterminals.
        #
        #   @return [Array<Token>]
        # @!attribute [rw] block
        #   The block of code to be executed when the production's right
        #   hand side is reduced.
        #
        #   @return [String]
        # @!attribute [rw] prec
        #   The precedence declaration for the production.
        #
        #   @return [Ace::Precedence]
        # @!attribute [rw] id
        #   The ID of the production.  The starting production always
        #   has an ID of 0.
        #
        #   @return [Numeric]

        # Creates a new production from a hash.  The hash's keys
        # correspond to the attributes on this class.
        #
        # @param hash [Hash<(Symbol, Object)>]
        def self.from_hash(hash)
          new(hash[:label] || hash["label"],
              hash[:items] || hash["items"],
              hash[:block] || hash["block"],
              hash[:prec]  || hash["prec"],
              hash[:id]    || hash["id"])
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
antelope-0.1.1 lib/antelope/ace/grammar/production.rb
antelope-0.1.0 lib/antelope/ace/grammar/production.rb