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
Always
false
. -
#parse(scanner, rules, labeled = {}) ⇒ Object
Always return
false
.
Methods inherited from Parser
#&, #labeled?, #one_or_more, #optional, #skip, #variable_capture_count?, #with_ws, #zero_or_more, #|
Methods inherited from Util::Node
#==, #[], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #initialize, #inspect, #method_missing, #name, #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.
38 39 40 |
# File 'lib/rattler/parsers/fail.rb', line 38 def self.[](type, ) self.new(:type => type, :message => ) end |
.parsed(results, *_) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rattler/parsers/fail.rb', line 20 def self.parsed(results, *_) #:nodoc: keyword, = results = eval() case keyword when 'fail' then self[:expr, ] when 'fail_rule' then self[:rule, ] when 'fail_parse' then self[:parse, ] end end |
Instance Method Details
#capturing? ⇒ Boolean
Always false
56 57 58 |
# File 'lib/rattler/parsers/fail.rb', line 56 def capturing? false end |
#parse(scanner, rules, labeled = {}) ⇒ 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 type
is :parse
50 51 52 |
# File 'lib/rattler/parsers/fail.rb', line 50 def parse(scanner, rules, labeled = {}) false end |