Sha256: 22e6b83395b130c74a94275ac30594de9cd8167fc7739d7aa8771fe1613fcb71
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
begin require 'awesome_print' require 'pry' rescue LoadError; end require 'regexp_parser' module EcmaReValidator # JS doesn't have Unicode matching UNICODE_CHARACTERS = Regexp::Syntax::Token::UnicodeProperty::All INVALID_REGEXP = [ # JS doesn't have \A or \Z :bos, :eos_ob_eol, # JS doesn't have lookbehinds :lookbehind, :nlookbehind, # JS doesn't have atomic grouping :atomic, # JS doesn't have possesive quantifiers :zero_or_one_possessive, :zero_or_more_possessive, :one_or_more_possessive, # JS doesn't have named capture groups :named_ab, :named_sq, # JS doesn't support modifying options :options, # JS doesn't support conditionals :condition_open, # JS doesn't support comments :comment ] INVALID_TOKENS = INVALID_REGEXP + UNICODE_CHARACTERS def self.valid?(input) if input.is_a? String begin input = Regexp.new(input) rescue RegexpError return false end elsif !input.is_a? Regexp return false end Regexp::Scanner.scan(input).none? do |t| if t[1] == :word || t[1] == :space || t[1] == :digit t[0] != :type else INVALID_TOKENS.include?(t[1]) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ecma-re-validator-0.1.1 | lib/ecma-re-validator.rb |