Class: Code::Parser::Call

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

Instance Method Summary collapse

Instance Method Details

#argumentObject



74
75
76
# File 'lib/code/parser/call.rb', line 74

def argument
  keyword_argument | regular_argument
end

#argumentsObject



78
79
80
81
82
83
84
# File 'lib/code/parser/call.rb', line 78

def arguments
  opening_parenthesis.ignore << whitespace? <<
    (
      whitespace? << argument <<
        (whitespace? << comma << whitespace?).maybe
    ).repeat << whitespace? << closing_parenthesis.ignore.maybe
end

#blockObject



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/code/parser/call.rb', line 108

def block
  (
    do_keyword << whitespace? << parameters.aka(:parameters).maybe <<
      code.aka(:body) << end_keyword.maybe
  ) |
    (
      opening_curly_bracket << whitespace? <<
        parameters.aka(:parameters).maybe << code.aka(:body) <<
        closing_curly_bracket.maybe
    )
end

#closing_curly_bracketObject



46
47
48
# File 'lib/code/parser/call.rb', line 46

def closing_curly_bracket
  str("}")
end

#closing_parenthesisObject



54
55
56
# File 'lib/code/parser/call.rb', line 54

def closing_parenthesis
  str(")")
end

#codeObject



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

def code
  Code
end

#code_presentObject



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

def code_present
  Code.new.present
end

#colonObject



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

def colon
  str(":")
end

#commaObject



30
31
32
# File 'lib/code/parser/call.rb', line 30

def comma
  str(",")
end

#do_keywordObject



58
59
60
# File 'lib/code/parser/call.rb', line 58

def do_keyword
  str("do")
end

#end_keywordObject



62
63
64
# File 'lib/code/parser/call.rb', line 62

def end_keyword
  str("end")
end

#equalObject



38
39
40
# File 'lib/code/parser/call.rb', line 38

def equal
  str("=")
end

#keyword_argumentObject



66
67
68
# File 'lib/code/parser/call.rb', line 66

def keyword_argument
  name.aka(:name) << whitespace? << colon << code.aka(:value)
end

#keyword_parameterObject



86
87
88
89
# File 'lib/code/parser/call.rb', line 86

def keyword_parameter
  name.aka(:name) << whitespace? << colon.aka(:keyword) <<
    code_present.aka(:default).maybe
end

#nameObject



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

def name
  Name
end

#opening_curly_bracketObject



42
43
44
# File 'lib/code/parser/call.rb', line 42

def opening_curly_bracket
  str("{")
end

#opening_parenthesisObject



50
51
52
# File 'lib/code/parser/call.rb', line 50

def opening_parenthesis
  str("(")
end

#parameterObject



96
97
98
# File 'lib/code/parser/call.rb', line 96

def parameter
  keyword_parameter | regular_parameter
end

#parametersObject



100
101
102
103
104
105
106
# File 'lib/code/parser/call.rb', line 100

def parameters
  pipe.ignore << whitespace? <<
    (
      whitespace? << parameter <<
        (whitespace? << comma << whitespace?).maybe
    ).repeat << (whitespace? << pipe.ignore).maybe
end

#pipeObject



34
35
36
# File 'lib/code/parser/call.rb', line 34

def pipe
  str("|")
end

#regular_argumentObject



70
71
72
# File 'lib/code/parser/call.rb', line 70

def regular_argument
  code_present.aka(:value)
end

#regular_parameterObject



91
92
93
94
# File 'lib/code/parser/call.rb', line 91

def regular_parameter
  name.aka(:name) << whitespace? <<
    (equal << whitespace? << code_present.aka(:default)).maybe
end

#rootObject



120
121
122
123
124
125
# File 'lib/code/parser/call.rb', line 120

def root
  (
    name.aka(:name) << (whitespace? << arguments.aka(:arguments)).maybe <<
      (whitespace? << block.aka(:block)).maybe
  ).aka(:call)
end

#whitespaceObject



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

def whitespace
  Whitespace
end

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end