Class: BELParser::Script::State::Set

Inherits:
Object
  • Object
show all
Extended by:
Keyword, BELParser::Script::StateFunction
Defined in:
lib/bel_parser/script/state/set.rb

Constant Summary collapse

TARGET_NODE =
BELParser::Parsers::AST::Set
LIST_NODE =
BELParser::Parsers::AST::List
FIELDS =
%w(type name id date authors comment)

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 BELParser::Script::StateFunction

consume

Methods included from Keyword

is_bel_version?, is_citation?, is_implicit_annotation?, is_support?

Class Method Details

.consume(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
# File 'lib/bel_parser/script/state/set.rb', line 18

def self.consume(ast_node, script_context)
  return nil unless ast_node.is_a?(TARGET_NODE)
  name_node, value_node = ast_node.children
  name_string           = name_node.identifier.string_literal
  case
  when is_citation?(name_string)
    handle_citation(value_node.children[0], script_context)
  when is_support?(name_string)
    handle_support(value_node, script_context)
  when value_node.children[0].is_a?(LIST_NODE)
    value_node
      .children[0]
      .list_items
      .each do |list_item|
        handle_annotation(name_string, list_item, script_context)
      end
  else
    case name_string
    when /\ASTATEMENT_GROUP\Z/
      handle_statement_group(value_node, script_context)
    else
      handle_annotation(name_string, value_node, script_context)
    end
  end
end

.handle_citation(value_node, script_context) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bel_parser/script/state/set.rb', line 44

def self.handle_citation(value_node, script_context)
  if value_node.is_a?(LIST_NODE)
    script_context[:citation] =
      Hash[
        FIELDS.zip(
          value_node
            .list_items
            .map { |li| li.children[0].string_literal })
      ]
  end
end

.handle_support(value_node, script_context) ⇒ Object



56
57
58
# File 'lib/bel_parser/script/state/set.rb', line 56

def self.handle_support(value_node, script_context)
  script_context[:support] = value_node.children[0].string_literal
end