Class: Ibex::IR::Automaton

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/ir/automaton_ir.rb

Overview

Immutable LALR automaton and its source grammar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grammar:, states:, conflict_summary:, algorithm: "lalr1", grammar_digest: nil, entry_states: nil, entry_construction: "shared") ⇒ Automaton

Returns a new instance of Automaton.



87
88
89
90
91
92
93
# File 'lib/ibex/ir/automaton_ir.rb', line 87

def initialize(grammar:, states:, conflict_summary:, algorithm: "lalr1", grammar_digest: nil,
               entry_states: nil, entry_construction: "shared")
  initialize_current(
    grammar: grammar, states: states, conflict_summary: conflict_summary, algorithm: algorithm,
    grammar_digest: grammar_digest, entry_states: entry_states, entry_construction: entry_construction
  )
end

Instance Attribute Details

#algorithmObject (readonly)

: String



75
76
77
# File 'lib/ibex/ir/automaton_ir.rb', line 75

def algorithm
  @algorithm
end

#conflict_summaryObject (readonly)

: conflict_summary



80
81
82
# File 'lib/ibex/ir/automaton_ir.rb', line 80

def conflict_summary
  @conflict_summary
end

#entry_constructionObject (readonly)

: String



82
83
84
# File 'lib/ibex/ir/automaton_ir.rb', line 82

def entry_construction
  @entry_construction
end

#entry_statesObject (readonly)

: Hash[String, Integer]



79
80
81
# File 'lib/ibex/ir/automaton_ir.rb', line 79

def entry_states
  @entry_states
end

#grammarObject (readonly)

: Grammar



77
78
79
# File 'lib/ibex/ir/automaton_ir.rb', line 77

def grammar
  @grammar
end

#grammar_digestObject (readonly)

: String



76
77
78
# File 'lib/ibex/ir/automaton_ir.rb', line 76

def grammar_digest
  @grammar_digest
end

#schema_versionObject (readonly)

: Integer



81
82
83
# File 'lib/ibex/ir/automaton_ir.rb', line 81

def schema_version
  @schema_version
end

#statesObject (readonly)

: Array



78
79
80
# File 'lib/ibex/ir/automaton_ir.rb', line 78

def states
  @states
end

Instance Method Details

#to_hObject



124
125
126
127
128
129
130
131
132
# File 'lib/ibex/ir/automaton_ir.rb', line 124

def to_h
  value = { ibex_ir: "automaton", schema_version: @schema_version, algorithm: @algorithm,
            grammar_digest: @grammar_digest, grammar: @grammar.to_h,
            states: @states.map { |state| state.to_h(@grammar) },
            conflict_summary: @conflict_summary } #: Hash[Symbol, Object?]
  value[:entry_states] = @entry_states unless @entry_states == { @grammar.start => 0 }
  value[:entry_construction] = @entry_construction
  value
end