Class: Parser::Builders::Default
- Inherits:
-
Object
- Object
- Parser::Builders::Default
- Defined in:
- lib/parser/builders/default.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
- #__ENCODING__(token) ⇒ Object
- #__FILE__(token) ⇒ Object
- #__LINE__(token) ⇒ Object
- #accessible(node) ⇒ Object
-
#alias(token, to, from) ⇒ Object
Aliasing.
- #arg(token) ⇒ Object
-
#arg_expr(expr) ⇒ Object
Ruby 1.8 block arguments.
-
#args(begin_t, args, end_t) ⇒ Object
Formal arguments.
-
#array(begin_t, elements, end_t) ⇒ Object
Arrays.
- #assign(lhs, token, rhs) ⇒ Object
-
#assignable(node) ⇒ Object
Assignment.
- #associate(begin_t, pairs, end_t) ⇒ Object
- #attr_asgn(receiver, dot_t, selector_t) ⇒ Object
- #back_ref(token) ⇒ Object
-
#begin(begin_t, body, end_t) ⇒ Object
Exception handling.
- #begin_body(compound_stmt, rescue_bodies = [], else_t = nil, else_ = nil, ensure_t = nil, ensure_ = nil) ⇒ Object
- #binary_op(receiver, token, arg) ⇒ Object
- #block(method_call, begin_t, args, body, end_t) ⇒ Object
- #block_pass(amper_t, arg) ⇒ Object
- #blockarg(amper_t, token) ⇒ Object
- #blockarg_expr(amper_t, expr) ⇒ Object
- #call_lambda(lambda_t) ⇒ Object
-
#call_method(receiver, dot_t, selector_t, begin_t = nil, args = [], end_t = nil) ⇒ Object
Method calls.
- #case(case_t, expr, body, end_t) ⇒ Object
- #compstmt(statements) ⇒ Object
-
#condition(cond_t, cond, then_t, if_true, else_t, if_false, end_t) ⇒ Object
Conditionals.
- #condition_mod(if_true, if_false, cond_t, cond) ⇒ Object
- #const(token) ⇒ Object
- #const_fetch(scope, t_colon2, token) ⇒ Object
- #const_global(t_colon3, token) ⇒ Object
- #cvar(token) ⇒ Object
-
#def_class(class_t, name, lt_t, superclass, body, end_t) ⇒ Object
Class and module definition.
-
#def_method(def_t, name, args, body, end_t, comments) ⇒ Object
Method (un)definition.
- #def_module(module_t, name, body, end_t) ⇒ Object
- #def_sclass(class_t, lshft_t, expr, body, end_t) ⇒ Object
- #def_singleton(def_t, definee, dot_t, name, args, body, end_t, comments) ⇒ Object
- #false(token) ⇒ Object
- #float(token, negate = false) ⇒ Object
- #for(for_t, iterator, in_t, iteratee, do_t, body, end_t) ⇒ Object
- #gvar(token) ⇒ Object
- #ident(token) ⇒ Object
- #index(receiver, lbrack_t, indexes, rbrack_t) ⇒ Object
- #index_asgn(receiver, lbrack_t, indexes, rbrack_t) ⇒ Object
-
#integer(token, negate = false) ⇒ Object
Numerics.
- #ivar(token) ⇒ Object
- #keyword_cmd(type, token, lparen_t = nil, args = [], rparen_t = nil) ⇒ Object
-
#logical_op(type, lhs, token, rhs) ⇒ Object
Logical operations: and, or.
-
#loop(loop_t, cond, do_t, body, end_t) ⇒ Object
Loops.
- #loop_mod(body, loop_t, cond) ⇒ Object
- #multi_assign(lhs, eql_t, rhs) ⇒ Object
- #multi_lhs(begin_t, items, end_t) ⇒ Object
-
#nil(token) ⇒ Object
Singletons.
- #not_op(token, receiver = nil) ⇒ Object
- #nth_ref(token) ⇒ Object
- #op_assign(lhs, operator_t, rhs) ⇒ Object
- #optarg(token, eql_t, value) ⇒ Object
-
#pair(key, assoc_t, value) ⇒ Object
Hashes.
- #pair_list_18(list) ⇒ Object
-
#parenthesize(begin_t, expr, end_t) ⇒ Object
Expression grouping.
- #postexe(postexe_t, lbrace_t, compstmt, rbrace_t) ⇒ Object
-
#preexe(preexe_t, lbrace_t, compstmt, rbrace_t) ⇒ Object
BEGIN, END.
- #range_exclusive(lhs, token, rhs) ⇒ Object
-
#range_inclusive(lhs, token, rhs) ⇒ Object
Ranges.
- #regexp_compose(begin_t, parts, end_t, options) ⇒ Object
-
#regexp_options(token) ⇒ Object
Regular expressions.
- #rescue_body(rescue_t, exc_list, assoc_t, exc_var, then_t, compound_stmt) ⇒ Object
-
#self(token) ⇒ Object
Access.
- #shadowarg(token) ⇒ Object
- #splat(star_t, arg = nil) ⇒ Object
- #splatarg(star_t, token = nil) ⇒ Object
- #splatarg_expr(star_t, expr = nil) ⇒ Object
-
#string(token) ⇒ Object
Strings.
- #string_compose(begin_t, parts, end_t) ⇒ Object
-
#symbol(token) ⇒ Object
Symbols.
- #symbol_compose(begin_t, parts, end_t) ⇒ Object
- #ternary(cond, question_t, if_true, colon_t, if_false) ⇒ Object
- #true(token) ⇒ Object
- #unary_op(token, receiver) ⇒ Object
- #undef_method(token, names) ⇒ Object
-
#when(when_t, patterns, then_t, body) ⇒ Object
Case matching.
- #words_compose(begin_t, parts, end_t) ⇒ Object
-
#xstring_compose(begin_t, parts, end_t) ⇒ Object
Executable strings.
Instance Attribute Details
#parser ⇒ Object
Returns the value of attribute parser.
4 5 6 |
# File 'lib/parser/builders/default.rb', line 4 def parser @parser end |
Instance Method Details
#__ENCODING__(token) ⇒ Object
191 192 193 |
# File 'lib/parser/builders/default.rb', line 191 def __ENCODING__(token) t(token, :__ENCODING__) end |
#__FILE__(token) ⇒ Object
50 51 52 |
# File 'lib/parser/builders/default.rb', line 50 def __FILE__(token) t(token, :__FILE__) end |
#__LINE__(token) ⇒ Object
25 26 27 |
# File 'lib/parser/builders/default.rb', line 25 def __LINE__(token) t(token, :__LINE__) end |
#accessible(node) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/parser/builders/default.rb', line 153 def accessible(node) case node.type when :__FILE__ node.updated(:str, [ node.src.expression.source_buffer.name ]) when :__LINE__ node.updated(:int, [ node.src.expression.line ]) when :__ENCODING__ s(:const, s(:const, nil, :Encoding), :UTF_8) when :ident name, = *node if @parser.static_env.declared?(name) node.updated(:lvar) else name, = *node node.updated(:send, [ nil, name ]) end else node end end |
#alias(token, to, from) ⇒ Object
Aliasing
340 341 342 |
# File 'lib/parser/builders/default.rb', line 340 def alias(token, to, from) t(token, :alias, to, from) end |
#arg(token) ⇒ Object
367 368 369 |
# File 'lib/parser/builders/default.rb', line 367 def arg(token) t(token, :arg, value(token).to_sym) end |
#arg_expr(expr) ⇒ Object
Ruby 1.8 block arguments
393 394 395 396 397 398 399 |
# File 'lib/parser/builders/default.rb', line 393 def arg_expr(expr) if expr.type == :lvasgn expr.updated(:arg) else s(:arg_expr, expr) end end |
#args(begin_t, args, end_t) ⇒ Object
Formal arguments
363 364 365 |
# File 'lib/parser/builders/default.rb', line 363 def args(begin_t, args, end_t) s(:args, *args) end |
#array(begin_t, elements, end_t) ⇒ Object
Arrays
82 83 84 |
# File 'lib/parser/builders/default.rb', line 82 def array(begin_t, elements, end_t) s(:array, *elements) end |
#assign(lhs, token, rhs) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/parser/builders/default.rb', line 242 def assign(lhs, token, rhs) case lhs.type when :lvasgn, :masgn, :gvasgn, :ivasgn, :cvdecl, :cvasgn, :cdecl, :send lhs << rhs when :const (lhs << rhs).updated(:cdecl) else raise NotImplementedError, "build assign #{lhs.inspect}" end end |
#assignable(node) ⇒ Object
Assignment
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/parser/builders/default.rb', line 199 def assignable(node) case node.type when :cvar if @parser.in_def? node.updated(:cvasgn) else node.updated(:cvdecl) end when :ivar node.updated(:ivasgn) when :gvar node.updated(:gvasgn) when :const if @parser.in_def? = ERRORS[:dynamic_const] diagnostic :error, , node.src.expression end node.updated(:cdecl) when :ident name, = *node @parser.static_env.declare(name) node.updated(:lvasgn) when :nil, :self, :true, :false, :__FILE__, :__LINE__, :__ENCODING__ = ERRORS[:invalid_assignment] diagnostic :error, , node.src.expression when :back_ref, :nth_ref = ERRORS[:backref_assignment] diagnostic :error, , node.src.expression else raise NotImplementedError, "build_assignable #{node.inspect}" end end |
#associate(begin_t, pairs, end_t) ⇒ Object
117 118 119 |
# File 'lib/parser/builders/default.rb', line 117 def associate(begin_t, pairs, end_t) s(:hash, *pairs) end |
#attr_asgn(receiver, dot_t, selector_t) ⇒ Object
456 457 458 459 460 461 |
# File 'lib/parser/builders/default.rb', line 456 def attr_asgn(receiver, dot_t, selector_t) method_name = (value(selector_t) + '=').to_sym # Incomplete method call. s(:send, receiver, method_name) end |
#back_ref(token) ⇒ Object
150 |
# File 'lib/parser/builders/default.rb', line 150 def back_ref(token); t(token, :back_ref, value(token).to_sym); end |
#begin(begin_t, body, end_t) ⇒ Object
Exception handling
559 560 561 |
# File 'lib/parser/builders/default.rb', line 559 def begin(begin_t, body, end_t) body end |
#begin_body(compound_stmt, rescue_bodies = [], else_t = nil, else_ = nil, ensure_t = nil, ensure_ = nil) ⇒ Object
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 |
# File 'lib/parser/builders/default.rb', line 569 def begin_body(compound_stmt, rescue_bodies=[], else_t=nil, else_=nil, ensure_t=nil, ensure_=nil) if rescue_bodies.any? if else_t compound_stmt = s(:rescue, compound_stmt, *(rescue_bodies << else_)) else compound_stmt = s(:rescue, compound_stmt, *(rescue_bodies << nil)) end end if ensure_t compound_stmt = s(:ensure, compound_stmt, ensure_) end compound_stmt end |
#binary_op(receiver, token, arg) ⇒ Object
472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/parser/builders/default.rb', line 472 def binary_op(receiver, token, arg) if @parser.version == 18 if value(token) == '!=' return s(:not, s(:send, receiver, :==, arg)) elsif value(token) == '!~' return s(:not, s(:send, receiver, :=~, arg)) end end s(:send, receiver, value(token).to_sym, arg) end |
#block(method_call, begin_t, args, body, end_t) ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/parser/builders/default.rb', line 436 def block(method_call, begin_t, args, body, end_t) receiver, selector, *call_args = *method_call last_arg = call_args.last if last_arg && last_arg.type == :block_pass # TODO uncomment when source maps are ready # diagnostic :error, :block_and_blockarg, # last_arg.src.expression diagnostic :error, ERRORS[:block_and_blockarg], last_arg.children.last.src.expression end s(:block, method_call, args, body) end |
#block_pass(amper_t, arg) ⇒ Object
452 453 454 |
# File 'lib/parser/builders/default.rb', line 452 def block_pass(amper_t, arg) s(:block_pass, arg) end |
#blockarg(amper_t, token) ⇒ Object
387 388 389 |
# File 'lib/parser/builders/default.rb', line 387 def blockarg(amper_t, token) s(:blockarg, value(token).to_sym) end |
#blockarg_expr(amper_t, expr) ⇒ Object
411 412 413 414 415 416 417 |
# File 'lib/parser/builders/default.rb', line 411 def blockarg_expr(amper_t, expr) if expr.type == :lvasgn expr.updated(:blockarg) else s(:blockarg_expr, expr) end end |
#call_lambda(lambda_t) ⇒ Object
432 433 434 |
# File 'lib/parser/builders/default.rb', line 432 def call_lambda(lambda_t) s(:send, nil, :lambda) end |
#call_method(receiver, dot_t, selector_t, begin_t = nil, args = [], end_t = nil) ⇒ Object
Method calls
423 424 425 426 427 428 429 430 |
# File 'lib/parser/builders/default.rb', line 423 def call_method(receiver, dot_t, selector_t, begin_t=nil, args=[], end_t=nil) if selector_t.nil? s(:send, receiver, :call, *args) else s(:send, receiver, value(selector_t).to_sym, *args) end end |
#case(case_t, expr, body, end_t) ⇒ Object
538 539 540 |
# File 'lib/parser/builders/default.rb', line 538 def case(case_t, expr, body, end_t) s(:case, expr, *body) end |
#compstmt(statements) ⇒ Object
589 590 591 592 593 594 595 596 597 598 |
# File 'lib/parser/builders/default.rb', line 589 def compstmt(statements) case when statements.one? statements.first when statements.none? s(:nil) else s(:begin, *statements) end end |
#condition(cond_t, cond, then_t, if_true, else_t, if_false, end_t) ⇒ Object
Conditionals
519 520 521 522 |
# File 'lib/parser/builders/default.rb', line 519 def condition(cond_t, cond, then_t, if_true, else_t, if_false, end_t) s(:if, check_condition(cond), if_true, if_false) end |
#condition_mod(if_true, if_false, cond_t, cond) ⇒ Object
524 525 526 |
# File 'lib/parser/builders/default.rb', line 524 def condition_mod(if_true, if_false, cond_t, cond) s(:if, check_condition(cond), if_true, if_false) end |
#const(token) ⇒ Object
179 180 181 |
# File 'lib/parser/builders/default.rb', line 179 def const(token) t(token, :const, nil, value(token).to_sym) end |
#const_fetch(scope, t_colon2, token) ⇒ Object
187 188 189 |
# File 'lib/parser/builders/default.rb', line 187 def const_fetch(scope, t_colon2, token) s(:const, scope, value(token).to_sym) end |
#const_global(t_colon3, token) ⇒ Object
183 184 185 |
# File 'lib/parser/builders/default.rb', line 183 def const_global(t_colon3, token) s(:const, s(:cbase), value(token).to_sym) end |
#cvar(token) ⇒ Object
148 |
# File 'lib/parser/builders/default.rb', line 148 def cvar(token); t(token, :cvar, value(token).to_sym); end |
#def_class(class_t, name, lt_t, superclass, body, end_t) ⇒ Object
Class and module definition
292 293 294 295 296 |
# File 'lib/parser/builders/default.rb', line 292 def def_class(class_t, name, lt_t, superclass, body, end_t) s(:class, name, superclass, body) end |
#def_method(def_t, name, args, body, end_t, comments) ⇒ Object
Method (un)definition
312 313 314 315 |
# File 'lib/parser/builders/default.rb', line 312 def def_method(def_t, name, args, body, end_t, comments) s(:def, value(name).to_sym, args, body) end |
#def_module(module_t, name, body, end_t) ⇒ Object
303 304 305 306 |
# File 'lib/parser/builders/default.rb', line 303 def def_module(module_t, name, body, end_t) s(:module, name, body) end |
#def_sclass(class_t, lshft_t, expr, body, end_t) ⇒ Object
298 299 300 301 |
# File 'lib/parser/builders/default.rb', line 298 def def_sclass(class_t, lshft_t, expr, body, end_t) s(:sclass, expr, body) end |
#def_singleton(def_t, definee, dot_t, name, args, body, end_t, comments) ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/parser/builders/default.rb', line 317 def def_singleton(def_t, definee, dot_t, name, args, body, end_t, comments) case definee.type when :int, :str, :dstr, :sym, :dsym, :regexp, :array, :hash = ERRORS[:singleton_literal] diagnostic :error, , nil # TODO definee.src.expression else s(:defs, definee, value(name).to_sym, args, body) end end |
#false(token) ⇒ Object
14 |
# File 'lib/parser/builders/default.rb', line 14 def false(token); t(token, :false); end |
#float(token, negate = false) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/parser/builders/default.rb', line 29 def float(token, negate=false) val = value(token) val = -val if negate t(token, :float, val) end |
#for(for_t, iterator, in_t, iteratee, do_t, body, end_t) ⇒ Object
552 553 554 555 |
# File 'lib/parser/builders/default.rb', line 552 def for(for_t, iterator, in_t, iteratee, do_t, body, end_t) s(:for, iterator, iteratee, body) end |
#gvar(token) ⇒ Object
147 |
# File 'lib/parser/builders/default.rb', line 147 def gvar(token); t(token, :gvar, value(token).to_sym); end |
#ident(token) ⇒ Object
145 |
# File 'lib/parser/builders/default.rb', line 145 def ident(token); t(token, :ident, value(token).to_sym); end |
#index(receiver, lbrack_t, indexes, rbrack_t) ⇒ Object
463 464 465 |
# File 'lib/parser/builders/default.rb', line 463 def index(receiver, lbrack_t, indexes, rbrack_t) s(:send, receiver, :[], *indexes) end |
#index_asgn(receiver, lbrack_t, indexes, rbrack_t) ⇒ Object
467 468 469 470 |
# File 'lib/parser/builders/default.rb', line 467 def index_asgn(receiver, lbrack_t, indexes, rbrack_t) # Incomplete method call. s(:send, receiver, :[]=, *indexes) end |
#integer(token, negate = false) ⇒ Object
Numerics
18 19 20 21 22 23 |
# File 'lib/parser/builders/default.rb', line 18 def integer(token, negate=false) val = value(token) val = -val if negate t(token, :int, val) end |
#ivar(token) ⇒ Object
146 |
# File 'lib/parser/builders/default.rb', line 146 def ivar(token); t(token, :ivar, value(token).to_sym); end |
#keyword_cmd(type, token, lparen_t = nil, args = [], rparen_t = nil) ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/parser/builders/default.rb', line 344 def keyword_cmd(type, token, lparen_t=nil, args=[], rparen_t=nil) case type when :return, :break, :next, :redo, :retry, :super, :zsuper, :yield, :defined? t(token, type, *args) else raise NotImplementedError, "build_keyword_cmd #{type} #{args.inspect}" end end |
#logical_op(type, lhs, token, rhs) ⇒ Object
Logical operations: and, or
513 514 515 |
# File 'lib/parser/builders/default.rb', line 513 def logical_op(type, lhs, token, rhs) s(type, lhs, rhs) end |
#loop(loop_t, cond, do_t, body, end_t) ⇒ Object
Loops
544 545 546 |
# File 'lib/parser/builders/default.rb', line 544 def loop(loop_t, cond, do_t, body, end_t) s(value(loop_t).to_sym, check_condition(cond), body) end |
#loop_mod(body, loop_t, cond) ⇒ Object
548 549 550 |
# File 'lib/parser/builders/default.rb', line 548 def loop_mod(body, loop_t, cond) s(value(loop_t).to_sym, check_condition(cond), body) end |
#multi_assign(lhs, eql_t, rhs) ⇒ Object
284 285 286 |
# File 'lib/parser/builders/default.rb', line 284 def multi_assign(lhs, eql_t, rhs) s(:masgn, lhs, rhs) end |
#multi_lhs(begin_t, items, end_t) ⇒ Object
280 281 282 |
# File 'lib/parser/builders/default.rb', line 280 def multi_lhs(begin_t, items, end_t) s(:mlhs, *items) end |
#nil(token) ⇒ Object
Singletons
12 |
# File 'lib/parser/builders/default.rb', line 12 def nil(token); t(token, :nil); end |
#not_op(token, receiver = nil) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/parser/builders/default.rb', line 495 def not_op(token, receiver=nil) if @parser.version == 18 s(:not, receiver) else if receiver.nil? s(:send, s(:nil), :'!') else s(:send, receiver, :'!') end end end |
#nth_ref(token) ⇒ Object
151 |
# File 'lib/parser/builders/default.rb', line 151 def nth_ref(token); t(token, :nth_ref, value(token)); end |
#op_assign(lhs, operator_t, rhs) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/parser/builders/default.rb', line 257 def op_assign(lhs, operator_t, rhs) case lhs.type when :gvasgn, :ivasgn, :lvasgn, :cvasgn, :cvdecl, :send operator = value(operator_t)[0..-1].to_sym case operator when :'&&' s(:and_asgn, lhs, rhs) when :'||' s(:or_asgn, lhs, rhs) else s(:op_asgn, lhs, operator, rhs) end when :back_ref, :nth_ref = ERRORS[:backref_assignment] diagnostic :error, , lhs.src.expression else raise NotImplementedError, "build op_assign #{lhs.inspect}" end end |
#optarg(token, eql_t, value) ⇒ Object
371 372 373 |
# File 'lib/parser/builders/default.rb', line 371 def optarg(token, eql_t, value) s(:optarg, value(token).to_sym, value) end |
#pair(key, assoc_t, value) ⇒ Object
Hashes
100 101 102 |
# File 'lib/parser/builders/default.rb', line 100 def pair(key, assoc_t, value) s(:pair, key, value) end |
#pair_list_18(list) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/parser/builders/default.rb', line 104 def pair_list_18(list) if list.size % 2 != 0 # TODO better location info here = ERRORS[:odd_hash] diagnostic :error, , list.last.src.expression else list. each_slice(2).map do |key, value| s(:pair, key, value) end end end |
#parenthesize(begin_t, expr, end_t) ⇒ Object
Expression grouping
135 136 137 |
# File 'lib/parser/builders/default.rb', line 135 def parenthesize(begin_t, expr, end_t) expr end |
#postexe(postexe_t, lbrace_t, compstmt, rbrace_t) ⇒ Object
606 607 608 |
# File 'lib/parser/builders/default.rb', line 606 def postexe(postexe_t, lbrace_t, compstmt, rbrace_t) s(:postexe, compstmt) end |
#preexe(preexe_t, lbrace_t, compstmt, rbrace_t) ⇒ Object
BEGIN, END
602 603 604 |
# File 'lib/parser/builders/default.rb', line 602 def preexe(preexe_t, lbrace_t, compstmt, rbrace_t) s(:preexe, compstmt) end |
#range_exclusive(lhs, token, rhs) ⇒ Object
127 128 129 |
# File 'lib/parser/builders/default.rb', line 127 def range_exclusive(lhs, token, rhs) s(:erange, lhs, rhs) end |
#range_inclusive(lhs, token, rhs) ⇒ Object
Ranges
123 124 125 |
# File 'lib/parser/builders/default.rb', line 123 def range_inclusive(lhs, token, rhs) s(:irange, lhs, rhs) end |
#regexp_compose(begin_t, parts, end_t, options) ⇒ Object
76 77 78 |
# File 'lib/parser/builders/default.rb', line 76 def regexp_compose(begin_t, parts, end_t, ) s(:regexp, *(parts << )) end |
#regexp_options(token) ⇒ Object
Regular expressions
72 73 74 |
# File 'lib/parser/builders/default.rb', line 72 def (token) t(token, :regopt, *value(token).each_char.sort.uniq.map(&:to_sym)) end |
#rescue_body(rescue_t, exc_list, assoc_t, exc_var, then_t, compound_stmt) ⇒ Object
563 564 565 566 567 |
# File 'lib/parser/builders/default.rb', line 563 def rescue_body(rescue_t, exc_list, assoc_t, exc_var, then_t, compound_stmt) s(:resbody, exc_list, exc_var, compound_stmt) end |
#self(token) ⇒ Object
Access
143 |
# File 'lib/parser/builders/default.rb', line 143 def self(token); t(token, :self); end |
#shadowarg(token) ⇒ Object
383 384 385 |
# File 'lib/parser/builders/default.rb', line 383 def shadowarg(token) s(:shadowarg, value(token).to_sym) end |
#splat(star_t, arg = nil) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/parser/builders/default.rb', line 86 def splat(star_t, arg=nil) if arg.nil? s(:splat) else s(:splat, arg) end end |
#splatarg(star_t, token = nil) ⇒ Object
375 376 377 378 379 380 381 |
# File 'lib/parser/builders/default.rb', line 375 def splatarg(star_t, token=nil) if token s(:splatarg, value(token).to_sym) else t(star_t, :splatarg) end end |
#splatarg_expr(star_t, expr = nil) ⇒ Object
401 402 403 404 405 406 407 408 409 |
# File 'lib/parser/builders/default.rb', line 401 def splatarg_expr(star_t, expr=nil) if expr.nil? t(star_t, :splatarg) elsif expr.type == :lvasgn expr.updated(:splatarg) else s(:splatarg_expr, expr) end end |
#string(token) ⇒ Object
Strings
38 39 40 |
# File 'lib/parser/builders/default.rb', line 38 def string(token) t(token, :str, value(token)) end |
#string_compose(begin_t, parts, end_t) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/parser/builders/default.rb', line 42 def string_compose(begin_t, parts, end_t) if parts.one? parts.first else s(:dstr, *parts) end end |
#symbol(token) ⇒ Object
Symbols
56 57 58 |
# File 'lib/parser/builders/default.rb', line 56 def symbol(token) t(token, :sym, value(token).to_sym) end |
#symbol_compose(begin_t, parts, end_t) ⇒ Object
60 61 62 |
# File 'lib/parser/builders/default.rb', line 60 def symbol_compose(begin_t, parts, end_t) s(:dsym, *parts) end |
#ternary(cond, question_t, if_true, colon_t, if_false) ⇒ Object
528 529 530 |
# File 'lib/parser/builders/default.rb', line 528 def ternary(cond, question_t, if_true, colon_t, if_false) s(:if, check_condition(cond), if_true, if_false) end |
#true(token) ⇒ Object
13 |
# File 'lib/parser/builders/default.rb', line 13 def true(token); t(token, :true); end |
#unary_op(token, receiver) ⇒ Object
484 485 486 487 488 489 490 491 492 493 |
# File 'lib/parser/builders/default.rb', line 484 def unary_op(token, receiver) case value(token) when '+', '-' method = value(token) + '@' else method = value(token) end s(:send, receiver, method.to_sym) end |
#undef_method(token, names) ⇒ Object
332 333 334 |
# File 'lib/parser/builders/default.rb', line 332 def undef_method(token, names) s(:undef, *names) end |
#when(when_t, patterns, then_t, body) ⇒ Object
Case matching
534 535 536 |
# File 'lib/parser/builders/default.rb', line 534 def when(when_t, patterns, then_t, body) s(:when, *(patterns << body)) end |
#words_compose(begin_t, parts, end_t) ⇒ Object
94 95 96 |
# File 'lib/parser/builders/default.rb', line 94 def words_compose(begin_t, parts, end_t) s(:array, *parts) end |
#xstring_compose(begin_t, parts, end_t) ⇒ Object
Executable strings
66 67 68 |
# File 'lib/parser/builders/default.rb', line 66 def xstring_compose(begin_t, parts, end_t) s(:xstr, *parts) end |