Class: Parslet::Atoms::Dynamic

### Home Classes Methods

### In Files

- lib/parslet/atoms/dynamic.rb

### Parent

Parslet::Atoms::Base

### Methods

- ::new
- #cached?
- #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::Dynamic

Evaluates a block at parse time. The result from the block must be a parser (something which implements apply). In the first case, the parser will then be applied to the input, creating the result.

Dynamic parses are never cached.

Example:

    dynamic { rand < 0.5 ? str('a') : str('b') }

### Attributes

block[R]

### Public Class Methods

new(block) click to toggle source

    # File lib/parslet/atoms/dynamic.rb, line 13
    def initialize(block)
      @block = block
    end

### Public Instance Methods

cached?() click to toggle source

    # File lib/parslet/atoms/dynamic.rb, line 17
    def cached?
      false
    end

to_s_inner(prec) click to toggle source

    # File lib/parslet/atoms/dynamic.rb, line 28
    def to_s_inner(prec)
      "dynamic { ... }"
    end

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

    # File lib/parslet/atoms/dynamic.rb, line 21
    def try(source, context, consume_all)
      result = block.call(source, context)

      # Result is a parslet atom.
      return result.apply(source, context, consume_all)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.