Class: Parslet::ErrorReporter::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/parslet/error_reporter/tree.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#err(atom, source, message, children = nil) ⇒ Cause

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

Parameters:

  • atom (Parslet::Atoms::Base)

    parslet that failed

  • source (Source)

    Source that we’re using for this parse. (line number information…)

  • message (String, Array)

    Error message at this level.

  • children (Array) (defaults to: nil)

    A list of errors from a deeper level (or nil).

Returns:

  • (Cause)

    An error tree combining children with message.



35
36
37
38
# 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) ⇒ Cause

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

Parameters:

  • atom (Parslet::Atoms::Base)

    parslet that failed

  • source (Source)

    Source that we’re using for this parse. (line number information…)

  • message (String, Array)

    Error message at this level.

  • pos (Fixnum)

    The real position of the error.

  • children (Array) (defaults to: nil)

    A list of errors from a deeper level (or nil).

Returns:

  • (Cause)

    An error tree combining children with message.



51
52
53
54
# 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

#succ(source) ⇒ Object

Notification that an expression successfully parsed not used, see ErrorReporter::Contextual



58
59
# File 'lib/parslet/error_reporter/tree.rb', line 58

def succ(source)
end