Parent

Class/Module Index [+]

Quicksearch

RGen::Util::PatternMatcher

A PatternMatcher can be used to find, insert and remove patterns on a given model.

A pattern is specified by means of a block passed to the add_pattern method. The block must take an Environment as first parameter and at least one model element as connection point as further parameter. The pattern matches if it can be found in a given environment and connected to the given connection point elements.

Attributes

debug[RW]

Public Class Methods

new() click to toggle source
# File lib/rgen/util/pattern_matcher.rb, line 17
def initialize
  @patterns = {} 
  @insert_mode = false
  @debug = false
end

Public Instance Methods

add_pattern(name, &block) click to toggle source
# File lib/rgen/util/pattern_matcher.rb, line 23
def add_pattern(name, &block)
  raise "a pattern needs at least 2 block parameters: " + 
    "an RGen environment and a model element as connection point"        unless block.arity >= 2
  @patterns[name] = block
end
find_pattern(env, name, *connection_points) click to toggle source
# File lib/rgen/util/pattern_matcher.rb, line 30
def find_pattern(env, name, *connection_points)
  match = find_pattern_internal(env, name, *connection_points)
end
insert_pattern(env, name, *connection_points) click to toggle source
# File lib/rgen/util/pattern_matcher.rb, line 34
def insert_pattern(env, name, *connection_points)
  @insert_mode = true
  root = evaluate_pattern(name, env, connection_points)
  @insert_mode = false
  root
end
lazy(&block) click to toggle source
# File lib/rgen/util/pattern_matcher.rb, line 54
def lazy(&block)
  if @insert_mode
    block.call
  else
    Lazy.new(&block)
  end
end
remove_pattern(env, name, *connection_points) click to toggle source
# File lib/rgen/util/pattern_matcher.rb, line 41
def remove_pattern(env, name, *connection_points)
  match = find_pattern_internal(env, name, *connection_points)
  if match
    match.elements.each do |e|
      disconnect_element(e)
      env.delete(e)
    end
    match
  else
    nil
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.