Class: Rcodetools::XMPDocFilter

Inherits:
XMPFilter show all
Includes:
ProcessParticularLine
Defined in:
lib/rcodetools/doc.rb

Defined Under Namespace

Modules: UseMethodAnalyzer

Constant Summary

Constants included from ProcessParticularLine

ProcessParticularLine::OPERATOR_CHARS

Constants inherited from XMPFilter

Rcodetools::XMPFilter::INITIALIZE_OPTS, Rcodetools::XMPFilter::INTERPRETER_FORK, Rcodetools::XMPFilter::INTERPRETER_RBTEST, Rcodetools::XMPFilter::INTERPRETER_RUBY, Rcodetools::XMPFilter::MARKER, Rcodetools::XMPFilter::MULTI_LINE_RE, Rcodetools::XMPFilter::SINGLE_LINE_RE, Rcodetools::XMPFilter::VAR, Rcodetools::XMPFilter::VERSION, Rcodetools::XMPFilter::WARNING_RE, Rcodetools::XMPFilter::XMP_RE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ProcessParticularLine

#__magic_help_code, #_handle_brackets, #_handle_do_end, #_handle_keywords, #add_BEGIN, #aref_or_aset?, #current_phrase, #fill_literal!, #runtime_data, #runtime_data_with_class, #set_expr_and_postfix!, #set_last_word!

Methods inherited from XMPFilter

#add_markers, #annotate, #annotated_line, #annotated_multi_line, #common_path, #debugprint, detect_rbtest, #execute, #execute_popen, #execute_ruby, #execute_script, #execute_tmpfile, #extract_data, #final_decoration, #get_test_method_from_lineno, #initialize_for_test_script, #initialize_rbtest, #initialize_rct_fork, #interpreter_command, #oneline_ize, #prepare_line_annotation, #windows?

Constructor Details

#initialize(opts = {}) ⇒ XMPDocFilter

Returns a new instance of XMPDocFilter.



9
10
11
12
13
# File 'lib/rcodetools/doc.rb', line 9

def initialize(opts = {})
  super
  @filename = opts[:filename]
  extend UseMethodAnalyzer if opts[:use_method_analyzer]
end

Class Method Details

.run(code, opts) ⇒ Object



15
16
17
# File 'lib/rcodetools/doc.rb', line 15

def self.run(code, opts)
  new(opts).doc(code, opts[:lineno], opts[:column])
end

Instance Method Details

#__prepare_line(x) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rcodetools/doc.rb', line 49

def __prepare_line(x)
  v = "#{VAR}"
  result = "#{VAR}_result"
  klass = "#{VAR}_klass"
  flag = "#{VAR}_flag"
  which_methods = "#{VAR}_methods"
  ancestor_class = "#{VAR}_ancestor_class"
  idx = 1
  recv = x[:recv] || x[:klass] || raise(ArgumentError, "need :recv or :klass")
  meth = x[:meth_or_constant] || x[:meth]
  debugprint "recv=#{recv}", "meth=#{meth}"
  if meth
    # imported from fastri/MagicHelp
    code = <<-EOC
#{v} = (#{recv})
$stderr.print("#{MARKER}[#{idx}] => " + #{v}.class.to_s  + " ")

if Module === #{v} and '#{meth}' =~ /^[A-Z]/ and #{v}.const_defined?('#{meth}')
#{result} = #{v}.to_s + "::#{meth}"
else
#{__magic_help_code result, v, meth.dump}
end

$stderr.puts(#{result})
exit
    EOC
  else
    code = <<-EOC
#{v} = (#{recv})
$stderr.print("#{MARKER}[#{idx}] => " + #{v}.class.to_s  + " ")
$stderr.puts(#{v}.to_s)
exit
    EOC
  end
  oneline_ize(code)
end

#_doc(code, lineno, column) ⇒ Object

overridable by module



87
88
# File 'lib/rcodetools/doc.rb', line 87

def _doc(code, lineno, column)
end

#doc(code, lineno, column = nil) ⇒ Object



90
91
92
# File 'lib/rcodetools/doc.rb', line 90

def doc(code, lineno, column=nil)
  _doc(code, lineno, column) or runtime_data(code, lineno, column).to_s
end

#prepare_line(expr, column) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rcodetools/doc.rb', line 19

def prepare_line(expr, column)
  set_expr_and_postfix!(expr, column){|c| 
    withop_re = /^.{#{c-1}}[#{OPERATOR_CHARS}]+/
    if expr =~ withop_re
      withop_re
    else
      /^.{#{c}}[\w#{OPERATOR_CHARS}]*/
    end
  }
  recv = expr

  # When expr already knows receiver and method,
  return(__prepare_line :recv => expr.eval_string, :meth => expr.meth) if expr.eval_string

  case expr
  when /^(?:::)?([A-Z].*)(?:::|\.)(.*)$/    # nested constants / class methods
    __prepare_line :klass => $1, :meth_or_constant => $2
  when /^(?:::)?[A-Z]/               # normal constants
    __prepare_line :klass => expr
  when /\.([^.]*)$/             # method call
    __prepare_line :recv => Regexp.last_match.pre_match, :meth => $1
  when /^(.+)(\[\]=?)$/                   # [], []=
    __prepare_line :recv => $1, :meth => $2
  when /[#{OPERATOR_CHARS}]+$/                   # operator
    __prepare_line :recv => Regexp.last_match.pre_match, :meth => $&
  else                        # bare words
    __prepare_line :recv => "self", :meth => expr
  end
end