Class: Antelope::Generator::Ruby

Inherits:
Antelope::Generator show all
Defined in:
lib/antelope/generator/ruby.rb

Overview

Generates a ruby parser.

Instance Attribute Summary

Attributes inherited from Antelope::Generator

#file, #grammar, #mods

Instance Method Summary collapse

Methods inherited from Antelope::Generator

#initialize, source_root, #template

Constructor Details

This class inherits a constructor from Antelope::Generator

Instance Method Details

#generatevoid

This method returns an undefined value.

Actually performs the generation. Takes the template from ruby.erb and outputs it to <file>_parser.rb.



50
51
52
53
54
# File 'lib/antelope/generator/ruby.rb', line 50

def generate
  template "ruby.erb", "#{file}_parser.rb" do |body|
    sprintf(grammar.compiler.body, :write => body)
  end
end

#generate_action_tableString

Creates an action table for the parser.

Returns:

  • (String)


12
13
14
15
16
# File 'lib/antelope/generator/ruby.rb', line 12

def generate_action_table
  out = ""
  PP.pp(mods[:tableizer].table, out)
  out
end

#generate_productions_listString

Outputs an array of all of the productions.

Returns:

  • (String)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/antelope/generator/ruby.rb', line 21

def generate_productions_list
  out = "["

  grammar.all_productions.each do |production|
    out                              <<
      "["                            <<
      production.label.name.inspect  <<
      ", "                           <<
      production.items.size.inspect  <<
      ", "

    block = if production.block.empty?
      "proc {}"
    else
      "proc #{production.block}"
    end

    out << block << "],\n"
  end

  out.chomp!(",\n")

  out << "]"
end