Class: Code::Parser::Call

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

#argumentObject



72
73
74
# File 'lib/code/parser/call.rb', line 72

def argument
  keyword_argument | regular_argument
end

#argumentsObject



76
77
78
79
80
# File 'lib/code/parser/call.rb', line 76

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

#blockObject



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/code/parser/call.rb', line 102

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



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

def closing_curly_bracket
  str("}")
end

#closing_parenthesisObject



52
53
54
# File 'lib/code/parser/call.rb', line 52

def closing_parenthesis
  str(")")
end

#codeObject



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

def code
  ::Code::Parser::Code
end

#code_presentObject



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

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

#colonObject



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

def colon
  str(":")
end

#commaObject



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

def comma
  str(",")
end

#do_keywordObject



56
57
58
# File 'lib/code/parser/call.rb', line 56

def do_keyword
  str("do")
end

#end_keywordObject



60
61
62
# File 'lib/code/parser/call.rb', line 60

def end_keyword
  str("end")
end

#equalObject



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

def equal
  str("=")
end

#keyword_argumentObject



64
65
66
# File 'lib/code/parser/call.rb', line 64

def keyword_argument
  name.aka(:name) << colon << code_present.aka(:value)
end

#keyword_parameterObject



82
83
84
85
# File 'lib/code/parser/call.rb', line 82

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

#nameObject



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

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

#opening_curly_bracketObject



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

def opening_curly_bracket
  str("{")
end

#opening_parenthesisObject



48
49
50
# File 'lib/code/parser/call.rb', line 48

def opening_parenthesis
  str("(")
end

#parameterObject



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

def parameter
  keyword_parameter | regular_parameter
end

#parametersObject



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

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

#pipeObject



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

def pipe
  str("|")
end

#regular_argumentObject



68
69
70
# File 'lib/code/parser/call.rb', line 68

def regular_argument
  code_present.aka(:value)
end

#regular_parameterObject



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

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

#rootObject



114
115
116
117
118
119
# File 'lib/code/parser/call.rb', line 114

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

#whitespaceObject



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

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

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end