Sha256: 1556ad2e00f0ee0492050f1b1cf0adfaf35d96614a47c0cfa0c95c4fb5163c89

Contents?: true

Size: 1.6 KB

Versions: 109

Compression:

Stored size: 1.6 KB

Contents

require 'bel_parser/parsers/ast/node'

module BELParser
  module Language
    module Semantics
      # NonCausalNestedStatement implements a {SemanticsFunction} that maps a
      # nested {BELParser::Parsers::AST::Statement} to {SemanticsWarning} if
      # the relationship is non-causal.
      class NonCausalNestedStatement
        include SemanticsFunction

        private_class_method :new

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

          rel = node.relationship.string_literal.to_sym
          unless spec.causal_relationships.include?(rel)
            NonCausalNestedStatementWarning.new(node, spec, rel)
          end
        end
      end

      # Represents a {SemanticsWarning} when a nested
      # {BELParser::Parsers::AST::Statement} has a non-causal relationship.
      class NonCausalNestedStatementWarning < SemanticsWarning
        attr_reader :non_causal_relationship

        def initialize(stmt_node, spec, rel)
          super(stmt_node, spec)
          @non_causal_relationship = spec.relationship(rel)
        end

        def to_s
          causal_relationships =
            @specification
            .causal_relationships
            .map(&:long)
            .join(', ')
          <<-MSG.gsub(/ {12}/, '')
            Nested statement is not a causal relationship.
             The "#{non_causal_relationship.long}" relationship is not causal.
             Causal Relationships: #{causal_relationships}
          MSG
        end
      end
    end
  end
end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
bel_parser-1.0.0.alpha.53-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.53 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.52-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.52 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.51-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.51 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.50-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.50 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.49-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.49 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.48-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.48 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.47-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.47 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.46-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.46 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.45-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.45 lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.44-java lib/bel_parser/language/semantics/non_causal_nested_statement.rb
bel_parser-1.0.0.alpha.44 lib/bel_parser/language/semantics/non_causal_nested_statement.rb