Class: Ibex::IR::Production

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

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.

RBS:

  • (id: Integer, lhs: Integer, rhs: Array[Integer], action: Action?, precedence_override: Integer?, origin: Hash[Symbol, untyped], ?documentation: String?, ?expansion: production_expansion?, ?node: node_annotation?) -> void

Parameters:

  • id: (Integer)
  • lhs: (Integer)
  • rhs: (Array[Integer])
  • action: (Action, nil)
  • precedence_override: (Integer, nil)
  • origin: (Hash[Symbol, untyped])
  • documentation: (String, nil) (defaults to: nil)
  • expansion: (production_expansion, nil) (defaults to: nil)
  • node: (node_annotation, nil) (defaults to: nil)


109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ibex/ir/grammar_ir.rb', line 109

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

Instance Attribute Details

#actionAction? (readonly)

Signature:

  • Action?

Returns:



99
100
101
# File 'lib/ibex/ir/grammar_ir.rb', line 99

def action
  @action
end

#documentationString? (readonly)

Signature:

  • String?

Returns:

  • (String, nil)


102
103
104
# File 'lib/ibex/ir/grammar_ir.rb', line 102

def documentation
  @documentation
end

#expansionproduction_expansion? (readonly)

Signature:

  • production_expansion?

Returns:

  • (production_expansion, nil)


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

def expansion
  @expansion
end

#idInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


96
97
98
# File 'lib/ibex/ir/grammar_ir.rb', line 96

def id
  @id
end

#lhsInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


97
98
99
# File 'lib/ibex/ir/grammar_ir.rb', line 97

def lhs
  @lhs
end

#nodenode_annotation? (readonly)

Signature:

  • node_annotation?

Returns:

  • (node_annotation, nil)


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

def node
  @node
end

#originHash[Symbol, untyped] (readonly)

Signature:

  • Hash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


101
102
103
# File 'lib/ibex/ir/grammar_ir.rb', line 101

def origin
  @origin
end

#precedence_overrideInteger? (readonly)

Signature:

  • Integer?

Returns:

  • (Integer, nil)


100
101
102
# File 'lib/ibex/ir/grammar_ir.rb', line 100

def precedence_override
  @precedence_override
end

#rhsArray[Integer] (readonly)

Signature:

  • Array[Integer]

Returns:

  • (Array[Integer])


98
99
100
# File 'lib/ibex/ir/grammar_ir.rb', line 98

def rhs
  @rhs
end

Instance Method Details

#to_h(schema_version: SCHEMA_VERSION) ⇒ Hash[Symbol, untyped]

RBS:

  • (?schema_version: Integer) -> Hash[Symbol, untyped]

Parameters:

  • schema_version: (Integer) (defaults to: SCHEMA_VERSION)

Returns:

  • (Hash[Symbol, untyped])


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

def to_h(schema_version: SCHEMA_VERSION)
  value = { id: @id, lhs: @lhs, rhs: @rhs, action: @action&.to_h(schema_version: schema_version),
            prec_override: @precedence_override, origin: @origin } #: Hash[Symbol, untyped]
  if schema_version >= 2
    value[:doc] = @documentation
    value[:expansion] = @expansion
    value[:node] = @node if @node
  end
  value
end