Class: Parslet::ErrorReporter::Tree

### Home Classes Methods

### In Files

- lib/parslet/error_reporter/tree.rb

### Parent

Object

### Methods

- #err
- #err_at

### Files

- README

### Class/Module Index

Quicksearch

- Parslet
- Parslet::Atoms
- Parslet::Atoms::Alternative
- Parslet::Atoms::Base
- Parslet::Atoms::CanFlatten
- Parslet::Atoms::Context
- Parslet::Atoms::DSL
- Parslet::Atoms::Entity
- Parslet::Atoms::Lookahead
- Parslet::Atoms::Named
- Parslet::Atoms::Precedence
- Parslet::Atoms::Re
- Parslet::Atoms::Repetition
- 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::Slice
- Parslet::Source
- Parslet::Source::LineCache
- Parslet::Source::RangeSearch
- Parslet::Transform
- Parslet::Transform::Context
- Parslet::UnconsumedInput

No matching classes.

# Parslet::ErrorReporter::Tree

An error reporter has two central methods, one for reporting errors at the current parse position (err) and one for reporting errors at a given parse position (err_at). The reporter can return an object (a 'cause') that will be returned to the caller along with the information that the parse failed.

When reporting errors on the outer levels of your parser, these methods get passed a list of error objects ('causes') from the inner levels. In this default implementation, the inner levels are considered error subtrees and are appended to the generated tree node at each level, thereby constructing an error tree.

This error tree will report in parallel with the grammar structure that failed. A one-to-one correspondence exists between each error in the tree and the parslet atom that produced that error.

The implementor is really free to use these return values as he sees fit. One example would be to return an error state object from these methods that is then updated as errors cascade up the parse derivation tree.

### Public Instance Methods

err(atom, source, message, children=nil) click to toggle source

Produces an error cause that combines the message at the current level with the errors that happened at a level below (children).

@param atom [Parslet::Atoms::Base] parslet that failed @param source [Source] Source that we're using for this parse. (line

    number information...)

@param message [String, Array] Error message at this level. @param children [Array] A list of errors from a deeper level (or nil). @return [Cause] An error tree combining children with message.

    # File lib/parslet/error_reporter/tree.rb, line 35
    def err(atom, source, message, children=nil)
      position = source.pos
      Cause.format(source, position, message, children)
    end

err_at(atom, source, message, pos, children=nil) click to toggle source

Produces an error cause that combines the message at the current level with the errors that happened at a level below (children).

@param atom [Parslet::Atoms::Base] parslet that failed @param source [Source] Source that we're using for this parse. (line

    number information...)

@param message [String, Array] Error message at this level. @param pos [Fixnum] The real position of the error. @param children [Array] A list of errors from a deeper level (or nil). @return [Cause] An error tree combining children with message.

    # File lib/parslet/error_reporter/tree.rb, line 51
    def err_at(atom, source, message, pos, children=nil)
      position = pos
      Cause.format(source, position, message, children)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.