Skip to content

Commit ac48c48

Browse files
committed
rename and move 'more' command to expression_info; set string encoding for stringIO
1 parent 40b4652 commit ac48c48

File tree

2 files changed

+56
-34
lines changed

2 files changed

+56
-34
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
require 'stringio'
2+
require 'irb/ruby-lex'
3+
4+
module Debugger
5+
6+
class ExpressionInfoCommand < Command
7+
def regexp
8+
/^\s*ex(?:pression_info)?\s+/
9+
end
10+
11+
def execute
12+
string_to_parse = @match.post_match.gsub("\\n", "\n") + "\n\n\n"
13+
14+
lexer = RubyLex.new
15+
io = StringIO.new(string_to_parse)
16+
# for passing to the lexer
17+
io.instance_exec(string_to_parse.encoding) do |string_encoding|
18+
@my_encoding = string_encoding
19+
def self.encoding
20+
@my_encoding
21+
end
22+
end
23+
24+
lexer.set_input(io)
25+
lexer.set_prompt {|ltype, indent, continue, lineno| }
26+
27+
last_statement = '',0
28+
lexer.each_top_level_statement do |line, line_no|
29+
last_statement = line, line_no
30+
end
31+
32+
result = true
33+
if /\A\s*\Z/m =~ last_statement[0]
34+
result = false
35+
end
36+
37+
@printer.print_pp("<expressionInfo incomplete=\"#{result.to_s}\"></expressionInfo>")
38+
end
39+
40+
class << self
41+
def help_command
42+
"expression_info"
43+
end
44+
45+
def help(cmd)
46+
%{
47+
ex[pression_info] <expression>\t
48+
returns parser-related information for the expression given\t\t
49+
'incomplete'=true|false\tindicates whether expression is a complete ruby
50+
expression and can be evaluated without getting syntax errors
51+
}
52+
end
53+
end
54+
end
55+
56+
end

lib/ruby-debug-ide/commands/inspect.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,4 @@ def execute
2222
end
2323
end
2424

25-
class MoreCommand < Command
26-
def regexp
27-
/^\s*more\s+/
28-
end
29-
30-
def execute
31-
require 'stringio'
32-
require 'irb/ruby-lex'
33-
34-
string_to_parse = @match.post_match.gsub("\\n", "\n") + "\n\n\n"
35-
36-
lexer = RubyLex.new
37-
io = StringIO.new(string_to_parse)
38-
# for passing to the lexer
39-
def io.encoding
40-
"utf-8"
41-
end
42-
lexer.set_input(io)
43-
lexer.set_prompt {|ltype, indent, continue, lineno| }
44-
45-
last_statement = '',0
46-
lexer.each_top_level_statement do |line, line_no|
47-
last_statement = line, line_no
48-
end
49-
50-
result = 1
51-
if /\A\s*\Z/m =~ last_statement[0]
52-
result = 0
53-
end
54-
55-
@printer.print_pp("<more value=\"#{result.to_s}\"></more>")
56-
end
57-
end
58-
5925
end

0 commit comments

Comments
 (0)