Class: BELParser::Script::Syntax::InvalidRegexPattern

Inherits:
Object
  • Object
show all
Extended by:
Language::Syntax::SyntaxFunction
Defined in:
lib/bel_parser/script/syntax/invalid_regex_pattern.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.map(ast_node, script_context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/bel_parser/script/syntax/invalid_regex_pattern.rb', line 15

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