Class: Parslet::ErrorReporter::Tree
- Inherits:
-
Object
- Object
- Parslet::ErrorReporter::Tree
- 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
-
#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).
-
#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).
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).
35 36 37 38 |
# File 'lib/parslet/error_reporter/tree.rb', line 35 def err(atom, source, , children=nil) position = source.pos Cause.format(source, position, , 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).
51 52 53 54 |
# File 'lib/parslet/error_reporter/tree.rb', line 51 def err_at(atom, source, , pos, children=nil) position = pos Cause.format(source, position, , children) end |