Class: BELParser::Script::Syntax::UndefinedAnnotationValue

Inherits:
Object
  • Object
show all
Extended by:
Language::Syntax::SyntaxFunction, Keyword
Defined in:
lib/bel_parser/script/syntax/undefined_annotation_value.rb

Constant Summary collapse

TARGET_NODE =
BELParser::Parsers::AST::Set
LIST_NODE =
BELParser::Parsers::AST::List

Constants included from Keyword

Keyword::BEL_VERSION_REGEX, Keyword::BEL_VERSION_STRING, Keyword::CITATION, Keyword::CITATION_REGEX, Keyword::IMPLICIT_ANNOTATIONS, Keyword::SUPPORT, Keyword::SUPPORT_REGEX

Class Method Summary collapse

Methods included from Keyword

is_bel_version?, is_citation?, is_implicit_annotation?, is_support?

Class Method Details

.annotation(name_string, script_context) ⇒ Object



51
52
53
54
55
# File 'lib/bel_parser/script/syntax/undefined_annotation_value.rb', line 51

def self.annotation(name_string, script_context)
  hash =
    script_context[:annotation_definitions] ||= Concurrent::Hash.new
  hash[name_string]
end

.map(ast_node, script_context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bel_parser/script/syntax/undefined_annotation_value.rb', line 18

def self.map(ast_node, script_context)
  return nil unless ast_node.is_a?(TARGET_NODE)
  name, value  = ast_node.children
  name_string  = ast_node.name.identifier.string_literal

  return nil if is_implicit_annotation?(name_string)
  type, dataset = annotation(name_string, script_context)
  return nil unless type == :uri || type == :url

  reader =
    case type
    when :uri
      script_context[:uri_reader]
    when :url
      script_context[:url_reader]
    end
  value_node = ast_node.value.children[0]
  if value_node.is_a?(LIST_NODE)
    value_node
      .list_items.map { |li| li.children[0].string_literal }
      .map do |string|
        map_value(ast_node, name_string, string, dataset.identifier, reader)
      end
  else
    map_value(
      ast_node,
      name_string,
      value_node.string_literal,
      dataset.identifier,
      reader)
  end
end

.map_value(ast_node, name_string, value_string, identifier, reader) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/bel_parser/script/syntax/undefined_annotation_value.rb', line 57

def self.map_value(ast_node, name_string, value_string, identifier, reader)
  value = reader.retrieve_value_from_resource(identifier, value_string)
  UndefinedAnnotationValueWarning.new(
    ast_node,
    name_string,
    value_string) unless value
end