class BELParser::Script::State::Set
Constants
Public Class Methods
consume(ast_node, script_context)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
handle_annotation(name_string, value_node, script_context)
click to toggle source
# File lib/bel_parser/script/state/set.rb, line 60 def self.handle_annotation(name_string, value_node, script_context) # add to annotation state script_context[:annotations] ||= Concurrent::Hash.new if value_node.children[0].respond_to?(:string_literal) namestr = value_node.children[0].string_literal else namestr = value_node.children[0].to_s end script_context[:annotations][name_string] = namestr end
handle_statement_group(value_node, script_context)
click to toggle source
# File lib/bel_parser/script/state/set.rb, line 72 def self.handle_statement_group(value_node, script_context) script_context[:statement_group] = value_node.children[0].string_literal # clear annotation state script_context[:annotations] ||= Concurrent::Hash.new script_context[:annotations].clear script_context[:citation] = nil end