Sha256: 9bf7afbe7d8d4e55a3f457012b5794b9b89d4468c76ff5bbf5f92de97aa41dba

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

require 'bel_parser/language'
require 'bel_parser/language/expression_validator'
require 'bel_parser/language/syntax_function'
require 'bel_parser/language/syntax_warning'
require 'bel_parser/quoting'
require 'bel_parser/parsers/ast/node'
require 'concurrent/hash'

module BELParser
  module Script
    module Syntax
      class ExpressionValidation
        extend BELParser::Language::Syntax::SyntaxFunction
        extend BELParser::Quoting

        TARGET_NODES = [
          BELParser::Parsers::AST::ObservedTerm,
          BELParser::Parsers::AST::SimpleStatement,
          BELParser::Parsers::AST::NestedStatement
        ]
        EXP_VALIDATOR = BELParser::Language::ExpressionValidator

        def self.map(ast_node, script_context)
          return nil unless TARGET_NODES.include?(ast_node.class)
          return nil unless script_context.key?(:specification)

          validator = expression_validator(script_context)
          validator.validate(ast_node).select(&:failure?)
        end

        def self.expression_validator(script_context)
          unless defined? @expression_validator
            spec, namespaces, uri_reader, url_reader =
              script_context.values_at(
                :specification,
                :namespace_definitions,
                :uri_reader,
                :url_reader)
            @expression_validator = EXP_VALIDATOR.new(
              spec, namespaces, uri_reader, url_reader)
          end
          @expression_validator
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bel_parser-1.0.0.alpha.46-java lib/bel_parser/script/syntax/expression_validation.rb
bel_parser-1.0.0.alpha.46 lib/bel_parser/script/syntax/expression_validation.rb
bel_parser-1.0.0.alpha.45-java lib/bel_parser/script/syntax/expression_validation.rb
bel_parser-1.0.0.alpha.45 lib/bel_parser/script/syntax/expression_validation.rb