Class: Code::Parser::Call

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

Instance Method Summary collapse

Instance Method Details

#ampersandObject



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

def ampersand
  str("&")
end

#argumentObject



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

def argument
  keyword_argument | regular_argument
end

#argumentsObject



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

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

#asteriskObject



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

def asterisk
  str("*")
end

#begin_keywordObject



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

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

#blockObject



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/code/parser/call.rb', line 138

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



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

def closing_curly_bracket
  str("}")
end

#closing_parenthesisObject



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

def closing_parenthesis
  str(")")
end

#codeObject



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

def code
  Code
end

#code_presentObject



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

def code_present
  Code.new.present
end

#colonObject



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

def colon
  str(":")
end

#commaObject



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

def comma
  str(",")
end

#do_keywordObject



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

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

#end_keywordObject



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

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

#equalObject



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

def equal
  str("=")
end

#keyword_argumentObject



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

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

#keyword_parameterObject



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

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



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

def opening_curly_bracket
  str("{")
end

#opening_parenthesisObject



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

def opening_parenthesis
  str("(")
end

#parameterObject



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

def parameter
  keyword_parameter | regular_parameter
end

#parametersObject



130
131
132
133
134
135
136
# File 'lib/code/parser/call.rb', line 130

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

#pipeObject



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

def pipe
  str("|")
end

#prefixObject



110
111
112
113
114
# File 'lib/code/parser/call.rb', line 110

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

#regular_argumentObject



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

def regular_argument
  code_present.aka(:value)
end

#regular_parameterObject



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

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

#rootObject



152
153
154
155
156
157
# File 'lib/code/parser/call.rb', line 152

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

#separatorObject



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

def separator
  Name.new.separator
end

#spread_operatorObject



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

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

#whiltespace_without_newline?Boolean



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

def whiltespace_without_newline?
  Whitespace.new.without_newline.maybe
end

#whitespaceObject



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

def whitespace
  Whitespace
end

#whitespace?Boolean



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

def whitespace?
  whitespace.maybe
end