Class: Code::Parser::Dictionnary

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

#closing_curly_bracketObject



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

def closing_curly_bracket
  str("}")
end

#codeObject



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

def code
  ::Code::Parser::Code.new.present
end

#colonObject



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

def colon
  str(":")
end

#commaObject



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

def comma
  str(",")
end

#equalObject



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

def equal
  str("=")
end

#greaterObject



44
45
46
# File 'lib/code/parser/dictionnary.rb', line 44

def greater
  str(">")
end

#key_valueObject



48
49
50
51
52
53
54
55
# File 'lib/code/parser/dictionnary.rb', line 48

def key_value
  (name.aka(:name) << colon << code.aka(:value)) |
    (statement.aka(:statement) << colon << code.aka(:value)) |
    (
      statement.aka(:statement) << whitespace? << equal << greater <<
        code.aka(:value)
    )
end

#nameObject



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

def name
  ::Code::Parser::Name
end

#opening_curly_bracketObject



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

def opening_curly_bracket
  str("{")
end

#rootObject



57
58
59
60
61
62
63
64
# File 'lib/code/parser/dictionnary.rb', line 57

def root
  (
    opening_curly_bracket.ignore << whitespace? <<
      key_value.repeat(0, 1) <<
      (whitespace? << comma << whitespace? << key_value).repeat <<
      (whitespace? << closing_curly_bracket.ignore).maybe
  ).aka(:dictionnary) | ::Code::Parser::List
end

#statementObject



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

def statement
  ::Code::Parser::Statement
end

#whitespaceObject



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

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

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end