Sha256: e7f1a8a7abcc0aa991c961afb159326aadfe1b2fb8f85ec5066eb1eeda5fdb4b
Contents?: true
Size: 1.79 KB
Versions: 82
Compression:
Stored size: 1.79 KB
Contents
require 'bel_parser/parsers/ast/node' module BELParser module Language module Semantics # MultipleSubjectObject implements a {SemanticsFunction} that maps a # {BELParser::Parsers::AST::Statement} to a {SemanticsWarning} if the # subject term is referenced as an argument of the object list term. class MultipleSubjectObject include SemanticsFunction private_class_method :new def self.map(stmt_node, spec, _namespaces) return nil unless stmt_node.is_a?(BELParser::Parsers::AST::Statement) return nil if stmt_node.relationship.string_literal.nil? rel = spec.relationship(stmt_node.relationship.string_literal.to_sym) return nil unless rel.listable? list_func = spec.function(:list) return nil unless list_func return nil unless stmt_node.object.term? map_subject_object(stmt_node, rel, spec) end def self.map_subject_object(stmt_node, rel, spec) sub_term = stmt_node.subject.term list_term = stmt_node.object.child if list_term.arguments.any? { |arg| sub_term == arg.child } MultipleSubjectObjectWarning.new(stmt_node, spec, rel) end end end # Represents a {SemanticsWarning} when a # {BELParser::Parsers::AST::Statement} includes the subject term as an # argument of an object list term. class MultipleSubjectObjectWarning < SemanticsWarning def initialize(stmt_node, spec, rel) super(stmt_node, spec) @rel = rel end def to_s <<-MSG.gsub(/ {12}/, '').delete("\n") A "#{@rel.long}" statement cannot use the subject term as an object list() argument. MSG end end end end end
Version data entries
82 entries across 82 versions & 1 rubygems