Class: Code::Parser::Rescue

Inherits:
Language show all
Defined in:
lib/code/parser/rescue.rb

Instance Method Summary collapse

Methods inherited from Language

<<, >>, absent, aka, #any, ignore, #inspect, maybe, parse, #parse, repeat, #str, then, #to_s, |

Instance Method Details

#rescue_classObject



8
9
10
# File 'lib/code/parser/rescue.rb', line 8

def rescue_class
  ::Code::Parser::Rescue
end

#rescue_keywordObject



20
21
22
# File 'lib/code/parser/rescue.rb', line 20

def rescue_keyword
  str("rescue")
end

#rootObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/code/parser/rescue.rb', line 24

def root
  (
    statement.aka(:left) <<
      (
        whitespace? << rescue_keyword << whitespace? <<
          rescue_class.aka(:right)
      ).maybe
  )
    .aka(:rescue)
    .then do |output|
      output[:rescue][:right] ? output : output[:rescue][:left]
    end
end

#statementObject



4
5
6
# File 'lib/code/parser/rescue.rb', line 4

def statement
  ::Code::Parser::Ternary
end

#whitespaceObject



12
13
14
# File 'lib/code/parser/rescue.rb', line 12

def whitespace
  ::Code::Parser::Whitespace
end

#whitespace?Boolean

Returns:



16
17
18
# File 'lib/code/parser/rescue.rb', line 16

def whitespace?
  whitespace.maybe
end