Class: Code::Parser::Call

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

Instance Method Summary collapse

Instance Method Details

#ampersandObject



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

def ampersand
  str("&")
end

#argumentObject



102
103
104
# File 'lib/code/parser/call.rb', line 102

def argument
  keyword_argument | regular_argument
end

#argumentsObject



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

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

#asteriskObject



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

def asterisk
  str("*")
end

#begin_keywordObject



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

def begin_keyword
  str("do") << separator.present
end

#blockObject



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/code/parser/call.rb', line 142

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

#closing_curly_bracketObject



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

def closing_curly_bracket
  str("}")
end

#closing_parenthesisObject



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

def closing_parenthesis
  str(")")
end

#codeObject



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

def code
  Code
end

#code_presentObject



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

def code_present
  Code.new.present
end

#colonObject



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

def colon
  str(":")
end

#commaObject



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

def comma
  str(",")
end

#do_keywordObject



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

def do_keyword
  str("do") << separator.present
end

#end_keywordObject



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

def end_keyword
  str("end") << separator.present
end

#equalObject



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

def equal
  str("=")
end

#keyword_argumentObject



94
95
96
# File 'lib/code/parser/call.rb', line 94

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

#keyword_parameterObject



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

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

#label_nameObject



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

def label_name
  LabelName
end

#nameObject



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

def name
  Name
end

#opening_curly_bracketObject



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

def opening_curly_bracket
  str("{")
end

#opening_parenthesisObject



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

def opening_parenthesis
  str("(")
end

#parameterObject



130
131
132
# File 'lib/code/parser/call.rb', line 130

def parameter
  keyword_parameter | regular_parameter
end

#parametersObject



134
135
136
137
138
139
140
# File 'lib/code/parser/call.rb', line 134

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

#pipeObject



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

def pipe
  str("|")
end

#prefixObject



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

def prefix
  (asterisk << asterisk).aka(:keyword_splat) |
    asterisk.aka(:regular_splat) | ampersand.aka(:block) |
    spread_operator.aka(:spread)
end

#regular_argumentObject



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

def regular_argument
  code_present.aka(:value)
end

#regular_parameterObject



125
126
127
128
# File 'lib/code/parser/call.rb', line 125

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

#rootObject



156
157
158
159
160
161
162
# File 'lib/code/parser/call.rb', line 156

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

#separatorObject



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

def separator
  Name.new.separator
end

#spread_operatorObject



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

def spread_operator
  str("...") | str("..") | str(".")
end

#whiltespace_without_newline?Boolean

Returns:



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

def whiltespace_without_newline?
  Whitespace.new.without_newline.maybe
end

#whitespaceObject



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

def whitespace
  Whitespace
end

#whitespace?Boolean

Returns:



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

def whitespace?
  whitespace.maybe
end