Class: Stupidedi::Parser::ConstraintTable::Shallowest

Inherits:
Stupidedi::Parser::ConstraintTable show all
Defined in:
lib/stupidedi/parser/constraint_table.rb

Overview

Chooses the Instruction that pops the fewest number of states. For example, in the X222 837P an HL segment signals the start of a new 2000 loop, but may or may not begin a new Table 2 – the specifications aren’t actually clear. This rule will not create a new Table 2, but just add a new 2000 loop under the current one.

Instance Attribute Summary

Attributes inherited from Stupidedi::Parser::ConstraintTable

#instructions

Instance Method Summary collapse

Methods inherited from Stupidedi::Parser::ConstraintTable

build, #copy, #critique, #pretty_print

Constructor Details

#initialize(instructions) ⇒ Shallowest

Returns a new instance of Shallowest.



77
78
79
# File 'lib/stupidedi/parser/constraint_table.rb', line 77

def initialize(instructions)
  @instructions = instructions
end

Instance Method Details

#matches(segment_tok, strict, mode) ⇒ Array<Instruction>

Returns:



82
83
84
85
86
87
88
89
# File 'lib/stupidedi/parser/constraint_table.rb', line 82

def matches(segment_tok, strict, mode)
  @__matches ||= begin
    shallowest = @instructions.map(&:pop_count).min
    @instructions.select{|i| i.pop_count == shallowest }.tap do |xs|
      critique(segment_tok, xs.map(&:segment_use)) if strict
    end
  end
end