Module: RubyParserStuff
- Included in:
- Ruby18Parser, Ruby19Parser
- Defined in:
- lib/ruby_parser/ruby_parser_extras.rb
Defined Under Namespace
Classes: Environment, Keyword, StackState
Constant Summary collapse
- VERSION =
SIGH
'2.3.1'
Instance Attribute Summary collapse
-
#canonicalize_conditions ⇒ Object
Canonicalize conditionals.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#file ⇒ Object
Returns the value of attribute file.
-
#in_def ⇒ Object
Returns the value of attribute in_def.
-
#in_single ⇒ Object
Returns the value of attribute in_single.
-
#lexer ⇒ Object
Returns the value of attribute lexer.
Instance Method Summary collapse
-
#arg_add(node1, node2) ⇒ Object
TODO: nuke.
-
#arg_blk_pass(node1, node2) ⇒ Object
TODO: nuke.
-
#arg_concat(node1, node2) ⇒ Object
TODO: nuke.
- #args(arg, optarg, rest_arg, block_arg, post_arg = nil) ⇒ Object
-
#args19(vals) ⇒ Object
TODO: migrate to args once 1.8 tests pass as well.
- #aryset(receiver, index) ⇒ Object
- #assignable(lhs, value = nil) ⇒ Object
- #block_append(head, tail) ⇒ Object
- #cond(node) ⇒ Object
-
#do_parse ⇒ Object
for pure ruby systems only.
-
#get_match_node(lhs, rhs) ⇒ Object
TODO: rename to new_match.
- #gettable(id) ⇒ Object
- #initialize(options = {}) ⇒ Object
-
#list_append(list, item) ⇒ Object
TODO: nuke me sigh.
-
#list_prepend(item, list) ⇒ Object
TODO: nuke me sigh.
- #literal_concat(head, tail) ⇒ Object
-
#logop(type, left, right) ⇒ Object
TODO: rename logical_op.
- #new_aref(val) ⇒ Object
- #new_body(val) ⇒ Object
- #new_call(recv, meth, args = nil) ⇒ Object
- #new_case(expr, body) ⇒ Object
- #new_class(val) ⇒ Object
- #new_compstmt(val) ⇒ Object
- #new_defn(val) ⇒ Object
- #new_defs(val) ⇒ Object
- #new_for(expr, var, body) ⇒ Object
- #new_if(c, t, f) ⇒ Object
- #new_iter(call, args, body) ⇒ Object
- #new_masgn(lhs, rhs, wrap = false) ⇒ Object
- #new_module(val) ⇒ Object
- #new_op_asgn(val) ⇒ Object
- #new_regexp(val) ⇒ Object
- #new_sclass(val) ⇒ Object
- #new_super(args) ⇒ Object
- #new_undef(n, m = nil) ⇒ Object
- #new_until(block, expr, pre) ⇒ Object
- #new_until_or_while(type, block, expr, pre) ⇒ Object
- #new_while(block, expr, pre) ⇒ Object
- #new_xstring(str) ⇒ Object
- #new_yield(args = nil) ⇒ Object
- #next_token ⇒ Object
-
#node_assign(lhs, rhs) ⇒ Object
TODO: rename new_assign.
- #process(str, file = "(string)") ⇒ Object (also: #parse)
- #remove_begin(node) ⇒ Object
- #reset ⇒ Object
- #ret_args(node) ⇒ Object
- #s(*args) ⇒ Object
-
#value_expr(oldnode) ⇒ Object
HACK.
- #void_stmts(node) ⇒ Object
- #warning(s) ⇒ Object
- #yyerror(msg) ⇒ Object
Instance Attribute Details
#canonicalize_conditions ⇒ Object
Canonicalize conditionals. Eg:
not x ? a : b
becomes:
x ? b : a
358 359 360 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 358 def canonicalize_conditions @canonicalize_conditions end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
117 118 119 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 117 def comments @comments end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
117 118 119 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 117 def env @env end |
#file ⇒ Object
Returns the value of attribute file.
116 117 118 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 116 def file @file end |
#in_def ⇒ Object
Returns the value of attribute in_def.
116 117 118 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 116 def in_def @in_def end |
#in_single ⇒ Object
Returns the value of attribute in_single.
116 117 118 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 116 def in_single @in_single end |
#lexer ⇒ Object
Returns the value of attribute lexer.
116 117 118 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 116 def lexer @lexer end |
Instance Method Details
#arg_add(node1, node2) ⇒ Object
TODO: nuke
119 120 121 122 123 124 125 126 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 119 def arg_add(node1, node2) # TODO: nuke return s(:arglist, node2) unless node1 node1[0] = :arglist if node1[0] == :array return node1 << node2 if node1[0] == :arglist return s(:arglist, node1, node2) end |
#arg_blk_pass(node1, node2) ⇒ Object
TODO: nuke
128 129 130 131 132 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 128 def arg_blk_pass node1, node2 # TODO: nuke node1 = s(:arglist, node1) unless [:arglist, :array].include? node1.first node1 << node2 if node2 node1 end |
#arg_concat(node1, node2) ⇒ Object
TODO: nuke
134 135 136 137 138 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 134 def arg_concat node1, node2 # TODO: nuke raise "huh" unless node2 node1 << s(:splat, node2).compact node1 end |
#args(arg, optarg, rest_arg, block_arg, post_arg = nil) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 140 def args arg, optarg, rest_arg, block_arg, post_arg = nil arg ||= s(:args) result = arg if optarg then optarg[1..-1].each do |lasgn| # FIX clean sexp iter raise "wtf? #{lasgn.inspect}" unless lasgn[0] == :lasgn result << lasgn[1] end end result << rest_arg if rest_arg result << :"&#{block_arg.last}" if block_arg result << optarg if optarg # TODO? huh - processed above as well post_arg[1..-1].each {|pa| result << pa } if post_arg result end |
#args19(vals) ⇒ Object
TODO: migrate to args once 1.8 tests pass as well
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 160 def args19 vals # TODO: migrate to args once 1.8 tests pass as well result = s(:args) block = nil vals.each do |val| case val when Sexp then case val.first when :args then val[1..-1].each do |name| result << name end when :block_arg then result << :"&#{val.last}" when :block then block = val val[1..-1].each do |lasgn| # FIX clean sexp iter raise "wtf? #{val.inspect}" unless lasgn[0] == :lasgn result << lasgn[1] end else raise "unhandled sexp: #{val.inspect}" end when Symbol then result << val when ",", nil then # ignore else raise "unhandled val: #{val.inspect} in #{vals.inspect}" end end result << block if block result end |
#aryset(receiver, index) ⇒ Object
197 198 199 200 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 197 def aryset receiver, index index[0] = :arglist if index[0] == :array s(:attrasgn, receiver, :"[]=", index) end |
#assignable(lhs, value = nil) ⇒ Object
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 241 242 243 244 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 202 def assignable(lhs, value = nil) id = lhs.to_sym id = id.to_sym if Sexp === id raise SyntaxError, "Can't change the value of #{id}" if id.to_s =~ /^(?:self|nil|true|false|__LINE__|__FILE__)$/ result = case id.to_s when /^@@/ then asgn = in_def || in_single > 0 s((asgn ? :cvasgn : :cvdecl), id) when /^@/ then s(:iasgn, id) when /^\$/ then s(:gasgn, id) when /^[A-Z]/ then s(:cdecl, id) else case self.env[id] when :lvar then s(:lasgn, id) when :dvar, nil then if self.env.current[id] == :dvar then s(:lasgn, id) elsif self.env[id] == :dvar then self.env.use(id) s(:lasgn, id) elsif ! self.env.dynamic? then s(:lasgn, id) else s(:lasgn, id) end else raise "wtf? unknown type: #{self.env[id]}" end end self.env[id] ||= :lvar result << value if value return result end |
#block_append(head, tail) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 246 def block_append(head, tail) return head if tail.nil? return tail if head.nil? case head[0] when :lit, :str then return tail end line = [head.line, tail.line].compact.min head = remove_begin(head) head = s(:block, head) unless head.node_type == :block head.line = line head << tail end |
#cond(node) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 264 def cond node return nil if node.nil? node = value_expr node case node.first when :lit then if Regexp === node.last then return s(:match, node) else return node end when :and then return s(:and, cond(node[1]), cond(node[2])) when :or then return s(:or, cond(node[1]), cond(node[2])) when :dot2 then label = "flip#{node.hash}" env[label] = :lvar return s(:flip2, node[1], node[2]) when :dot3 then label = "flip#{node.hash}" env[label] = :lvar return s(:flip3, node[1], node[2]) else return node end end |
#do_parse ⇒ Object
for pure ruby systems only
295 296 297 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 295 def do_parse _racc_do_parse_rb(_racc_setup, false) end |
#get_match_node(lhs, rhs) ⇒ Object
TODO: rename to new_match
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 299 def get_match_node lhs, rhs # TODO: rename to new_match if lhs then case lhs[0] when :dregx, :dregx_once then return s(:match2, lhs, rhs).line(lhs.line) when :lit then return s(:match2, lhs, rhs).line(lhs.line) if Regexp === lhs.last end end if rhs then case rhs[0] when :dregx, :dregx_once then return s(:match3, rhs, lhs).line(lhs.line) when :lit then return s(:match3, rhs, lhs).line(lhs.line) if Regexp === rhs.last end end return s(:call, lhs, :"=~", s(:arglist, rhs)).line(lhs.line) end |
#gettable(id) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 321 def gettable(id) id = id.to_sym if String === id result = case id.to_s when /^@@/ then s(:cvar, id) when /^@/ then s(:ivar, id) when /^\$/ then s(:gvar, id) when /^[A-Z]/ then s(:const, id) else type = env[id] if type then s(type, id) elsif env.dynamic? and :dvar == env[id] then s(:lvar, id) else s(:call, nil, id, s(:arglist)) end end raise "identifier #{id.inspect} is not valid" unless result result end |
#initialize(options = {}) ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 360 def initialize( = {}) super() v = self.class.name[/1[89]/] self.lexer = RubyLexer.new v && v.to_i self.lexer.parser = self @env = Environment.new @comments = [] @canonicalize_conditions = true self.reset end |
#list_append(list, item) ⇒ Object
TODO: nuke me sigh
374 375 376 377 378 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 374 def list_append list, item # TODO: nuke me *sigh* return s(:array, item) unless list list = s(:array, list) unless Sexp === list && list.first == :array list << item end |
#list_prepend(item, list) ⇒ Object
TODO: nuke me sigh
380 381 382 383 384 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 380 def list_prepend item, list # TODO: nuke me *sigh* list = s(:array, list) unless Sexp === list && list[0] == :array list.insert 1, item list end |
#literal_concat(head, tail) ⇒ Object
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 386 def literal_concat head, tail return tail unless head return head unless tail htype, ttype = head[0], tail[0] head = s(:dstr, '', head) if htype == :evstr case ttype when :str then if htype == :str head[-1] << tail[-1] elsif htype == :dstr and head.size == 2 then head[-1] << tail[-1] else head << tail end when :dstr then if htype == :str then tail[1] = head[-1] + tail[1] head = tail else tail[0] = :array tail[1] = s(:str, tail[1]) tail.delete_at 1 if tail[1] == s(:str, '') head.push(*tail[1..-1]) end when :evstr then head[0] = :dstr if htype == :str if head.size == 2 and tail.size > 1 and tail[1][0] == :str then head[-1] << tail[1][-1] head[0] = :str if head.size == 2 # HACK ? else head.push(tail) end else x = [head, tail] raise "unknown type: #{x.inspect}" end return head end |
#logop(type, left, right) ⇒ Object
TODO: rename logical_op
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 430 def logop(type, left, right) # TODO: rename logical_op left = value_expr left if left and left[0] == type and not left.paren then node, second = left, nil while (second = node[2]) && second[0] == type and not second.paren do node = second end node[2] = s(type, second, right) return left end return s(type, left, right) end |
#new_aref(val) ⇒ Object
448 449 450 451 452 453 454 455 456 457 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 448 def new_aref val val[2] ||= s(:arglist) val[2][0] = :arglist if val[2][0] == :array # REFACTOR if val[0].node_type == :self then result = new_call nil, :"[]", val[2] else result = new_call val[0], :"[]", val[2] end result end |
#new_body(val) ⇒ Object
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 459 def new_body val result = val[0] if val[1] then result = s(:rescue) result << val[0] if val[0] resbody = val[1] while resbody do result << resbody resbody = resbody.resbody(true) end result << val[2] if val[2] result.line = (val[0] || val[1]).line elsif not val[2].nil? then warning("else without rescue is useless") result = block_append(result, val[2]) end result = s(:ensure, result, val[3]).compact if val[3] return result end |
#new_call(recv, meth, args = nil) ⇒ Object
485 486 487 488 489 490 491 492 493 494 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 485 def new_call recv, meth, args = nil result = s(:call, recv, meth) result.line = recv.line if recv args ||= s(:arglist) args[0] = :arglist if args.first == :array args = s(:arglist, args) unless args.first == :arglist result << args result end |
#new_case(expr, body) ⇒ Object
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 496 def new_case expr, body result = s(:case, expr) line = (expr || body).line while body and body.node_type == :when result << body body = body.delete_at 3 end # else body = nil if body == s(:block) result << body result.line = line result end |
#new_class(val) ⇒ Object
513 514 515 516 517 518 519 520 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 513 def new_class val line, path, superclass, body = val[1], val[2], val[3], val[5] scope = s(:scope, body).compact result = s(:class, path, superclass, scope) result.line = line result.comments = self.comments.pop result end |
#new_compstmt(val) ⇒ Object
522 523 524 525 526 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 522 def new_compstmt val result = void_stmts(val[0]) result = remove_begin(result) if result result end |
#new_defn(val) ⇒ Object
528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 528 def new_defn val (_, line), name, args, body = val[0], val[1], val[3], val[4] body ||= s(:nil) body ||= s(:block) body = s(:block, body) unless body.first == :block result = s(:defn, name.to_sym, args, s(:scope, body)) result.line = line result.comments = self.comments.pop result end |
#new_defs(val) ⇒ Object
541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 541 def new_defs val recv, name, args, body = val[1], val[4], val[6], val[7] body ||= s(:block) body = s(:block, body) unless body.first == :block result = s(:defs, recv, name.to_sym, args, s(:scope, body)) result.line = recv.line result.comments = self.comments.pop result end |
#new_for(expr, var, body) ⇒ Object
553 554 555 556 557 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 553 def new_for expr, var, body result = s(:for, expr, var).line(var.line) result << body if body result end |
#new_if(c, t, f) ⇒ Object
559 560 561 562 563 564 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 559 def new_if c, t, f l = [c.line, t && t.line, f && f.line].compact.min c = cond c c, t, f = c.last, f, t if c[0] == :not and canonicalize_conditions s(:if, c, t, f).line(l) end |
#new_iter(call, args, body) ⇒ Object
566 567 568 569 570 571 572 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 566 def new_iter call, args, body result = s(:iter) result << call if call result << args result << body if body result end |
#new_masgn(lhs, rhs, wrap = false) ⇒ Object
574 575 576 577 578 579 580 581 582 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 574 def new_masgn lhs, rhs, wrap = false rhs = value_expr(rhs) rhs = lhs[1] ? s(:to_ary, rhs) : s(:array, rhs) if wrap lhs.delete_at 1 if lhs[1].nil? lhs << rhs lhs end |
#new_module(val) ⇒ Object
584 585 586 587 588 589 590 591 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 584 def new_module val line, path, body = val[1], val[2], val[4] body = s(:scope, body).compact result = s(:module, path, body) result.line = line result.comments = self.comments.pop result end |
#new_op_asgn(val) ⇒ Object
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 593 def new_op_asgn val lhs, asgn_op, arg = val[0], val[1].to_sym, val[2] name = lhs.value arg = remove_begin(arg) result = case asgn_op # REFACTOR when :"||" then lhs << arg s(:op_asgn_or, self.gettable(name), lhs) when :"&&" then lhs << arg s(:op_asgn_and, self.gettable(name), lhs) else # TODO: why [2] ? lhs[2] = new_call(self.gettable(name), asgn_op, s(:arglist, arg)) lhs end result.line = lhs.line result end |
#new_regexp(val) ⇒ Object
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 614 def new_regexp val node = val[1] || s(:str, '') = val[2] o, k = 0, nil .split(//).uniq.each do |c| # FIX: this has a better home v = { 'x' => Regexp::EXTENDED, 'i' => Regexp::IGNORECASE, 'm' => Regexp::MULTILINE, 'o' => Regexp::ONCE, 'n' => Regexp::ENC_NONE, 'e' => Regexp::ENC_EUC, 's' => Regexp::ENC_SJIS, 'u' => Regexp::ENC_UTF8, }[c] raise "unknown regexp option: #{c}" unless v o += v k = c if c =~ /[esu]/ end case node[0] when :str then node[0] = :lit node[1] = if k then Regexp.new(node[1], o, k) else Regexp.new(node[1], o) end when :dstr then if =~ /o/ then node[0] = :dregx_once else node[0] = :dregx end node << o if o and o != 0 else node = s(:dregx, '', node); node[0] = :dregx_once if =~ /o/ node << o if o and o != 0 end node end |
#new_sclass(val) ⇒ Object
659 660 661 662 663 664 665 666 667 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 659 def new_sclass val recv, in_def, in_single, body = val[3], val[4], val[6], val[7] scope = s(:scope, body).compact result = s(:sclass, recv, scope) result.line = val[2] self.in_def = in_def self.in_single = in_single result end |
#new_super(args) ⇒ Object
669 670 671 672 673 674 675 676 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 669 def new_super args if args && args.node_type == :block_pass then s(:super, args) else args ||= s(:arglist) s(:super, *args[1..-1]) end end |
#new_undef(n, m = nil) ⇒ Object
678 679 680 681 682 683 684 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 678 def new_undef n, m = nil if m then block_append(n, s(:undef, m)) else s(:undef, n) end end |
#new_until(block, expr, pre) ⇒ Object
703 704 705 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 703 def new_until block, expr, pre new_until_or_while :until, block, expr, pre end |
#new_until_or_while(type, block, expr, pre) ⇒ Object
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 686 def new_until_or_while type, block, expr, pre other = type == :until ? :while : :until line = [block && block.line, expr.line].compact.min block, pre = block.last, false if block && block[0] == :begin expr = cond expr result = unless expr.first == :not and canonicalize_conditions then s(type, expr, block, pre) else s(other, expr.last, block, pre) end result.line = line result end |
#new_while(block, expr, pre) ⇒ Object
707 708 709 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 707 def new_while block, expr, pre new_until_or_while :while, block, expr, pre end |
#new_xstring(str) ⇒ Object
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 711 def new_xstring str if str then case str[0] when :str str[0] = :xstr when :dstr str[0] = :dxstr else str = s(:dxstr, '', str) end str else s(:xstr, '') end end |
#new_yield(args = nil) ⇒ Object
727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 727 def new_yield args = nil # TODO: raise args.inspect unless [:arglist].include? args.first # HACK raise SyntaxError, "Block argument should not be given." if args && args.node_type == :block_pass args ||= s(:arglist) # TODO: I can prolly clean this up args[0] = :arglist if args.first == :array args = s(:arglist, args) unless args.first == :arglist return s(:yield, *args[1..-1]) end |
#next_token ⇒ Object
741 742 743 744 745 746 747 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 741 def next_token if self.lexer.advance then return self.lexer.token, self.lexer.yacc_value else return [false, '$end'] end end |
#node_assign(lhs, rhs) ⇒ Object
TODO: rename new_assign
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 749 def node_assign(lhs, rhs) # TODO: rename new_assign return nil unless lhs rhs = value_expr rhs case lhs[0] when :gasgn, :iasgn, :lasgn, :dasgn, :dasgn_curr, :masgn, :cdecl, :cvdecl, :cvasgn then lhs << rhs when :attrasgn, :call then args = lhs.pop unless Symbol === lhs.last lhs << arg_add(args, rhs) when :const then lhs[0] = :cdecl lhs << rhs else raise "unknown lhs #{lhs.inspect}" end lhs end |
#process(str, file = "(string)") ⇒ Object Also known as: parse
771 772 773 774 775 776 777 778 779 780 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 771 def process(str, file = "(string)") raise "bad val: #{str.inspect}" unless String === str self.file = file self.lexer.src = str.dup @yydebug = ENV.has_key? 'DEBUG' do_parse end |
#remove_begin(node) ⇒ Object
783 784 785 786 787 788 789 790 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 783 def remove_begin node oldnode = node if node and :begin == node[0] and node.size == 2 then node = node[-1] node.line = oldnode.line end node end |
#reset ⇒ Object
792 793 794 795 796 797 798 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 792 def reset lexer.reset self.in_def = false self.in_single = 0 self.env.reset self.comments.clear end |
#ret_args(node) ⇒ Object
800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 800 def ret_args node if node then raise SyntaxError, "block argument should not be given" if node[0] == :block_pass node = node.last if node[0] == :array && node.size == 2 # HACK matz wraps ONE of the FOUR splats in a newline to # distinguish. I use paren for now. ugh node = s(:svalue, node) if node[0] == :splat and not node.paren node[0] = :svalue if node[0] == :arglist && node[1][0] == :splat end node end |
#s(*args) ⇒ Object
815 816 817 818 819 820 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 815 def s(*args) result = Sexp.new(*args) result.line ||= lexer.lineno if lexer.src # otherwise... result.file = self.file result end |
#value_expr(oldnode) ⇒ Object
HACK
822 823 824 825 826 827 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 822 def value_expr oldnode # HACK node = remove_begin oldnode node.line = oldnode.line if oldnode node[2] = value_expr(node[2]) if node and node[0] == :if node end |
#void_stmts(node) ⇒ Object
829 830 831 832 833 834 835 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 829 def void_stmts node return nil unless node return node unless node[0] == :block node[1..-1] = node[1..-1].map { |n| remove_begin(n) } node end |
#warning(s) ⇒ Object
837 838 839 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 837 def warning s # do nothing for now end |
#yyerror(msg) ⇒ Object
841 842 843 844 |
# File 'lib/ruby_parser/ruby_parser_extras.rb', line 841 def yyerror msg # for now do nothing with the msg super end |