Module: Ibex::Codegen::SymbolLabels

Defined in:
lib/ibex/codegen/symbol_labels.rb,
sig/ibex/codegen/symbol_labels.rbs

Overview

Builds human-facing symbol labels without changing Grammar IR identities.

Class Method Summary collapse

Class Method Details

.build(grammar) ⇒ Hash[Integer, String]

RBS:

  • (IR::Grammar grammar) -> Hash[Integer, String]

Parameters:

Returns:

  • (Hash[Integer, String])


8
9
10
11
12
13
14
15
# File 'lib/ibex/codegen/symbol_labels.rb', line 8

def self.build(grammar)
  labels = grammar.symbols.to_h { |symbol| [symbol.id, symbol.display_name || symbol.name] }
  grammar.productions.each do |production|
    expression = production.origin[:expression]
    labels[production.lhs] = expression if expression.is_a?(String)
  end
  labels
end