Sha256: d486f03dda709798adffe6fb1c84a202203013e8631161c506b3f7d87e911970

Contents?: true

Size: 1.8 KB

Versions: 39

Compression:

Stored size: 1.8 KB

Contents

require 'bel_parser/language'
require 'bel_parser/language/syntax_function'
require 'bel_parser/language/syntax_error'
require 'bel_parser/parsers/ast/node'
require 'concurrent/hash'
require_relative '../keywords'

module BELParser
  module Script
    module Syntax
      class UnsupportedBELVersion
        extend BELParser::Language::Syntax::SyntaxFunction
        extend Keyword

        TARGET_NODE = BELParser::Parsers::AST::DocumentProperty

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

          value_string = value.children[0].string_literal
          begin
            BELParser::Language.specification(value_string)
            nil
          rescue ArgumentError
            script_context[:specification] = BELParser::Language.default_specification
            UnsupportedBELVersionWarning.new(ast_node, value_string)
          end
        end
      end

      # UnsupportedBELVersionError represents the use of an unsupported
      # BEL version string.
      class UnsupportedBELVersionWarning < BELParser::Language::Syntax::SyntaxWarning
        # Gets the unsupported bel version.
        attr_reader :unsupported_version

        def initialize(document_property_node, unsupported_version)
          super(document_property_node, nil)
          @unsupported_version = unsupported_version
          @default             = BELParser::Language.default_version
        end

        def msg
          <<-MSG.gsub(/^ +/, '').delete("\n")
            Unsupported BEL version "#@unsupported_version". 
            Setting BEL version to the default version "#@default".
          MSG
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
bel_parser-1.1.6-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.6 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.5 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.4-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.4 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.3-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.3 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.2-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.2 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.1-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.1.1 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.8-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.8 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.7-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.7 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.6-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.6 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.5-java lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.5 lib/bel_parser/script/syntax/unsupported_bel_version.rb
bel_parser-1.0.4-java lib/bel_parser/script/syntax/unsupported_bel_version.rb