Class: Rattler::Parsers::Fail
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::Fail
- Defined in:
- lib/rattler/parsers/fail.rb
Overview
Fail
is a parser that always fails. It can be used to define more useful error messages.
Class Method Summary collapse
-
.[](type, message) ⇒ Fail
Create a new parser that always fails with
message
. - .parsed(results, *_) ⇒ Object
Instance Method Summary collapse
-
#capturing? ⇒ Boolean
false
. -
#parse(*_) ⇒ Object
Always return
false
.
Methods inherited from Parser
#&, #>>, #capturing_decidable?, #labeled?, #list, #one_or_more, #optional, #repeat, #semantic?, #sequence?, #skip, #variable_capture_count?, #with_ws, #zero_or_more, #|
Methods included from Runtime::ParserHelper
Methods inherited from Util::Node
#==, #[], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #initialize, #inspect, #method_missing, #name, #pretty_print, #pretty_print_cycle, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children
Constructor Details
This class inherits a constructor from Rattler::Util::Node
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rattler::Util::Node
Class Method Details
.[](type, message) ⇒ Fail
Create a new parser that always fails with message
. The type
should be one of :expr
, :rule
or :parse
, indicating to simply fail, to cause its parse rule to fail, or to cause the entire parse to fail, respectively.
29 30 31 |
# File 'lib/rattler/parsers/fail.rb', line 29 def self.[](type, ) self.new(:type => type, :message => ) end |
.parsed(results, *_) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rattler/parsers/fail.rb', line 10 def self.parsed(results, *_) #:nodoc: keyword, arg_expr = results arg = eval(arg_expr) case keyword when 'fail' then self[:expr, arg] when 'fail_rule' then self[:rule, arg] when 'fail_parse' then self[:parse, arg] when 'expected' then self[:expr, arg.to_sym] end end |
Instance Method Details
#capturing? ⇒ Boolean
Returns false
.
46 47 48 |
# File 'lib/rattler/parsers/fail.rb', line 46 def capturing? false end |
#parse(*_) ⇒ Object
Always return false
. The parser code generated for this parser should use message
as the failure message, and should cause its parse rule to fail if type
is :rule
or cause the entire parse to fail if type
is :parse
41 42 43 |
# File 'lib/rattler/parsers/fail.rb', line 41 def parse(*_) false end |