Class: Code::Parser::Ternary

Inherits:
Language
  • Object
show all
Defined in:
lib/code/parser/ternary.rb

Instance Method Summary collapse

Instance Method Details

#colonObject



26
27
28
# File 'lib/code/parser/ternary.rb', line 26

def colon
  str(":")
end

#question_markObject



22
23
24
# File 'lib/code/parser/ternary.rb', line 22

def question_mark
  str("?")
end

#rootObject



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

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



6
7
8
# File 'lib/code/parser/ternary.rb', line 6

def statement
  Range
end

#ternaryObject



10
11
12
# File 'lib/code/parser/ternary.rb', line 10

def ternary
  Ternary
end

#whitespaceObject



14
15
16
# File 'lib/code/parser/ternary.rb', line 14

def whitespace
  Whitespace
end

#whitespace?Boolean

Returns:



18
19
20
# File 'lib/code/parser/ternary.rb', line 18

def whitespace?
  whitespace.maybe
end