Class: Parslet::Atoms::Re

### Home Classes Methods

### In Files

- lib/parslet/atoms/re.rb
- lib/parslet/atoms/visitor.rb

### Parent

Parslet::Atoms::Base

### Methods

- ::new
- #accept
- #to_s_inner
- #try

### Files

- README

### Class/Module Index

Quicksearch

- Parslet
- Parslet::Atoms
- Parslet::Atoms::Alternative
- Parslet::Atoms::Base
- Parslet::Atoms::CanFlatten
- Parslet::Atoms::Capture
- Parslet::Atoms::Context
- Parslet::Atoms::DSL
- Parslet::Atoms::Dynamic
- Parslet::Atoms::Entity
- Parslet::Atoms::Lookahead
- Parslet::Atoms::Named
- Parslet::Atoms::Precedence
- Parslet::Atoms::Re
- Parslet::Atoms::Repetition
- Parslet::Atoms::Scope
- Parslet::Atoms::Sequence
- Parslet::Atoms::Str
- Parslet::Cause
- Parslet::ClassMethods
- Parslet::DelayedMatchConstructor
- Parslet::ErrorReporter
- Parslet::ErrorReporter::Deepest
- Parslet::ErrorReporter::Tree
- Parslet::Expression
- Parslet::Expression::Treetop
- Parslet::Expression::Treetop::Parser
- Parslet::Expression::Treetop::Transform
- Parslet::ParseFailed
- Parslet::Parser
- Parslet::Parser::PrettyPrinter
- Parslet::Parser::Visitors
- Parslet::Parser::Visitors::Citrus
- Parslet::Parser::Visitors::Treetop
- Parslet::Pattern
- Parslet::Pattern::SequenceBind
- Parslet::Pattern::SimpleBind
- Parslet::Pattern::SubtreeBind
- Parslet::Scope
- Parslet::Scope::Binding
- Parslet::Scope::NotFound
- Parslet::Slice
- Parslet::Source
- Parslet::Source::LineCache
- Parslet::Source::RangeSearch
- Parslet::Transform
- Parslet::Transform::Context

No matching classes.

# Parslet::Atoms::Re

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

### Attributes

match[R]
re[R]

### Public Class Methods

new(match) click to toggle source

    # File lib/parslet/atoms/re.rb, line 12
    def initialize(match)
      super()

      @match = match.to_s
      @re    = Regexp.new(self.match, Regexp::MULTILINE)
      @error_msgs = {
        :premature  => "Premature end of input",
        :failed     => "Failed to match #{match.inspect[1..-2]}"
      }
    end

### Public Instance Methods

accept(visitor) click to toggle source

Call back visitors visit_re method. See parslet/export for an example.

    # File lib/parslet/atoms/visitor.rb, line 77
    def accept(visitor)
      visitor.visit_re(match)
    end

to_s_inner(prec) click to toggle source

    # File lib/parslet/atoms/re.rb, line 34
    def to_s_inner(prec)
      match.inspect[1..-2]
    end

try(source, context, consume_all) click to toggle source

    # File lib/parslet/atoms/re.rb, line 23
    def try(source, context, consume_all)
      return succ(source.consume(1)) if source.matches?(re)

      # No string could be read
      return context.err(self, source, @error_msgs[:premature])        if source.chars_left < 1

      # No match
      return context.err(self, source, @error_msgs[:failed])
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.