Class: Antelope::Generator::Ruby
- Defined in:
- lib/antelope/generator/ruby.rb
Overview
Generates a ruby parser.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#generate ⇒ void
Actually performs the generation.
-
#generate_action_table ⇒ String
Creates an action table for the parser.
-
#generate_productions_list ⇒ String
Outputs an array of all of the productions.
Methods inherited from Base
#initialize, #productions, register_as, source_root, #table, #template
Constructor Details
This class inherits a constructor from Antelope::Generator::Base
Instance Method Details
#generate ⇒ void
This method returns an undefined value.
Actually performs the generation. Takes the template from
ruby.erb and outputs it to <file>_parser.rb.
54 55 56 57 58 |
# File 'lib/antelope/generator/ruby.rb', line 54 def generate template "ruby.erb", "#{file}.rb" do |body| sprintf(grammar.compiler.body, :write => body) end end |
#generate_action_table ⇒ String
Creates an action table for the parser.
16 17 18 19 20 |
# File 'lib/antelope/generator/ruby.rb', line 16 def generate_action_table out = "" PP.pp(table, out) out end |
#generate_productions_list ⇒ String
Outputs an array of all of the productions.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/antelope/generator/ruby.rb', line 25 def generate_productions_list out = "[" productions.each do |(label, size, block)| out << "[" << label.name.inspect << ", " << size.inspect << ", " block = if block.empty? "proc { |_| _ }" else "proc #{production.block}" end out << block << "],\n" end out.chomp!(",\n") out << "]" end |