Class: Stupidedi::Parser::Instruction
- Inherits:
-
Object
- Object
- Stupidedi::Parser::Instruction
- Includes:
- Inspect
- Defined in:
- lib/stupidedi/parser/instruction.rb
Instance Attribute Summary collapse
-
#drop_count ⇒ Integer
readonly
This controls the allowed order in which structures may occur, by indicating the number of instructions to remove from the beginning of the instruction table.
-
#pop_count ⇒ Integer
readonly
This indicates the number of levels to ascend and terminate within the tree before storing the segment.
-
#push ⇒ Zipper::AbstractCursor
readonly
This indicates that a child node should be added to the tree, which will then contain the segment.
-
#segment_id ⇒ Symbol
readonly
The segment identifier to which this Instruction applies.
-
#segment_use ⇒ Schema::SegmentUse
readonly
The segment use contains helpful information about the context of the segment within a definition tree (eg the parent structure's definition).
Instance Method Summary collapse
- #copy(changes = {}) ⇒ Instruction
- #hash
-
#initialize(segment_id, segment_use, pop, drop, push) ⇒ Instruction
constructor
A new instance of Instruction.
- #pretty_print(q)
Methods included from Inspect
Constructor Details
#initialize(segment_id, segment_use, pop, drop, push) ⇒ Instruction
Returns a new instance of Instruction.
53 54 55 56 |
# File 'lib/stupidedi/parser/instruction.rb', line 53 def initialize(segment_id, segment_use, pop, drop, push) @segment_id, @segment_use, @pop_count, @drop_count, @push = segment_id || segment_use.definition.id, segment_use, pop, drop, push end |
Instance Attribute Details
#drop_count ⇒ Integer (readonly)
This controls the allowed order in which structures may occur, by indicating the number of instructions to remove from the beginning of the instruction table.
Repeatable structures have a value that ensures that their instruction remains in the successor table.
Sibling structures that have the same position (as defined by their Schema::SegmentUse) will have equal drop_count values such that all of the sibling instructions remain in the successor table when any one of them is executed.
41 42 43 |
# File 'lib/stupidedi/parser/instruction.rb', line 41 def drop_count @drop_count end |
#pop_count ⇒ Integer (readonly)
This indicates the number of levels to ascend and terminate within the tree before storing the segment.
26 27 28 |
# File 'lib/stupidedi/parser/instruction.rb', line 26 def pop_count @pop_count end |
#push ⇒ Zipper::AbstractCursor (readonly)
This indicates that a child node should be added to the tree, which will then contain the segment.
When a segment indicates the start of a child structure, the class
indicated by this attribute is expected to respond to push
by
creating a new AbstractState.
51 52 53 |
# File 'lib/stupidedi/parser/instruction.rb', line 51 def push @push end |
#segment_id ⇒ Symbol (readonly)
The segment identifier to which this Stupidedi::Parser::Instruction applies
12 13 14 |
# File 'lib/stupidedi/parser/instruction.rb', line 12 def segment_id @segment_id end |
#segment_use ⇒ Schema::SegmentUse (readonly)
The segment use contains helpful information about the context of the segment within a definition tree (eg the parent structure's definition). It also enumerates the allowed values for segment qualifiers, which is used to minimize non-determinism.
20 21 22 |
# File 'lib/stupidedi/parser/instruction.rb', line 20 def segment_use @segment_use end |
Instance Method Details
#copy(changes = {}) ⇒ Instruction
63 64 65 66 67 68 69 70 |
# File 'lib/stupidedi/parser/instruction.rb', line 63 def copy(changes = {}) Instruction.new \ changes.fetch(:segment_id, @segment_id), changes.fetch(:segment_use, @segment_use), changes.fetch(:pop_count, @pop_count), changes.fetch(:drop_count, @drop_count), changes.fetch(:push, @push) end |
#hash
58 59 60 |
# File 'lib/stupidedi/parser/instruction.rb', line 58 def hash [Instruction, state].hash end |
#pretty_print(q)
This method returns an undefined value.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/stupidedi/parser/instruction.rb', line 73 def pretty_print(q) id = "% 3s" % @segment_id.to_s unless @segment_use.nil? width = 18 name = @segment_use.definition.name # Truncate the segment name to `width` characters if name.length > width - 2 id = id + ": #{name.slice(0, width - 2)}.." else id = id + ": #{name.ljust(width)}" end end q.text "Instruction[#{"% 3s" % id}]" q.group(6, "(", ")") do q.breakable "" unless @segment_use.nil? q.text "position: #{@segment_use.position}," q.breakable end q.text "pop: #{@pop_count}," q.breakable q.text "drop: #{@drop_count}" end end |