Sha256: 75edf0d7ac793ff7a0e43c94ec314ac0f04389895a111555d0c229b02fe03c1d

Contents?: true

Size: 1.64 KB

Versions: 46

Compression:

Stored size: 1.64 KB

Contents

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

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

        TARGET_NODE = BELParser::Parsers::AST::NamespaceDefinition

        def self.map(ast_node, script_context)
          return nil unless ast_node.is_a?(TARGET_NODE)
          resource_reader = script_context[:resource_reader]

          keyword, domain = ast_node.children
          if domain.url?
            url = unquote(domain.child.string.string_literal)
            unless resource_reader.retrieve_resource(url)
              prefix = keyword.identifier.string_literal
              return UnresolvableNamespaceError.new(ast_node, prefix, url)
            end
          end

          nil
        end
      end

      # UnresolvableNamespaceError indicates that a namespace resource could
      # not be resolved.
      class UnresolvableNamespaceError < BELParser::Language::Syntax::SyntaxError
        # Gets the unresolvable namespace prefix.
        attr_reader :prefix
        # Gets the unresolvable namespace identifier.
        attr_reader :identifier

        def initialize(define_namespace_node, prefix, identifier)
          super(define_namespace_node, nil)
          @prefix     = prefix
          @identifier = identifier
        end

        def msg
          %(Could not resolve "#@prefix" with identifier "#@identifier".)
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
bel_parser-1.0.0.alpha.44-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.44 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.43-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.43 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.42-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.42 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.41-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.41 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.40-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.40 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.39-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.39 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.38-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.38 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.37-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.37 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.36-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.36 lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.35-java lib/bel_parser/script/syntax/unresolvable_namespace.rb
bel_parser-1.0.0.alpha.35 lib/bel_parser/script/syntax/unresolvable_namespace.rb