Module: Ibex::Codegen::RubyValuePrinters
- Included in:
- Ruby
- Defined in:
- lib/ibex/codegen/ruby_value_printers.rb,
sig/ibex/codegen/ruby_value_printers.rbs
Overview
Emits declarative value-printer tables and methods for Ruby parsers.
Instance Method Summary collapse
- #append_value_printer(lines, printer) ⇒ void
- #append_value_printer_table(lines, indent) ⇒ void
- #append_value_printers(lines) ⇒ void
- #value_printer_action_method_source ⇒ ActionMethodSource
Instance Method Details
#append_value_printer(lines, printer) ⇒ void
This method returns an undefined value.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ibex/codegen/ruby_value_printers.rb', line 35 def append_value_printer(lines, printer) symbol = @grammar.symbol(printer[:symbol]) || raise(Ibex::Error, "missing printer symbol #{printer[:symbol]}") source_builder = value_printer_action_method_source source = source_builder.value_printer_method_source(symbol.id, printer) if @line_convert location = printer[:loc] lines << " class_eval(#{source.dump}, #{location[:file].inspect}, #{location[:line]})" elsif source_builder.column_sensitive?(printer[:code]) lines << source else source.lines.each { |line| lines << " #{line.rstrip}" } end end |
#append_value_printer_table(lines, indent) ⇒ void
This method returns an undefined value.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ibex/codegen/ruby_value_printers.rb', line 15 def append_value_printer_table(lines, indent) return if @grammar.value_printers.empty? entries = @grammar.value_printers.map do |printer| symbol = @grammar.symbol(printer[:symbol]) || raise(Ibex::Error, "missing printer symbol #{printer[:symbol]}") "#{symbol.id} => :_ibex_value_printer_#{symbol.id}" end lines << "#{indent}VALUE_PRINTERS = { #{entries.join(', ')} }.freeze" end |
#append_value_printers(lines) ⇒ void
This method returns an undefined value.
27 28 29 30 31 32 |
# File 'lib/ibex/codegen/ruby_value_printers.rb', line 27 def append_value_printers(lines) @grammar.value_printers.each do |printer| append_value_printer(lines, printer) lines << "" end end |
#value_printer_action_method_source ⇒ ActionMethodSource
51 52 53 |
# File 'lib/ibex/codegen/ruby_value_printers.rb', line 51 def value_printer_action_method_source @value_printer_action_method_source ||= ActionMethodSource.new(@grammar) end |