class Pione::Lang::Sequence

Sequence is a base class for all expressions.

Public Class Methods

index_type(env) click to toggle source

Set the index type.

# File lib/pione/lang/sequence.rb, line 38
def index_type(env)
  @index_type
end
inherited(subclass) click to toggle source
# File lib/pione/lang/sequence.rb, line 22
def inherited(subclass)
  members.each {|member_name| subclass.member(member_name, default: default_values[member_name])}
  subclass.immutable true
  subclass.set_index_type(index_type(nil))
end
piece_class(klass) click to toggle source

Get/set piece class.

# File lib/pione/lang/sequence.rb, line 29
def piece_class(klass)
  (@piece_classes ||= []) << klass
end
piece_classes() click to toggle source
# File lib/pione/lang/sequence.rb, line 33
def piece_classes
  @piece_classes ||= []
end
set_index_type(type) click to toggle source

Set the index type.

# File lib/pione/lang/sequence.rb, line 43
def set_index_type(type)
  @index_type = type
end
void() click to toggle source

Make a void sequence.

# File lib/pione/lang/sequence.rb, line 49
def Sequence.void
  Sequence.new([])
end

Public Instance Methods

+(other)
Alias for: concat
assertive?() click to toggle source

Return true if the sequence is assertive about attributes.

# File lib/pione/lang/sequence.rb, line 69
def assertive?
  true
end
attribute() click to toggle source
# File lib/pione/lang/sequence.rb, line 73
def attribute
  members - [:pieces]
end
concat(other) click to toggle source

Concatenate self and another sequence. If self and another are assertive, raise SequenceAttributeError exception when the attributes are different.

@param other [Sequence]

other sequence

@return [Sequence]

a new sequence that have members of self and other
# File lib/pione/lang/sequence.rb, line 85
def concat(other)
  if assertive? and other.assertive?
    raise SequenceAttributeError.new(other) unless attribute == other.attribute
  end
  attr = not(other.assertive?) ? @attribute : other.attribute
  set(pieces: pieces + other.pieces)
end
Also aliased as: +
each() { |set(pieces: [e])| ... } click to toggle source

Iterate each elements.

@return [Enumerator]

return an enumerator if the block is not given
# File lib/pione/lang/sequence.rb, line 103
def each
  if block_given?
    pieces.each {|e| yield set(pieces: [e])}
  else
    to_enum(:each)
  end
end
eval(env) click to toggle source
# File lib/pione/lang/sequence.rb, line 111
def eval(env)
  set(pieces: pieces.map{|piece| piece.eval(env)})
end
push(piece) click to toggle source

Push the piece to the sequecence.

# File lib/pione/lang/sequence.rb, line 95
def push(piece)
  set(pieces: pieces + [piece])
end
set_annotation_type(type) click to toggle source

Set the annotation type to the sequence.

# File lib/pione/lang/sequence.rb, line 127
def set_annotation_type(type)
  set(annotation_type: type)
end
update_pieces(data) click to toggle source

Update pieces with the data.

# File lib/pione/lang/sequence.rb, line 116
def update_pieces(data)
  _pieces = pieces.map do |piece|
    _data = data.inject({}) do |tbl, (key, val)|
      tbl.tap {|x| x[key] = val.kind_of?(Proc) ? val.call(piece) : val}
    end
    piece.set(_data)
  end
  set(pieces: _pieces)
end
void?() click to toggle source

Return true if the sequence is void.

@return [Boolean]

true if the sequence is void
# File lib/pione/lang/sequence.rb, line 64
def void?
  self.class == Sequence and empty?
end