Sha256: b081cffd489a52bb112d75a21c0ab06c9a5a04088ad78ee41791d3879244a37a

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

module Pione
  module Lang
    # Piece is a base class for all elements of sequence. You cannot write it
    # directly in PIONE language because pieces are not included in expressions.
    class Piece < StructX
      include Util::Positionable
      immutable true

      # Declare the type name of piece.
      def self.piece_type_name(name=nil)
        name ? @piece_type_name = name : @piece_type_name
      end

      forward :class, :piece_type_name

      def eval(env)
        return self
      end

      # Convert to text string.
      def textize
        args = to_h.map do |key, val|
          "%s=%s" % [key, val.kind_of?(Piece) ? val.textize : val.to_s]
        end.join(", ")
        "#%s{%s}" % [piece_type_name, args]
      end
    end

    # SimplePiece is a piece of sequence that has single value elements.
    class SimplePiece < Piece
      member :value

      def textize
        "#%s{value=%s}" % [piece_type_name, value.textize]
      end

      def inspect
        "#%s{value=%s}" % [piece_type_name, value.to_s]
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pione-0.5.0 lib/pione/lang/piece.rb
pione-0.5.0.alpha.2 lib/pione/lang/piece.rb
pione-0.5.0.alpha.1 lib/pione/lang/piece.rb
pione-0.4.2 lib/pione/lang/piece.rb
pione-0.4.1 lib/pione/lang/piece.rb
pione-0.4.0 lib/pione/lang/piece.rb
pione-0.3.2 lib/pione/lang/piece.rb
pione-0.3.1 lib/pione/lang/piece.rb
pione-0.3.0 lib/pione/lang/piece.rb