Class: BELParser::Language::Version1_0::Upgrades::TranslocationTransformation

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin, TermTransformation, Parsers::AST::Sexp
Defined in:
lib/bel_parser/language/version1_0/upgrades/translocation_transformation.rb

Constant Summary

Constants included from TermTransformation

TermTransformation::ACTIVITIES, TermTransformation::PMODTYPES

Instance Method Summary collapse

Methods included from TermTransformation

#collapse, #on_argument, #on_function, #on_nested_statement, #on_object, #on_observed_term, #on_simple_statement, #on_statement, #on_subject

Methods included from Parsers::AST::Sexp

#annotation_definition, #argument, #blank_line, #comment, #comment_line, #document_property, #domain, #function, #identifier, #keyword, #list, #list_item, #name, #namespace_definition, #nested_statement, #object, #observed_term, #parameter, #pattern, #prefix, #relationship, #set, #simple_statement, #statement, #string, #subject, #term, #unset, #uri, #url, #value

Methods included from AST::Processor::Mixin

#handler_missing, #process, #process_all

Instance Method Details

#add_loc_func(argument_node, function_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bel_parser/language/version1_0/upgrades/translocation_transformation.rb', line 22

def add_loc_func(argument_node, function_name)
  prefix_name = argument_node.child.prefix.children[0].string_literal
  value_name = argument_node.child.value.children[0].string_literal
  argument(
    term(
      function(
        identifier(function_name)),
      argument(
        parameter(
          prefix(
            identifier(prefix_name)),
          value(
            identifier(value_name))))))
end

#on_term(term_node) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/bel_parser/language/version1_0/upgrades/translocation_transformation.rb', line 14

def on_term(term_node)
  if ['tloc', 'translocation'].include?(term_node.function.identifier.string_literal)
    term_node.updated([term_node.function, term_node.arguments[0], add_loc_func(term_node.arguments[1], 'fromLoc'), add_loc_func(term_node.arguments[2], 'toLoc') ].flatten)
  else
    term_node.updated([process(term_node.function), term_node.arguments.map! {|arg| process(arg)}].flatten())
  end
end