Sha256: 11d25a0d1d588c9600a6add0fb8f41deb07a80c536bd331007fe6fd432cdcc09

Contents?: true

Size: 472 Bytes

Versions: 2

Compression:

Stored size: 472 Bytes

Contents

# frozen_string_literal: true

module Farseer
  class Regexp
    include MapFactory

    WS_REGEXP = /^(?'token'\s*)(?'rest'.*)$/
    RegexpError = Class.new(ArgumentError)

    def initialize(regexp)
      raise RegexpError unless regexp.names == ['token', 'rest']

      @regexp = regexp
      freeze
    end

    WS = new(WS_REGEXP)

    def parse(input)
      match = input.match(@regexp)

      Maybe.return(Result.new(match[:token], match[:rest]))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
farseer-0.9.0 lib/farseer/regexp.rb
farseer-0.8.0 lib/farseer/regexp.rb