Exception: Parslet::ParseFailed
- Inherits:
-
StandardError
- Object
- StandardError
- Parslet::ParseFailed
- Defined in:
- lib/parslet.rb
Overview
Raised when the parse failed to match. It contains the message that should be presented to the user. More details can be extracted from the exceptions #parse_failure_cause member: It contains an instance of Cause that stores all the details of your failed parse in a tree structure.
begin
parslet.parse(str)
rescue Parslet::ParseFailed => failure
puts failure.parse_failure_cause.ascii_tree
end
Alternatively, you can just require ‘parslet/convenience’ and call the method #parse_with_debug instead of #parse. This method will never raise and print error trees to stdout.
require 'parslet/convenience'
parslet.parse_with_debug(str)
Instance Attribute Summary collapse
-
#parse_failure_cause ⇒ Parslet::Cause
readonly
Why the parse failed.
Instance Method Summary collapse
-
#initialize(message, parse_failure_cause = nil) ⇒ ParseFailed
constructor
A new instance of ParseFailed.
Constructor Details
#initialize(message, parse_failure_cause = nil) ⇒ ParseFailed
Returns a new instance of ParseFailed.
75 76 77 78 |
# File 'lib/parslet.rb', line 75 def initialize(, parse_failure_cause=nil) super() @parse_failure_cause = parse_failure_cause end |
Instance Attribute Details
#parse_failure_cause ⇒ Parslet::Cause (readonly)
Why the parse failed.
83 84 85 |
# File 'lib/parslet.rb', line 83 def parse_failure_cause @parse_failure_cause end |