lib/patternmatching/pattern.rb in patternmatching-0.2.3 vs lib/patternmatching/pattern.rb in patternmatching-0.2.4

- old
+ new

@@ -21,41 +21,13 @@ # seems something do ... end def something proc {_} end end + include DSL_INSIDE - # Domain Specific Language style methods for outside - module DSL_OUTSIDE - include DSL_INSIDE - #Build structured data - #=== Usage - # build {[foo(bar, 100), foo(buzz, "abc")]} - def build(&block) - NodeBuilder.new.instance_eval(&block) - end - - #Build structured data - #=== Usage - # PatternMatching.build {[foo(bar, 100), foo(buzz, "abc")]} - def self.build(&block) - NodeBuilder.new.instance_eval(&block) - end - - #Do pattern matching - #===Usage - # make TARGET do - # seems as {PATTERN_1} do ACTION_1 end - # seems as {PATTERN_2} do ACTION_2 end - # seems something do ACTION_DEFAULT end - # end - def make(target, &block) - patterns = [] - PatternFragments.new(patterns).instance_eval(&block) - MatchExec.exec_as(target, patterns, self) - end - + module DSL_MODULE #Define method as partial style #=== Usage # func(NAME).seems as {PATTERN_1} do ACTION_1 end # func(NAME).seems as {PATTERN_2} do ACTION_2 end # func(NAME).seems something do ACTION_DEFAULT end @@ -83,10 +55,36 @@ fragments.instance_eval(&block) end fragments end end + include DSL_MODULE + + # Domain Specific Language style methods for outside + module DSL_OUTSIDE + #Build structured data + #=== Usage + # build {[foo(bar, 100), foo(buzz, "abc")]} + def build(&block) + NodeBuilder.new.instance_eval(&block) + end + + #Do pattern matching + #===Usage + # make TARGET do + # seems as {PATTERN_1} do ACTION_1 end + # seems as {PATTERN_2} do ACTION_2 end + # seems something do ACTION_DEFAULT end + # end + def make(target, &block) + patterns = [] + PatternFragments.new(patterns).instance_eval(&block) + MatchExec.exec_as(target, patterns, self) + end + + end include DSL_OUTSIDE + extend DSL_OUTSIDE #Class for structured data/patterns class Node def initialize(name, children) @name = name