Class: BELParser::Language::Semantics::RelationshipNotListable

Inherits:
Object
  • Object
show all
Includes:
SemanticsFunction
Defined in:
lib/bel_parser/language/semantics/relationship_not_listable.rb

Overview

RelationshipNotListable implements a SemanticsFunction that maps a Parsers::AST::Statement to a SemanticsWarning if the relationship cannot be used for multiple terms in a list.

Class Method Summary collapse

Class Method Details

.map(node, spec, _namespaces) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/bel_parser/language/semantics/relationship_not_listable.rb', line 14

def self.map(node, spec, _namespaces)
  return nil unless node.is_a?(BELParser::Parsers::AST::Statement)
  return nil unless node.relationship?
  return nil unless node.object.term?

  map_statement(node, spec)
end

.map_statement(stmt_node, spec) ⇒ Object



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

def self.map_statement(stmt_node, spec)
  list_func = spec.function(:list)
  return nil unless list_func

  obj_func = stmt_node.object.child.function.identifier.string_literal
  return nil unless spec.function(obj_func.to_sym) == list_func

  rel = spec.relationship(stmt_node.relationship.string_literal.to_sym)
  return nil unless rel

  RelationshipNotMultipleWarning.new(stmt_node, spec, rel) unless
    rel.listable?
end