Common routines for XMPCompletionFilter/XMPDocFilter
# File lib/rcodetools/completion.rb, line 181
181: def __magic_help_code(result, v, meth)
182: code = #{result} = #{v}.method(#{meth}).inspect.match( %r[\\A#<(?:Unbound)?Method: (.*?)>\\Z] )[1].sub(/\\A.*?\\((.*?)\\)(.*)\\Z/){ "\#{$1}\#{$2}" }.sub(/#<Class:(.*?)>#/) { "\#{$1}." } #{result} = #{v}.to_s + ".new" if #{result} == 'Class#new' and #{v}.private_method_defined?(:initialize) #{result} = "Object#" + #{meth} if #{result} =~ /^Kernel#/ and Kernel.instance_methods(false).map{|x| x.to_s}.include? #{meth} #{result}
183: end
# File lib/rcodetools/completion.rb, line 62
62: def _handle_brackets(expr_orig, expr)
63: [ ]{ }], ]( )], %[ ]! ].each do |left, right|
64: n_left = expr_orig.count(left) - expr.count(left)
65: n_right = expr_orig.count(right) - expr.count(right)
66: n = n_left - n_right
67: @postfix << ";#{left}" * n if n >= 0
68: end
69: end
# File lib/rcodetools/completion.rb, line 55
55: def _handle_do_end(right_stripped)
56: right_stripped << "\n"
57: n_do = right_stripped.scan(/[\s\)]do\s/).length
58: n_end = right_stripped.scan(/\bend\b/).length
59: @postfix = ";begin" * (n_do - n_end)
60: end
# File lib/rcodetools/completion.rb, line 71
71: def _handle_keywords(expr_orig, column)
72: ]if unless while until for].each do |keyw|
73: pos = expr_orig.index(/\b#{keyw}\b/)
74: @postfix << ";begin" if pos and pos < column # if * xxx
75:
76: pos = expr_orig.index(/;\s*#{keyw}\b/)
77: @postfix << ";begin" if pos and column < pos # * ; if xxx
78: end
79: end
# File lib/rcodetools/completion.rb, line 140
140: def add_BEGIN
141: BEGIN {class Object def method_missing(meth, *args, &block) # ignore NoMethodError endend}
142: end
# File lib/rcodetools/completion.rb, line 81
81: def aref_or_aset?(right_stripped, last_char)
82: if last_char == [[
83: case right_stripped
84: when /\]\s*=/ then "[]="
85: when /\]/ then "[]"
86: end
87: end
88: end
# File lib/rcodetools/completion.rb, line 118
118: def current_phrase(expr)
119: paren_level = 0
120: start = 0
121: (expr.length-1).downto(0) do |i|
122: c = expr[i,1]
123: if c =~ /[\)\}\]]/
124: paren_level += 1
125: next
126: end
127: if paren_level > 0
128: next if c =~ /[, ]/
129: else
130: break (start = i+1) if c =~ /[ ,\(\{\[]/
131: end
132: if c =~ /[\(\{\[]/
133: paren_level -= 1
134: break (start = i+1) if paren_level < 0
135: end
136: end
137: expr[start..1]
138: end
# File lib/rcodetools/completion.rb, line 11
11: def fill_literal!(expr)
12: [ "\"", "'", "`" ].each do |q|
13: expr.gsub!(/#{q}(.+)#{q}/){ '"' + "x"*$1.length + '"' }
14: end
15: expr.gsub!(/(%([wWqQxrs])?(\W))(.+?)\33//){
16: percent = $2 == 'x' ? '%'+$3 : $1 # avoid executing shell command
17: percent + "x"*$4.length + $3
18: }
19: [ ]( )], ]{ }], %[ ]!, ]< >] ].each do |b,e|
20: rb, re = [b,e].map{ |x| Regexp.quote(x)}
21: expr.gsub!(/(%([wWqQxrs])?(#{rb}))(.+)#{re}/){
22: percent = $2 == 'x' ? '%'+$3 : $1 # avoid executing shell command
23: percent + "x"*$4.length + e
24: }
25: end
26: end
# File lib/rcodetools/completion.rb, line 177
177: def runtime_data(code, lineno, column=nil)
178: runtime_data_with_class(code, lineno, column)[1]
179: end
# File lib/rcodetools/completion.rb, line 154
154: def runtime_data_with_class(code, lineno, column=nil)
155: newcode = code.to_a.enum_with_index.map{|line, i|
156: i+1==lineno ? prepare_line(line.chomp, column) : line
157: }.join
158: newcode << add_BEGIN if @ignore_NoMethodError
159: debugprint "newcode", newcode.gsub(/;/, "\n"), "-"*80
160: stdout, stderr = execute(newcode)
161: output = stderr.readlines
162: debugprint "stderr", output, "-"*80
163: output = output.reject{|x| /^-:[0-9]+: warning/.match(x)}
164: runtime_data = extract_data(output)
165: if exception = /^-:[0-9]+:.*/.match(output.join)
166: raise NewCodeError, exception[0].chomp
167: end
168: begin
169: dat = runtime_data.results[1][0]
170: debugprint "dat = #{dat.inspect}"
171: [dat[0], dat[1..1].to_s]
172: rescue
173: raise RuntimeDataError, runtime_data.inspect
174: end
175: end
# File lib/rcodetools/completion.rb, line 33
33: def set_expr_and_postfix!(expr, column, ®exp)
34: expr.extend ExpressionExtension
35:
36: @postfix = ""
37: expr_orig = expr.clone
38: column ||= expr.length
39: last_char = expr[column-1]
40: expr.replace expr[ regexp[column] ]
41: debugprint "expr_orig=#{expr_orig}", "expr(sliced)=#{expr}"
42: right_stripped = Regexp.last_match.post_match
43: _handle_do_end right_stripped
44: aref_or_aset = aref_or_aset? right_stripped, last_char
45: debugprint "aref_or_aset=#{aref_or_aset.inspect}"
46: set_last_word! expr, aref_or_aset
47: fill_literal! expr_orig
48: _handle_brackets expr_orig, expr
49: expr << aref_or_aset if aref_or_aset
50: _handle_keywords expr_orig, column
51: debugprint "expr(processed)=#{expr}"
52: expr
53: end
# File lib/rcodetools/completion.rb, line 90
90: def set_last_word!(expr, aref_or_aset=nil)
91: debugprint "expr(before set_last_word)=#{expr}"
92: if aref_or_aset
93: opchars = ""
94: else
95: opchars = expr.slice!(/\s*[#{OPERATOR_CHARS}]+$/)
96: debugprint "expr(strip opchars)=#{expr}"
97: end
98:
99: expr.replace(if expr =~ /[\"\'\`]$/ # String operations
100: "''"
101: else
102: fill_literal! expr
103: phrase = current_phrase(expr)
104: if aref_or_aset
105: expr.eval_string = expr[0..2]
106: expr.meth = aref_or_aset
107: elsif phrase.match( /^(.+)\.(.*)$/ )
108: expr.eval_string, expr.meth = $1, $2
109: elsif opchars != ''
110: expr
111: end
112: debugprint "expr.eval_string=#{expr.eval_string}", "expr.meth=#{expr.meth}"
113: phrase
114: end << (opchars || '')) # ` font-lock hack
115: debugprint "expr(after set_last_word)=#{expr}"
116: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.