Class: LL::CodeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ll/code_generator.rb

Overview

The CodeGenerator class takes a CompiledConfiguration instance and turns it into a block of Ruby source code that can be used as an actual LL(1) parser.

Constant Summary collapse

TEMPLATE =

The ERB template to use for code generation.

File.expand_path('../driver_template.erb', __FILE__)

Instance Method Summary collapse

Instance Method Details

#generate(config, add_requires = true) ⇒ String



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ll/code_generator.rb', line 20

def generate(config, add_requires = true)
  context = ERBContext.new(
    :config       => config,
    :add_requires => add_requires
  )

  template = File.read(TEMPLATE)
  erb      = ERB.new(template, nil, '-').result(context.get_binding)

  return erb
end