lib/pione/pnml/compiler.rb in pione-0.4.1 vs lib/pione/pnml/compiler.rb in pione-0.4.2
- old
+ new
@@ -23,10 +23,11 @@
rules << InputMergeComplement
rules << InputParallelizationComplement
rules << OutputDecompositionComplement
rules << OutputSynchronizationComplement
end
+ @actions = []
end
# Compile a PNML file into PIONE document as a string.
def compile
# annotations
@@ -37,21 +38,31 @@
# build rules
rules, flow_elements = build_constituent_rule_definitions
definition_main = build_flow_rule_definition(@option[:flow_rule_name] || "Main", flow_elements)
+ # merge literate actions
+ rules.each do |rule|
+ if @option[:literate_actions]
+ if action = @option[:literate_actions][rule.name]
+ rule.action_content = action[:content]
+ end
+ end
+ end
+
# textize
[*annotations, "", definition_main.textize, *rules.map {|rule| rule.textize}].join("\n")
end
private
# Build constituent rule definitions by transitions in the net.
def build_constituent_rule_definitions
definition = @net.transitions.each_with_object({}) do |transition, table|
if Perspective.rule?(transition)
- rule = RuleDefinition.new(transition.name)
+ type = Perspective.flow_rule?(transition) ? :flow : :action
+ rule = RuleDefinition.new(transition.name, type)
# inputs
@net.find_all_places_by_target_id(transition.id).each do |place|
if Perspective.file?(place)
rule.inputs << Perspective.normalize_data_name(place.name)
@@ -73,18 +84,18 @@
table[transition.id] = rule
end
end
# save all inner rules
- rules = definition.values.compact
+ rules = definition.values.select{|rule_def| rule_def.action?}.compact
flow_elements = definition.values.compact
# conditional branch
@net.transitions.each do |transition|
places = @net.find_all_places_by_target_id(transition.id)
- inputs = places.select {|place| Perspective.file?(place)}
- inputs = inputs.map {|input| Perspective.normalize_data_name(input.name)}
+ input_places = places.select {|place| Perspective.file?(place)}
+ inputs = input_places.map {|input| Perspective.normalize_data_name(input.name)}
case Perspective.normalize_data_name(transition.name)
when "if"
# if-branch
condition = @net.find_place_by_source_id(transition.id)
@@ -155,10 +166,10 @@
:outputs => outputs,
:params => @net.places.select {|place| Perspective.param?(place) and Perspective.net_input?},
:flow_elements => flow_elements,
}
- RuleDefinition.new(name, option)
+ RuleDefinition.new(name, :flow, option)
end
def find_next_rules(base_rule)
@net.find_all_places_by_source_id(base_rule.id).each_with_object([]) do |place, res|
@net.find_all_transitions_by_source_id(place.id).each do |transition|