Class: Code::Parser::Call

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

Instance Method Summary collapse

Instance Method Details

#ampersandObject



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

def ampersand
  str("&")
end

#argumentObject



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

def argument
  keyword_argument | regular_argument
end

#argumentsObject



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

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

#asteriskObject



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

def asterisk
  str("*")
end

#begin_keywordObject



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

def begin_keyword
  str("do")
end

#blockObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/code/parser/call.rb', line 130

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



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



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

def end_keyword
  str("end")
end

#equalObject



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

def equal
  str("=")
end

#keyword_argumentObject



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

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

#keyword_parameterObject



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

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



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

def parameter
  keyword_parameter | regular_parameter
end

#parametersObject



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

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

#prefixObject



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

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

#regular_argumentObject



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

def regular_argument
  code_present.aka(:value)
end

#regular_parameterObject



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

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

#rootObject



144
145
146
147
148
149
# File 'lib/code/parser/call.rb', line 144

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

#spread_operatorObject



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

def spread_operator
  str("...") | str("..") | str(".")
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