Class: Antelope::Generator::Ruby

Inherits:
Base
  • Object
show all
Defined in:
lib/antelope/generator/ruby.rb

Overview

Generates a ruby parser.

Instance Attribute Summary

Attributes inherited from Base

#file, #grammar, #mods

Instance Method Summary collapse

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

#generatevoid

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_tableString

Creates an action table for the parser.

Returns:

  • (String)


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_listString

Outputs an array of all of the productions.

Returns:

  • (String)


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