lib/openwfe/expressions/raw_prog.rb in openwferu-0.9.13 vs lib/openwfe/expressions/raw_prog.rb in openwferu-0.9.14

- old
+ new

@@ -28,12 +28,10 @@ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. #++ # -# $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $ -# # # "made in Japan" # # John Mettraux at openwfe.org @@ -90,29 +88,20 @@ &block) end def self.method_missing (m, *args, &block) - #puts "__c_method_missing >>>#{m}<<<<" + @ccontext = Context.new() \ + if (not @ccontext) or @ccontext.discarded? - @ccontext = Context.new() unless @ccontext - ProcessDefinition.make_expression( @ccontext, OpenWFE::to_expression_name(m), ProcessDefinition.pack_args(args), &block) end - # - # This method has to be overriden in order to define - # a process definition. - # - def make - raise "make() implementation is missing, please provide one" - end - def self.make_expression (context, exp_name, params, &block) string_child = nil attributes = OpenWFE::SymbolHash.new @@ -167,10 +156,12 @@ # segment raw representation # def ProcessDefinition.do_make (instance=nil) context = if @ccontext + @ccontext.discard + # preventing further additions in case of reevaluation @ccontext elsif instance instance.make instance.context else @@ -194,13 +185,45 @@ top_expression.children = context.top_expressions top_expression end + # + # Parses the string to find the class name of the process definition + # and returns that class (instance). + # + def self.extract_class (ruby_proc_def_string) + + ruby_proc_def_string.each_line do |l| + + m = l.match " *class *([a-zA-Z0-9]*) *< .*ProcessDefinition" + return eval(m[1]) if m + end + + nil + end + + # + # Turns a String containing a ProcessDefinition ... + # + def self.eval_ruby_process_definition (code, safety_level=2) + + o = OpenWFE::eval_safely(code, safety_level) + + o = extract_class(code) \ + if (o == nil) or o.is_a?(SimpleExpRepresentation) + + return o.do_make \ + if o.is_a?(ProcessDefinition) or o.is_a?(Class) + + o + end + protected def ProcessDefinition.pack_args (args) + return args[0] if args.length == 1 a = {} args.each_with_index do |arg, index| if arg.is_a? Hash a = a.merge(arg) @@ -234,16 +257,23 @@ s.gsub("_", ".") end class Context - attr_accessor :parent_expression - attr_reader :top_expressions, :previous_parent_expressions + attr_accessor :parent_expression, :top_expressions + attr_reader :previous_parent_expressions def initialize @parent_expression = nil @top_expressions = [] @previous_parent_expressions = [] + end + + def discard + @discarded = true + end + def discarded? + (@discarded == true) end # # puts the current parent expression on top of the 'previous # parent expressions' stack, the current parent expression