Class: Ibex::IR::Production

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

Overview

A normalized BNF production using symbol ids.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, lhs:, rhs:, action:, precedence_override:, origin:, documentation: nil, expansion: nil, node: nil) ⇒ Production

Returns a new instance of Production.



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ibex/ir/grammar_ir.rb', line 117

def initialize(id:, lhs:, rhs:, action:, precedence_override:, origin:, documentation: nil, expansion: nil,
               node: nil)
  @id = id
  @lhs = lhs
  @rhs = IR.deep_freeze(rhs)
  @action = action
  @precedence_override = precedence_override
  @origin = IR.deep_freeze(origin)
  @documentation = documentation&.dup&.freeze
  @expansion = IR.deep_freeze(expansion)
  @node = IR.deep_freeze(node)
  freeze
end

Instance Attribute Details

#actionObject (readonly)

: Action?



107
108
109
# File 'lib/ibex/ir/grammar_ir.rb', line 107

def action
  @action
end

#documentationObject (readonly)

: String?



110
111
112
# File 'lib/ibex/ir/grammar_ir.rb', line 110

def documentation
  @documentation
end

#expansionObject (readonly)

: production_expansion?



111
112
113
# File 'lib/ibex/ir/grammar_ir.rb', line 111

def expansion
  @expansion
end

#idObject (readonly)

: Integer



104
105
106
# File 'lib/ibex/ir/grammar_ir.rb', line 104

def id
  @id
end

#lhsObject (readonly)

: Integer



105
106
107
# File 'lib/ibex/ir/grammar_ir.rb', line 105

def lhs
  @lhs
end

#nodeObject (readonly)

: node_annotation?



112
113
114
# File 'lib/ibex/ir/grammar_ir.rb', line 112

def node
  @node
end

#originObject (readonly)

: Hash[Symbol, Object?]



109
110
111
# File 'lib/ibex/ir/grammar_ir.rb', line 109

def origin
  @origin
end

#precedence_overrideObject (readonly)

: Integer?



108
109
110
# File 'lib/ibex/ir/grammar_ir.rb', line 108

def precedence_override
  @precedence_override
end

#rhsObject (readonly)

: Array



106
107
108
# File 'lib/ibex/ir/grammar_ir.rb', line 106

def rhs
  @rhs
end

Instance Method Details

#to_hObject



132
133
134
135
136
137
138
139
# File 'lib/ibex/ir/grammar_ir.rb', line 132

def to_h
  value = { id: @id, lhs: @lhs, rhs: @rhs, action: @action&.to_h,
            prec_override: @precedence_override, origin: @origin } #: Hash[Symbol, Object?]
  value[:doc] = @documentation
  value[:expansion] = @expansion
  value[:node] = @node if @node
  value
end