Class: Code::Parser::Ternary

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

#colonObject



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

def colon
  str(":")
end

#question_markObject



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

def question_mark
  str("?")
end

#rootObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/code/parser/ternary.rb', line 28

def root
  (
    statement.aka(:left) <<
      (
        whitespace? << question_mark << whitespace? <<
          ternary.aka(:middle) <<
          (
            whitespace? << colon << whitespace? << ternary.aka(:right)
          ).maybe
      ).maybe
  )
    .aka(:ternary)
    .then do |output|
      output[:ternary][:middle] ? output : output[:ternary][:left]
    end
end

#statementObject



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

def statement
  ::Code::Parser::Range
end

#ternaryObject



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

def ternary
  ::Code::Parser::Ternary
end

#whitespaceObject



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

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

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end