Sha256: 0f0bab3fd74ba385aac6cf228d9440d57e6e9308abef55b1fa82797c6f76c44b

Contents?: true

Size: 1.42 KB

Versions: 44

Compression:

Stored size: 1.42 KB

Contents

require 'bel_parser/language'
require 'bel_parser/quoting'
require 'bel_parser/parsers/ast/node'
require 'concurrent/hash'
require_relative '../keywords'
require_relative '../state_function'

module BELParser
  module Script
    module State
      class Unset
        extend StateFunction
        extend BELParser::Script::Keyword
        extend BELParser::Quoting

        TARGET_NODE = BELParser::Parsers::AST::Unset

        def self.consume(ast_node, script_context)
          return nil unless ast_node.is_a?(TARGET_NODE)
          name_string = ast_node.name.identifier.string_literal
          case name_string
          when /\ASTATEMENT_GROUP\Z/
            handle_statement_group(script_context)
          else
            handle_annotation(name_string, script_context)
          end
        end

        def self.handle_annotation(name, script_context)
          script_context[:annotations] ||= Concurrent::Hash.new
          script_context[:annotations].delete(name)
          script_context[:citation] = nil if is_citation?(name)
        end
        private_class_method :handle_annotation

        def self.handle_statement_group(script_context)
          script_context.delete(:statement_group)
          script_context[:annotations] ||= Concurrent::Hash.new
          script_context[:annotations].clear
          script_context[:citation] = nil
        end
        private_class_method :handle_statement_group
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
bel_parser-1.0.0.alpha.46-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.46 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.45-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.45 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.44-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.44 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.43-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.43 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.42-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.42 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.41-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.41 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.40-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.40 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.39-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.39 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.38-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.38 lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.37-java lib/bel_parser/script/state/unset.rb
bel_parser-1.0.0.alpha.37 lib/bel_parser/script/state/unset.rb