Class: Code::Parser::Function
Instance Method Summary
collapse
Methods inherited from Language
<<, >>, absent, aka, #any, ignore, #inspect, maybe, parse, #parse, repeat, #str, then, #to_s, |
Instance Method Details
#closing_curly_bracket ⇒ Object
52
53
54
|
# File 'lib/code/parser/function.rb', line 52
def closing_curly_bracket
str("}")
end
|
#closing_parenthesis ⇒ Object
28
29
30
|
# File 'lib/code/parser/function.rb', line 28
def closing_parenthesis
str(")")
end
|
8
9
10
|
# File 'lib/code/parser/function.rb', line 8
def code
::Code::Parser::Code
end
|
#code_present ⇒ Object
12
13
14
|
# File 'lib/code/parser/function.rb', line 12
def code_present
::Code::Parser::Code.new.present
end
|
32
33
34
|
# File 'lib/code/parser/function.rb', line 32
def colon
str(":")
end
|
36
37
38
|
# File 'lib/code/parser/function.rb', line 36
def comma
str(",")
end
|
40
41
42
|
# File 'lib/code/parser/function.rb', line 40
def equal
str("=")
end
|
44
45
46
|
# File 'lib/code/parser/function.rb', line 44
def greater
str(">")
end
|
#keyword_parameter ⇒ Object
56
57
58
59
|
# File 'lib/code/parser/function.rb', line 56
def keyword_parameter
name.aka(:name) << whitespace? << colon.aka(:keyword) <<
code_present.aka(:default).maybe
end
|
4
5
6
|
# File 'lib/code/parser/function.rb', line 4
def name
::Code::Parser::Name
end
|
#opening_curly_bracket ⇒ Object
48
49
50
|
# File 'lib/code/parser/function.rb', line 48
def opening_curly_bracket
str("{")
end
|
#opening_parenthesis ⇒ Object
24
25
26
|
# File 'lib/code/parser/function.rb', line 24
def opening_parenthesis
str("(")
end
|
#parameter ⇒ Object
66
67
68
|
# File 'lib/code/parser/function.rb', line 66
def parameter
keyword_parameter | regular_parameter
end
|
#parameters ⇒ Object
70
71
72
73
74
|
# File 'lib/code/parser/function.rb', line 70
def parameters
opening_parenthesis.ignore << whitespace? << parameter.repeat(0, 1) <<
(whitespace? << comma << whitespace? << parameter).repeat <<
whitespace? << closing_parenthesis.ignore.maybe
end
|
#regular_parameter ⇒ Object
61
62
63
64
|
# File 'lib/code/parser/function.rb', line 61
def regular_parameter
name.aka(:name) << whitespace? <<
(equal << whitespace? << code_present.aka(:default)).maybe
end
|
76
77
78
79
80
81
82
|
# File 'lib/code/parser/function.rb', line 76
def root
(
parameters.aka(:parameters) << whitespace? << equal << greater <<
whitespace? << opening_curly_bracket << code.aka(:body) <<
closing_curly_bracket.maybe
).aka(:function) | ::Code::Parser::ChainedCall
end
|
#whitespace ⇒ Object
16
17
18
|
# File 'lib/code/parser/function.rb', line 16
def whitespace
::Code::Parser::Whitespace
end
|
#whitespace? ⇒ Boolean
20
21
22
|
# File 'lib/code/parser/function.rb', line 20
def whitespace?
whitespace.maybe
end
|