Class: Code::Parser::IfModifier

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

#if_keywordObject



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

def if_keyword
  str("if")
end

#if_modifierObject



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

def if_modifier
  ::Code::Parser::IfModifier
end

#operatorObject



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

def operator
  if_keyword | unless_keyword | while_keyword | until_keyword
end

#rootObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/code/parser/if_modifier.rb', line 40

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

#statementObject



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

def statement
  ::Code::Parser::OrKeyword
end

#unless_keywordObject



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

def unless_keyword
  str("unless")
end

#until_keywordObject



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

def until_keyword
  str("until")
end

#while_keywordObject



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

def while_keyword
  str("while")
end

#whitespaceObject



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

def whitespace
  ::Code::Parser::Whitespace.new.without_newline
end

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end