Class: LazyPP::Parser
- Inherits:
-
Parslet::Parser
- Object
- Parslet::Parser
- LazyPP::Parser
show all
- Includes:
- ParserMethods
- Defined in:
- lib/readable-cpp/parser.rb
Instance Method Summary
collapse
#`, #comma_list, included, #join
Instance Method Details
#brackets(rule) ⇒ Object
5
6
7
|
# File 'lib/readable-cpp/parser.rb', line 5
def brackets(rule)
l_bracket >> spaced?(rule) >> r_bracket
end
|
#brackets?(rule) ⇒ Boolean
8
9
10
|
# File 'lib/readable-cpp/parser.rb', line 8
def brackets?(rule)
brackets(rule) | rule
end
|
#derived_english ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/readable-cpp/parser.rb', line 145
rule(:derived_english) {
join(
const.as(:const) >> (space >> (ref_eng|ptr_eng)).present? |
ptr_eng.as(:ptr) |
ref_eng.as(:ref) |
str(?[)>> spaced?(expr.maybe.as(:array)) >> str(?]) |
`array of` >> (
(space >> int.as(:array) | space? >> parens(expr).as(:array)) |
any.present?.as(:array_unsized)
) |
(
`function` >> `s`.maybe >> (space >> `taking`).maybe >>
(space? >> func_sig_args | space >> func_sig_args_innards) >>
space? >> (str('->') | returnsing)
) |
func_sig_args >> space? >> (str('->') | returnsing),
space
)
}
|
#func_sig_args_innards ⇒ Object
488
489
490
491
|
# File 'lib/readable-cpp/parser.rb', line 488
rule(:func_sig_args_innards) { ( func_sig_args_innards__ ).as(:func_sig)
}
|
#func_sig_nosave ⇒ Object
func_sig.present? didnt work, but this does..
458
459
460
461
462
463
|
# File 'lib/readable-cpp/parser.rb', line 458
rule(:func_sig_nosave) { (specifiers >> space?).maybe >> (storage >> space?).maybe >>
func_sig_args >>
spaced?(str('->')) >> type
}
|
#infix_expr(left, op, right) ⇒ Object
16 is the entry point for expressions. 17 is available from inside parens
757
758
759
760
|
# File 'lib/readable-cpp/parser.rb', line 757
def infix_expr left, op, right
( left.as(:left) >> spaced?(op.as(:op)) >> right.as(:right)
).as(:infix)
end
|
#paren_tagged(rule, tag = :parens) ⇒ Object
27
28
29
|
# File 'lib/readable-cpp/parser.rb', line 27
def paren_tagged(rule, tag=:parens)
parens(rule.as(tag))
end
|
#paren_tagged?(rule, tag) ⇒ Boolean
30
31
32
33
|
# File 'lib/readable-cpp/parser.rb', line 30
def paren_tagged?(rule, tag)
paren_tagged(rule,tag) |
rule
end
|
#parens(rule) ⇒ Object
21
22
23
|
# File 'lib/readable-cpp/parser.rb', line 21
def parens(rule)
l_paren >> spaced?(rule) >> r_paren
end
|
#parens?(rule) ⇒ Boolean
24
25
26
|
# File 'lib/readable-cpp/parser.rb', line 24
def parens?(rule)
parents(rule) | rule
end
|
#parens_oder_spacen(rule) ⇒ Object
17
18
19
20
|
# File 'lib/readable-cpp/parser.rb', line 17
def parens_oder_spacen(rule)
parens(rule) |
space >> rule
end
|
TODO save comments in program
49
50
51
|
# File 'lib/readable-cpp/parser.rb', line 49
rule(:space_comments) {
(.as(:comment) | match['\s'].repeat(1)).repeat(1)
}
|
#spaced(rule) ⇒ Object
11
12
13
|
# File 'lib/readable-cpp/parser.rb', line 11
def spaced(rule)
space >> rule >> space
end
|
#spaced?(rule) ⇒ Boolean
14
15
16
|
# File 'lib/readable-cpp/parser.rb', line 14
def spaced?(rule)
space? >> rule >> space?
end
|
#var_decl(terminator = semicolon_terminal) ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/readable-cpp/parser.rb', line 245
def var_decl(terminator = semicolon_terminal)
`var` >> space >>
join(
( var_decl_assign | var_decl_initialize
).as(:var_decl),
spaced?(comma)
).as(:stmts) >> terminator
end
|