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.
# 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
# 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
# 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
# File lib/rgen/util/pattern_matcher.rb, line 54 def lazy(&block) if @insert_mode block.call else Lazy.new(&block) end end
# 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
Generated with the Darkfish Rdoc Generator 2.