Parent

RText::Instantiator

Constants

InstantiatorProblem

A problem found during instantiation if the file is not known, it will be nil

Public Class Methods

new(language) click to toggle source

Creates an instantiator for RText::Language language

# File lib/rtext/instantiator.rb, line 15
def initialize(language)
  @lang = language
end

Public Instance Methods

instantiate(str, options={}) click to toggle source

instantiate str, options include:

:env
  environment to which model elements will be added

:problems
  an array to which problems will be appended

:unresolved_refs
  an array to which unresolved references will be appended

:root_elements
  an array which will hold the root elements

:file_name
  name of the file being instantiated, will be set on model elements

:fragment_ref
  object which references the fragment being instantiated, will be set on model elements 

:on_progress
  a proc which is called twice for each model element: 
  when the command token is recognized and when the element is instantiated
# File lib/rtext/instantiator.rb, line 43
def instantiate(str, options={})
  @line_numbers = {}
  @env = options[:env]
  @problems = options[:problems] || []
  @unresolved_refs = options[:unresolved_refs]
  @root_elements = options[:root_elements] || []
  @file_name = options[:file_name]
  @fragment_ref = options[:fragment_ref]
  @on_progress_proc = options[:on_progress]
  @context_class_stack = []
  parser = Parser.new(@lang.reference_regexp)
  @root_elements.clear
  parser_problems = []
  parser.parse(str, 
    :descent_visitor => lambda do |command|
      clazz = @lang.class_by_command(command.value, @context_class_stack.last)
      # in case no class is found, nil will be pushed, this will case the next command
      # lookup to act as if called from toplevel
      @context_class_stack.push(clazz)
    end,
    :ascent_visitor => lambda do |*args|
      if args[0]
        element =create_element(*args)
        @context_class_stack.pop
        element
      else
        unassociated_comments(args[3])
      end
    end,
    :on_command_token => @on_progress_proc && lambda do
      @on_progress_proc.call
    end,
    :problems => parser_problems)
  parser_problems.each do |p|
    problem(p.message, p.line)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.