Sha256: 30ffe6cac6ddb9b202f49802d317c79c970bd9f8fa057062c4b4edb0c6a0af9a

Contents?: true

Size: 1.32 KB

Versions: 59

Compression:

Stored size: 1.32 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'

module BELParser
  module Script
    module Syntax
      class InvalidRegexPattern
        extend BELParser::Language::Syntax::SyntaxFunction

        TARGET_NODE = BELParser::Parsers::AST::Pattern

        def self.map(ast_node, script_context)
          return nil unless ast_node.is_a?(TARGET_NODE)
          pattern = ast_node.string.string_literal
          begin
            Regexp.new(pattern)
            nil
          rescue RegexpError => error
            InvalidRegexPatternError.new(ast_node, pattern, error.to_s)
          end
        end
      end

      # InvalidRegexPattern indicates that a pattern represented an invalid
      # regular expression.
      class InvalidRegexPatternError < BELParser::Language::Syntax::SyntaxError
        # Gets the invalid pattern.
        attr_reader :pattern

        def initialize(pattern_node, pattern, error_msg)
          super(pattern_node, nil)
          @pattern   = pattern
          @error_msg = error_msg
        end

        def msg
          <<-MSG.gsub(/^ +/, '').delete("\n")
            "#@pattern" is not a valid regular expression (#@error_msg).
          MSG
        end
      end
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
bel_parser-1.0.4 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.3-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.3 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.2-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.2 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.1-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.1 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.61-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.61 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.60-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.60 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.59-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.59 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.58-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.58 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.57-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.57 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.0.alpha.56-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb