class Pione::PNML::ConditionalBranch
ConditionalBranch
is a class represents PIONE’s conditional branch declaration.
Constants
- TEMPLATE_CASE
- TEMPLATE_IF
- TEMPLATE_IF_ELSE
Attributes
condition[R]
table[R]
Public Class Methods
new(type, condition)
click to toggle source
# File lib/pione/pnml/pione-model.rb, line 684 def initialize(type, condition) @type = type @condition = condition @table = Hash.new {|h,k| h[k] = []} end
Public Instance Methods
as_declaration(option={})
click to toggle source
# File lib/pione/pnml/pione-model.rb, line 690 def as_declaration(option={}) case @type when :"if" branch_then = @table[:then].map do |rule| rule.as_declaration(option.merge(level: option[:level] + 1)) end.join("\n") if @table[:else].empty? indent(Util::Indentation.cut(TEMPLATE_IF) % [@condition, branch_then], option) else branch_else = @table[:else].map do |rule| rule.as_declaration(option.merge(level: option[:level] + 1)) end.join("\n") indent(Util::Indentation.cut(TEMPLATE_IF_ELSE) % [@condition, branch_then, branch_else], option) end when :"case" branches = @table.each_with_object([]) do |(val, rules), lines| lines << ((val == :else) ? "else" : "when %s" % val) level = (option[:level] || 0) + 1 lines.concat(rules.map{|rule| rule.as_declaration(option.merge(level: level))}) end.join("\n") indent(Util::Indentation.cut(TEMPLATE_CASE) % [@condition, branches], option) end end