Class: Ibex::Codegen::RBS
- Inherits:
-
Object
- Object
- Ibex::Codegen::RBS
- Defined in:
- lib/ibex/codegen/rbs.rb
Overview
Generates an RBS declaration for the public surface of a generated parser. rubocop:disable Metrics/ClassLength -- one generator owns the complete parser signature.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(automaton, superclass: nil, omit_action_call: nil) ⇒ RBS
constructor
A new instance of RBS.
Constructor Details
#initialize(automaton, superclass: nil, omit_action_call: nil) ⇒ RBS
Returns a new instance of RBS.
18 19 20 21 22 23 24 |
# File 'lib/ibex/codegen/rbs.rb', line 18 def initialize(automaton, superclass: nil, omit_action_call: nil) @automaton = automaton @grammar = automaton.grammar @superclass = superclass || @grammar.superclass || "Ibex::Runtime::Parser" @omit_action_call = omit_action_call.nil? ? @grammar.[:omit_action_call] : omit_action_call @generated_action_abi = GeneratedActionABI::Cache.new end |
Instance Method Details
#generate ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ibex/codegen/rbs.rb', line 27 def generate lines = ["# Generated by Ibex #{grammar_digest_comment}", ""] modules, class_name = class_parts modules.each { |name| lines << "module #{name}" } lines << "class #{class_name} < #{@superclass}" append_ast_contract(lines) append_syntax_contract(lines) append_contract(lines) append_lexer_contract(lines) append_value_printer_signatures(lines) append_actions(lines) lines << "end" modules.reverse_each { lines << "end" } "#{lines.join("\n")}\n" end |