class Pione::PNML::Perspective

‘Perspective` is a meta class for PIONE’s concepts overlayed in PNML.

Constants

TRANSFORMER_OPT

Public Class Methods

case_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword “case”.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword "case"
# File lib/pione/pnml/pione-model.rb, line 304
def case_transition?(env, node)
  match_transition_parser?(env, node, :case_transition)
end
constraint_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword “constraint”.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword "constraint"
# File lib/pione/pnml/pione-model.rb, line 328
def constraint_transition?(env, node)
  match_transition_parser?(env, node, :constraint_transition)
end
data_modifier(env, node) click to toggle source

Return the modifier of node name.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [String]

modifier or nil
# File lib/pione/pnml/pione-model.rb, line 228
def data_modifier(env, node)
  if node.kind_of?(Place) and not(node.name.nil?)
    begin
      parsed = Parser.new.data_place.parse(node.name)
      if parsed.kind_of?(Hash)
        return parsed[:modifier].to_s
      end
    rescue Parslet::ParseFailed
      begin
        parsed = Parser.new.empty_place.parse(node.name)
        if parsed.kind_of?(Hash)
          return parsed[:modifier].to_s
        end
      rescue Parslet::ParseFailed
      end
    end
  end
  return nil
end
data_place?(env, node) click to toggle source

Return true if the node is a data place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a data place
# File lib/pione/pnml/pione-model.rb, line 64
def data_place?(env, node)
  match_place_parser_with_type?(env, node, :data_place, :expr, Lang::TypeDataExpr)
end
else_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword “else”.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword "else"
# File lib/pione/pnml/pione-model.rb, line 292
def else_transition?(env, node)
  match_transition_parser?(env, node, :else_transition)
end
empty?(env, node) click to toggle source

Return true if the node is empty.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is empty
# File lib/pione/pnml/pione-model.rb, line 16
def empty?(env, node)
  empty_place?(env, node) or empty_transition?(env, node)
end
empty_place?(env, node) click to toggle source

Return true if the node is an empty place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is an empty place
# File lib/pione/pnml/pione-model.rb, line 28
def empty_place?(env, node)
  match_place_parser?(env, node, :empty_place)
end
empty_transition?(env, node) click to toggle source

Return true if the node is an empty transition.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is an empty transition
# File lib/pione/pnml/pione-model.rb, line 40
def empty_transition?(env, node)
  match_transition_parser?(env, node, :empty_transition)
end
eval_param_sentence(env, node) click to toggle source

Evaluate the node as a parameter sentence.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Object]

evaluated result
# File lib/pione/pnml/pione-model.rb, line 132
def eval_param_sentence(env, node)
  eval_transition(env, node, :param_sentence, :param_sentence)
end
expr_place?(env, node) click to toggle source

Return true if the node is an expression place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is an exression place
# File lib/pione/pnml/pione-model.rb, line 52
def expr_place?(env, node)
  match_place_parser?(env, node, :expr_place)
end
external_rule_transition?(env, node) click to toggle source

Return ture if the node is an external rule.

@param env [Lang::Environment]

language environment

@param [PNML::Node] node

PNML node

@return [Boolean]

true if the node is an external rule
# File lib/pione/pnml/pione-model.rb, line 216
def external_rule_transition?(env, node)
  match_transition_parser?(env, node, :external_rule_transition)
end
feature_place?(env, node) click to toggle source

Return true if the node is a feature place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a feature place
# File lib/pione/pnml/pione-model.rb, line 156
def feature_place?(env, node)
  match_place_parser_with_type?(env, node, :expr_place, :expr, Lang::TypeFeature)
end
feature_transition?(env, node) click to toggle source

Return true if the node is a feature transition.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a feature transition
# File lib/pione/pnml/pione-model.rb, line 168
def feature_transition?(env, node)
  match_place_parser?(env, node, :feature_sentence)
end
if_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword “if”.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword "if"
# File lib/pione/pnml/pione-model.rb, line 268
def if_transition?(env, node)
  match_transition_parser?(env, node, :if_transition)
end
internal_rule_transition?(env, node) click to toggle source

Return ture if the node is an internal rule.

@param env [Lang::Environment]

language environment

@param [PNML::Node] node

PNML node

@return [Boolean]

true if the node is an internal rule
# File lib/pione/pnml/pione-model.rb, line 204
def internal_rule_transition?(env, node)
  match_transition_parser?(env, node, :internal_rule_transition)
end
keyword_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword
# File lib/pione/pnml/pione-model.rb, line 256
def keyword_transition?(env, node)
  match_transition_parser?(env, node, :keyword_transition)
end
net_input_data_place?(env, node) click to toggle source

Return true if the node is a net input data place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a net input data place
# File lib/pione/pnml/pione-model.rb, line 76
def net_input_data_place?(env, node)
  if data_place?(env, node)
    return net_input_data_symbol?(data_modifier(env, node))
  else
    return false
  end
end
net_output_data_place?(env, node) click to toggle source

Return true if the node is a net output data place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a net output data place
# File lib/pione/pnml/pione-model.rb, line 92
def net_output_data_place?(env, node)
  if data_place?(env, node)
    return net_output_data_symbol?(data_modifier(env, node))
  else
    return false
  end
end
param_place?(env, node) click to toggle source

Return true if the node is a parameter.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a parameter
# File lib/pione/pnml/pione-model.rb, line 108
def param_place?(env, node)
  match_place_parser_with_type?(env, node, :expr_place, :expr, Lang::TypeParameterSet)
end
param_transition?(env, node) click to toggle source

Return true if the node is a parameter sentence transition.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a parameter sentence transition
# File lib/pione/pnml/pione-model.rb, line 120
def param_transition?(env, node)
  match_transition_parser?(env, node, :param_sentence)
end
rule_transition?(env, node) click to toggle source

Return true if the node is a rule.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a rule.
# File lib/pione/pnml/pione-model.rb, line 192
def rule_transition?(env, node)
  match_transition_parser?(env, node, :rule_transition)
end
then_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword “then”.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword "then"
# File lib/pione/pnml/pione-model.rb, line 280
def then_transition?(env, node)
  match_transition_parser?(env, node, :then_transition)
end
ticket_place?(env, node) click to toggle source

Return true if the node is a ticket place.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a ticket place
# File lib/pione/pnml/pione-model.rb, line 144
def ticket_place?(env, node)
  match_place_parser_with_type?(env, node, :expr_place, :expr, Lang::TypeTicketExpr)
end
variable_binding_transition?(env, node) click to toggle source

Return true if the node is a variable binding transition.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

the node

@return [Boolean]

true if the node is a variable binding transition
# File lib/pione/pnml/pione-model.rb, line 180
def variable_binding_transition?(env, node)
  match_transition_parser?(env, node, :variable_binding_sentence)
end
when_transition?(env, node) click to toggle source

Return true if the node is a transition with keyword “when”.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@return [Boolean]

true if the node is a transition with keyword "when"
# File lib/pione/pnml/pione-model.rb, line 316
def when_transition?(env, node)
  match_transition_parser?(env, node, :when_transition)
end

Private Class Methods

eval_transition(env, node, parser_name, target_name) click to toggle source

Evaluate the transition and return the result.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@param parser_name [Symbol]

place parser name

@param target_name [Symbol]

target name that has expected type

@param expected_type [Pione::Lang::Type]

expected PIONE type

@return [Boolean]

true if the node is the place parser
# File lib/pione/pnml/pione-model.rb, line 477
def eval_transition(env, node, parser_name, target_name)
  parsed = parse_transition(env, node, parser_name)
  if parsed and parsed[target_name]
    return Lang::DocumentTransformer.new.apply(parsed[target_name], TRANSFORMER_OPT)
  else
    return nil
  end
end
match_place_parser?(env, node, parser_name) { |parsed| ... } click to toggle source

Return true if the node matches the place parser.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@param parser_name [String]

place parser name

@return [Boolean]

true if the node is the place parser
# File lib/pione/pnml/pione-model.rb, line 393
def match_place_parser?(env, node, parser_name)
  parsed = parse_place(env, node, parser_name)
  if not(parsed.nil?)
    if block_given?
      return yield parsed
    else
      return true
    end
  else
    return false
  end
end
match_place_parser_with_type?(env, node, parser_name, target_name, expected_type) click to toggle source

Return true if the node matches the place parser and expected type.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@param parser_name [String]

place parser name

@param target_name [Symbol]

target name that has expected type

@param expected_type [Pione::Lang::Type]

expected PIONE type

@return [Boolean]

true if the node is the place parser
# File lib/pione/pnml/pione-model.rb, line 420
def match_place_parser_with_type?(env, node, parser_name, target_name, expected_type)
  parsed = parse_place(env, node, parser_name)
  if parsed and parsed[target_name]
    expr = Lang::DocumentTransformer.new.apply(parsed[target_name], TRANSFORMER_OPT)
    return expr.pione_type(env) == expected_type
  else
    return false
  end
end
match_transition_parser?(env, node, parser_name) click to toggle source

Return true if the node matches the transition parser.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@param parser_name [Symbol]

transition parser name

@return [Boolean]

true if the node is the keyword
# File lib/pione/pnml/pione-model.rb, line 459
def match_transition_parser?(env, node, parser_name)
  not(parse_transition(env, node, parser_name).nil?)
end
net_input_data_symbol?(str) click to toggle source

Return true if the string is net input data symbol.

@param [String]

string

@return [Boolean]

true if the string is net input data symbol
# File lib/pione/pnml/pione-model.rb, line 340
def net_input_data_symbol?(str)
  return false if str.nil?

  Parser.new.net_input_symbol.parse(str)
  return true
rescue Parslet::ParseFailed
  return false
end
net_output_data_symbol?(str) click to toggle source

Return true if the string is net output data symbol.

@param [String]

string

@return [Boolean]

true if the string is net output data symbol
# File lib/pione/pnml/pione-model.rb, line 355
def net_output_data_symbol?(str)
  return false if str.nil?

  Parser.new.net_output_symbol.parse(str)
  return true
rescue Parslet::ParseFailed
  return false
end
parse_place(env, node, parser_name) click to toggle source

Return true if the node matches the place parser.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@param parser_name [String]

place parser name

@return [Boolean]

true if the node is the place parser
# File lib/pione/pnml/pione-model.rb, line 374
def parse_place(env, node, parser_name)
  if node.kind_of?(Place) and not(node.name.nil?)
    begin
      return Parser.new.send(parser_name).parse(node.name)
    rescue Parslet::ParseFailed
    end
  end
end
parse_transition(env, node, parser_name) click to toggle source

Return true if the node matches the transition parser.

@param env [Lang::Environment]

language environment

@param node [PNML::Node]

PNML's node

@param parser_name [Symbol]

place parser name

@return [Boolean]

true if the node is the transition parser
# File lib/pione/pnml/pione-model.rb, line 440
def parse_transition(env, node, parser_name)
  if node.kind_of?(Transition) and not(node.name.nil?)
    begin
      return Parser.new.send(parser_name).parse(node.name)
    rescue Parslet::ParseFailed
    end
  end
end