Class: Ibex::Codegen::ActionSource
- Inherits:
-
Object
- Object
- Ibex::Codegen::ActionSource
- Includes:
- RubyAST
- Defined in:
- lib/ibex/codegen/action_source.rb
Overview
Generates static-check-only Ruby containing semantic action methods.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(automaton, omit_action_call: nil) ⇒ ActionSource
constructor
A new instance of ActionSource.
Constructor Details
#initialize(automaton, omit_action_call: nil) ⇒ ActionSource
Returns a new instance of ActionSource.
19 20 21 22 23 24 |
# File 'lib/ibex/codegen/action_source.rb', line 19 def initialize(automaton, omit_action_call: nil) @automaton = automaton @grammar = automaton.grammar @omit_action_call = omit_action_call.nil? ? @grammar.[:omit_action_call] : omit_action_call @method_source = ActionMethodSource.new(@grammar) end |
Instance Method Details
#generate ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ibex/codegen/action_source.rb', line 27 def generate lines = [ "# frozen_string_literal: true", "# Generated by Ibex #{grammar_digest_comment}.", "# Static-check-only semantic action shadow source.", "# DO NOT LOAD OR EXECUTE: runtime wiring and user code are intentionally absent.", "" ] modules, class_name = class_parts modules.each { |name| lines << "module #{name}" } lines << "class #{class_name}" append_ast(lines) append_value_printers(lines) append_actions(lines) lines << "end" modules.reverse_each { lines << "end" } "#{lines.join("\n")}\n" end |