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.1.6-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.6 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.5 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.4-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.4 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.3-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.3 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.2-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.2 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.1-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.1.1 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.8-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.8 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.7-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.7 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.6-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.6 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.5-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.5 lib/bel_parser/script/syntax/invalid_regex_pattern.rb
bel_parser-1.0.4-java lib/bel_parser/script/syntax/invalid_regex_pattern.rb