Sha256: ea37a11c88c419238d3d9c8f2c38d13ebc22fb1d9f711e7b16c07b2bb2c4c474

Contents?: true

Size: 686 Bytes

Versions: 2

Compression:

Stored size: 686 Bytes

Contents

# Matches a special kind of regular expression that only ever matches one
# character at a time. Useful members of this family are: character ranges, 
# \w, \d, \r, \n, ...
#
# Example: 
#
#   match('[a-z]')  # matches a-z
#   match('\s')     # like regexps: matches space characters
#
class Parslet::Atoms::Re < Parslet::Atoms::Base
  attr_reader :match
  def initialize(match)
    @match = match
  end

  def try(io)
    r = Regexp.new(match, Regexp::MULTILINE)
    s = io.read(1)
    error(io, "Premature end of input") unless s
    error(io, "Failed to match #{match.inspect[1..-2]}") unless s.match(r)
    return s
  end

  def to_s_inner(prec)
    match.inspect[1..-2]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parslet-0.11.0 lib/parslet/atoms/re.rb
parslet-0.10.1 lib/parslet/atoms/re.rb