class Rox::Core::RegularExpressionExtensions
Public Class Methods
new(parser)
click to toggle source
# File lib/rox/core/roxx/regular_expression_extensions.rb, line 4 def initialize(parser) @parser = parser end
Public Instance Methods
extend()
click to toggle source
# File lib/rox/core/roxx/regular_expression_extensions.rb, line 8 def extend @parser.add_operator('match') do |_parser, stack, _context| text = stack.pop pattern = stack.pop flags = stack.pop unless text.is_a?(String) && pattern.is_a?(String) && flags.is_a?(String) raise ArgumentError, 'should be string' end options = 0 flags.each_char do |flag| case flag when 'i' options |= Regexp::IGNORECASE when 'x' options |= Regexp::EXTENDED when 'm' options |= Regexp::MULTILINE end end matched = !Regexp.new(pattern, options).match(text).nil? stack.push(matched) end end