Module OpenWFE::DefParser
In: lib/openwfe/expool/parser.rb

A process definition parser.

Currently supports XML, Ruby process pdefinitions, YAML and JSON.

Methods

Public Class methods

in : a process pdefinition out : a tree [ name, attributes, children ]

[Source]

    # File lib/openwfe/expool/parser.rb, line 57
57:         def self.parse (pdef)
58: 
59:             return pdef \
60:                 if pdef.is_a?(Array)
61: 
62:             return parse_string(pdef) \
63:                 if pdef.is_a?(String)
64: 
65:             return pdef.do_make \
66:                 if pdef.is_a?(ProcessDefinition) or pdef.is_a?(Class)
67: 
68:             return pdef.to_a \
69:                 if pdef.is_a?(SimpleExpRepresentation)
70:                     # for legacy stuff
71: 
72:             raise "cannot handle pdefinition of class #{pdef.class.name}"
73:         end

[Source]

    # File lib/openwfe/expool/parser.rb, line 75
75:         def self.parse_string (pdef)
76: 
77:             pdef = pdef.strip
78: 
79:             return parse_xml(pdef) \
80:                 if pdef[0, 1] == "<"
81: 
82:             return YAML.load(s) \
83:                 if pdef.match /^--- ./
84: 
85:             #
86:             # else it's some ruby code to eval
87: 
88:             ProcessDefinition.eval_ruby_process_definition pdef
89:         end

The process definition is expressed as XML, turn that into an expression tree.

[Source]

     # File lib/openwfe/expool/parser.rb, line 95
 95:         def self.parse_xml (xml)
 96: 
 97:             xml = REXML::Document.new(xml) \
 98:                 if xml.is_a?(String)
 99: 
100:             xml = xml.root \
101:                 if xml.is_a?(REXML::Document)
102: 
103:             if xml.is_a?(REXML::Text)
104: 
105:                 s = xml.to_s.strip
106: 
107:                 return s if s.length > 0
108: 
109:                 return nil
110:             end
111: 
112:             return nil if xml.is_a?(REXML::Comment)
113: 
114:             # xml element thus...
115: 
116:             name = xml.name
117: 
118:             attributes = xml.attributes.inject({}) do |r, (k, v)|
119:                 r[k] = v
120:                 r
121:             end
122: 
123:             rep = [ name, attributes, [] ]
124: 
125:             xml.children.each do |c|
126: 
127:                 #r = if c.is_a?(REXML::Element) and c.prefix != xml.prefix
128:                 #    c
129:                 #else
130:                 #    parse_xml c
131:                 #end
132:                 r = parse_xml c
133: 
134:                 rep.last << r if r
135:             end
136: 
137:             rep
138:         end

[Validate]