Class: Parslet::Atoms::Sequence

### Home Classes Methods

### In Files

- lib/parslet/atoms/sequence.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::Sequence

A sequence of parslets, matched from left to right. Denoted by '>>'

Example:

    str('a') >> str('b')  # matches 'a', then 'b'

### Attributes

parslets[R]

### Public Class Methods

new(*parslets) click to toggle source

    # File lib/parslet/atoms/sequence.rb, line 9
    def initialize(*parslets)
      super()

      @parslets = parslets
      @error_msgs = {
        :failed  => "Failed to match sequence (#{self.inspect})"
      }
    end

### Public Instance Methods

>>(parslet) click to toggle source

    # File lib/parslet/atoms/sequence.rb, line 18
    def >>(parslet)
      self.class.new(* @parslets+[parslet])
    end

accept(visitor) click to toggle source

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

    # File lib/parslet/atoms/visitor.rb, line 42
    def accept(visitor)
      visitor.visit_sequence(parslets)
    end

to_s_inner(prec) click to toggle source

    # File lib/parslet/atoms/sequence.rb, line 42
    def to_s_inner(prec)
      parslets.map { |p| p.to_s(prec) }.join(' ')
    end

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

    # File lib/parslet/atoms/sequence.rb, line 22
    def try(source, context, consume_all)
      # Presize an array
      result = Array.new(parslets.size + 1)
      result[0] = :sequence

      parslets.each_with_index do |p, idx|
        child_consume_all = consume_all && (idx == parslets.size-1)
        success, value = p.apply(source, context, child_consume_all)

        unless success
          return context.err(self, source, @error_msgs[:failed], [value])
        end

        result[idx+1] = value
      end

      return succ(result)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.