Class: Code::Parser::If

Inherits:
Language show all
Defined in:
lib/code/parser/if.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

#codeObject



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

def code
  ::Code::Parser::Code
end

#else_keywordObject



36
37
38
# File 'lib/code/parser/if.rb', line 36

def else_keyword
  str("else")
end

#elsif_keywordObject



32
33
34
# File 'lib/code/parser/if.rb', line 32

def elsif_keyword
  str("elsif")
end

#end_keywordObject



40
41
42
# File 'lib/code/parser/if.rb', line 40

def end_keyword
  str("end")
end

#if_classObject



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

def if_class
  ::Code::Parser::If
end

#if_keywordObject



24
25
26
# File 'lib/code/parser/if.rb', line 24

def if_keyword
  str("if")
end

#rootObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/code/parser/if.rb', line 44

def root
  (
    (if_keyword | unless_keyword).aka(:first_operator) << whitespace <<
      statement.aka(:first_statement) << code.aka(:first_body) <<
      (
        (
          elsif_keyword.aka(:operator) << whitespace <<
            statement.aka(:statement) << code.aka(:body)
        ) |
          (
            else_keyword << whitespace <<
              (if_keyword | unless_keyword).aka(:operator) <<
              whitespace << statement.aka(:statement) << code.aka(:body)
          ) | (else_keyword.aka(:operator) << code.aka(:body))
      ).repeat(1).aka(:elses).maybe << end_keyword.maybe
  ).aka(:if) | statement
end

#statementObject



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

def statement
  ::Code::Parser::IfModifier
end

#unless_keywordObject



28
29
30
# File 'lib/code/parser/if.rb', line 28

def unless_keyword
  str("unless")
end

#whitespaceObject



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

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

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end