Class: RubyCompleteCode
- Inherits:
-
CompleteCode
- Object
- CompleteCode
- RubyCompleteCode
- Defined in:
- ext/ae-editor/ae-editor.rb
Constant Summary collapse
- RESERVED_WORDS =
["__FILE__","and","def","end","in","or","self","unless", "__LINE__","begin","defined?","ensure","module","redo","super","until", "BEGIN","break","do","false","next","rescue","then","when", "END","case","else","for","nil","retry","true","while", "alias","class","elsif","if","not","return","undef","yield"]
Instance Attribute Summary collapse
-
#modified_col ⇒ Object
readonly
Returns the value of attribute modified_col.
-
#modified_row ⇒ Object
readonly
Returns the value of attribute modified_row.
Attributes inherited from CompleteCode
Instance Method Summary collapse
- #candidates(_show_error = false) ⇒ Object
- #create_modified_temp_file(_base_file = nil) ⇒ Object
- #declaration(_dec_line = '') ⇒ Object
- #dot_trip(_var_name) ⇒ Object
-
#initialize(_editor, _row, _col) ⇒ RubyCompleteCode
constructor
A new instance of RubyCompleteCode.
-
#process_source ⇒ Object
def is_dot? @is_dot end.
- #scope_trip ⇒ Object
Methods inherited from CompleteCode
#focus_word, #is_dot?, #refresh_words
Constructor Details
#initialize(_editor, _row, _col) ⇒ RubyCompleteCode
Returns a new instance of RubyCompleteCode.
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'ext/ae-editor/ae-editor.rb', line 471 def initialize(_editor, _row, _col) # @editor = _editor # @source = _editor.text_value # @row = _row.to_i # @col = _col.to_i super if _editor && _editor. tmp_file = _editor.create_temp_file begin @ss = RubyCtagsSourceStructure.new(tmp_file, _editor., _row.to_i) ensure File.delete(tmp_file) end else @ss = RubySourceStructure.new(@source) end # @filter='' # @words = Array.new # process_source end |
Instance Attribute Details
#modified_col ⇒ Object (readonly)
Returns the value of attribute modified_col.
465 466 467 |
# File 'ext/ae-editor/ae-editor.rb', line 465 def modified_col @modified_col end |
#modified_row ⇒ Object (readonly)
Returns the value of attribute modified_row.
465 466 467 |
# File 'ext/ae-editor/ae-editor.rb', line 465 def modified_row @modified_row end |
Instance Method Details
#candidates(_show_error = false) ⇒ Object
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
# File 'ext/ae-editor/ae-editor.rb', line 706 def candidates(_show_error = false) super temp_file = create_modified_temp_file(@editor.file) begin Arcadia.is_windows??ruby='rubyw':ruby=Arcadia.ruby _cmp_s = "|#{ruby} '#{temp_file}' 2>&1" _ret = nil onlyw = [] begin open(_cmp_s,"r") do |f| _ret = f.readlines.collect!{| line | #line.chomp anlyl = line.split('#')[1] onlyw << anlyl.strip if anlyl line.strip } end rescue _ret = [] end if _ret.include?(':ARCADIA_CC_ERROR') _ret = [] end if @filter.strip.length > 0 && !is_dot? @words.each{|w| if !(onlyw.include?(w) || onlyw.include?("##{w}")) _ret << w end } end if !is_dot? RESERVED_WORDS.each{|w| if !onlyw.include?(w) && !@words.include?(w) _ret << w end } end _ret.sort rescue Exception => e Arcadia.runtime_error(e) #Arcadia.console(self, 'msg'=>e.to_s, 'level'=>'error') ensure File.delete(temp_file) if File.exist?(temp_file) end end |
#create_modified_temp_file(_base_file = nil) ⇒ Object
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'ext/ae-editor/ae-editor.rb', line 752 def create_modified_temp_file(_base_file=nil) if _base_file # _file = File.join(File.dirname(_base_file),'~~'+File.basename(_base_file)) _file = File.join(Arcadia.instance.local_dir,'~~'+File.basename(_base_file)) else _file = File.join(Arcadia.instance.local_dir,'~~buffer') end f = File.new(_file, "w") begin if f f.syswrite(@modified_source) end ensure f.close unless f.nil? end _file end |
#declaration(_dec_line = '') ⇒ Object
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'ext/ae-editor/ae-editor.rb', line 527 def declaration(_dec_line='') if _dec_line.include?('.new') pre, post = _dec_line.split('.new') dec_line_processed = "#{pre}.new" post.strip! if post if post && post[0..0]=='(' k=0 ch = '(' while k < post.length && ch != ')' k = k+1 ch=post[k..k] end if ch == ')' args = post[1..k-1] args_array = args.split(',') n_args = args_array.length if n_args > 0 new_args = '' 1.upto( n_args ){ if new_args.length > 0 new_args = "#{new_args}," end new_args = "#{new_args}nil" } dec_line_processed = "#{dec_line_processed}(#{new_args})" end end end else dec_line_processed = _dec_line end dec_line_processed end |
#dot_trip(_var_name) ⇒ Object
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'ext/ae-editor/ae-editor.rb', line 492 def dot_trip(_var_name) # ret = "_class=#{_var_name}.class.name\n" ret = "_class=#{_var_name}.class.to_s\n" # ret = ret +"_methods=#{_var_name}.methods\n" ret = ret +"_methods=#{_var_name}.public_methods(includeSuper=true)\n" ret = ret +"owner_on = Method.instance_methods.include?('owner')\n" ret = ret +"_methods.each{|m|\n" ret = ret +"meth = #{_var_name}.method(m)\n" ret = ret +"if owner_on\n" ret = ret +" _owner=meth.owner.name\n" ret = ret +"else\n" ret = ret +" meth_insp = meth.inspect\n" ret = ret +" to_sub ='#<Method:\s'+_class\n" ret = ret +" _owner=meth_insp.sub(to_sub,'').split('#')[0].strip.sub('(','').sub(')','')\n" ret = ret +" _owner=_class if _owner.strip.length==0\n" ret = ret +"end\n" ret = ret +"if _owner != _class\n" ret = ret +' print %Q{#{_owner}##{m}##{meth.arity.to_s}\n}'+"\n" ret = ret +"else\n" ret = ret +' print %Q{##{m}##{meth.arity.to_s}\n}'+"\n" ret = ret +"end\n" ret = ret + "}\n" ret = ret + "exit\n" ret end |
#process_source ⇒ Object
def is_dot?
@is_dot
end
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 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 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'ext/ae-editor/ae-editor.rb', line 565 def process_source super @modified_source = "begin\n" @modified_row = @row+1 @modified_col = @col @class_node = @ss.class_node_by_line(@row) focus_line_to_evaluate = @focus_line @modified_source = "#{@modified_source}Dir.chdir('#{File.dirname(@editor.file)}')\n" if @editor.file @modified_row = @modified_row+1 require_tk = false @source_array.each_with_index{|line,j| # 0) if a comment I do not consider it if line.strip.length > 0 && line.strip[0..0]=='#' @modified_row = @modified_row-1 m = /&require_dir_ref=[\s]*(.)*/.match(line) if m require_dir_ref=line.split('&require_dir_ref=')[1].strip @modified_source = "#{@modified_source}Dir.chdir('#{require_dir_ref}')\n" @modified_row = @modified_row+1 end m = /&require_omissis=[\s]*(.)*/.match(line) if m require_omissis=line.split('&require_omissis=')[1].strip @modified_source = "#{@modified_source}require \"#{require_omissis}\"\n" @modified_row = @modified_row+1 end # 1) include require elsif line.strip.length>7 && (line.strip[0..7]=="require " || line.strip[0..7]=="require(") @modified_source = "#{@modified_source}#{line}\n" if !require_tk && line.strip[8..-1].include?("tk") require_tk = true # @modified_source = "#{@modified_source}Tk.root.destroy if Tk && Tk.root\n" end # 2) include evalueting row with a $SAFE 3 elsif j.to_i == @row-1 focus_line_to_evaluate = line break # 3) eliminiamo la riga else @modified_row = @modified_row-1 end break if j.to_i >= @row - 1 } if require_tk @modified_source = "#{@modified_source}Tk.root.destroy if Tk && Tk.root\n" @modified_row = @modified_row+1 end if focus_line_to_evaluate # search an optional declaration if @focus_world && @focus_world.strip.length > 0 begin re = Regexp::new('[\s\n\t\;]('+@focus_world.strip+')[\s\t]*=(.)*') @source_array.each_with_index do |line,j| #m = /[\s\n\t\;](#{focus_world})[\s\t]*=(.)*/.match(line) if j >= @row-1 break else m = re.match("\s#{line}") if m @dec_line = line @class_dec_line_node = @ss.class_node_by_line(j+1) break end end end rescue Exception => e # Arcadia.console(self, 'msg'=>e.inspect, 'level'=>'error') end end if @class_node to_iniect = "$SAFE = 3\n" if @class_dec_line_node && @class_dec_line_node.label == @class_node.label to_iniect = "#{to_iniect}#{declaration(@dec_line)}\n" end if @focus_world.length > 0 to_iniect = "#{to_iniect}#{dot_trip(@focus_world)}\n" else to_iniect = "#{to_iniect}#{scope_trip}\n" end #to_iniect = "#{to_iniect}#{focus_line}\n" to_iniect_class = @class_node.label else to_iniect = '' to_iniect_class = '' end ss_source = @ss.scheletor_from_node(@ss.root,'',to_iniect, to_iniect_class) ss_source_array = ss_source.split("\n") ss_len = ss_source_array.length if ss_len>0 && ss_source_array[0].strip != focus_line_to_evaluate.strip @modified_source = "#{@modified_source}#{ss_source}" if @class_node @modified_source = "#{@modified_source}#{@class_node.label.downcase} = #{@class_node.label}.new\n" end else ss_len = 0 @class_node = nil end if @class_node @modified_row = @modified_row + @ss.injected_row else @modified_source = "#{@modified_source}$SAFE = 3\n" if @dec_line @modified_source = "#{@modified_source}#{declaration(@dec_line)}\n" @modified_row = @modified_row+1 end #@modified_source = "#{@modified_source}_candidates=@candidates\n" if @focus_world.length > 0 @modified_source = "#{@modified_source}#{dot_trip(@focus_world)}\n" else @modified_source = "#{@modified_source}#{scope_trip}\n" end #@modified_source = "#{@modified_source}@candidates=_candidates\n" #@modified_source = "#{@modified_source}#{focus_line}\n" @modified_row = @modified_row+1+ss_len end end @modified_source = "#{@modified_source}rescue Exception => e\n" @modified_source = "#{@modified_source} if e.class != SystemExit\n" @modified_source = "#{@modified_source} p :ARCADIA_CC_ERROR\n" @modified_source = "#{@modified_source} p e.message\n" @modified_source = "#{@modified_source} end\n" @modified_source = "#{@modified_source}end\n" @modified_row = @modified_row+6 # if @filter.strip.length > 0 && !is_dot? # refresh_words # end # Arcadia.console(self, 'msg'=>@modified_source) # Arcadia.console(self, 'msg'=>"@modified_row=#{@modified_row}") # Arcadia.console(self, 'msg'=>"focus_line=#{focus_line}") if focus_line # Arcadia.console(self, 'msg'=>"focus_world=#{focus_world}") if focus_world # Arcadia.console(self, 'msg'=>"@filter=#{@filter}") if @filter # Arcadia.console(self, 'msg'=>"@dec_line=#{@dec_line}") if @dec_line # Arcadia.console(self, 'msg'=>"declaration(@dec_line)=#{declaration(@dec_line)}") if @dec_line end |
#scope_trip ⇒ Object
518 519 520 521 522 523 524 525 |
# File 'ext/ae-editor/ae-editor.rb', line 518 def scope_trip ret = "ObjectSpace.each_object(Module){|o|\n" ret = ret + " o_name = o.name\n" ret = ret + " print '#'+o_name+'\n' if o_name && o_name.strip.length>0 \n" ret = ret + "}\n" ret = ret + dot_trip('self') ret end |