rib 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
1
  before_install: 'git submodule update --init'
2
2
  script: 'ruby -r bundler/setup -S rake test'
3
3
 
4
+ env:
5
+ - 'RBXOPT=-X19'
6
+
4
7
  rvm:
5
8
  - 1.9.2
6
9
  - 1.9.3
7
- - rbx-19mode
8
- - jruby-19mode
10
+ - rbx-head
11
+ - jruby-head
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGES
2
2
 
3
+ ## Rib 1.1.1 -- 2013-01-25
4
+
5
+ * Fixed some multiline issue with Rubinius and JRuby.
6
+ * Properly indent for multiline prompt.
7
+ * Removed ripl compatibility layer.
8
+ * Only retry 5 times upon failures. This prevents from infinite retries.
9
+ * Don't retry on quiting.
10
+ * Added a half-baked debugger support. Try it with:
11
+ `require 'rib/extra/debugger'; Rib.debug`
12
+
3
13
  ## Rib 1.1.0 -- 2012-07-18
4
14
 
5
15
  * Support for Ruby 1.8 is dropped.
data/lib/rib/api.rb CHANGED
@@ -1,8 +1,6 @@
1
1
 
2
2
  module Rib; end
3
3
  module Rib::API
4
- extend self
5
-
6
4
  # Called before shell starts looping
7
5
  def before_loop
8
6
  self
@@ -25,6 +23,10 @@ module Rib::API
25
23
  def eval_binding ; config[:binding] ; end
26
24
  # The line number for next evaluation
27
25
  def line ; config[:line] ; end
26
+ # The object for the current binding
27
+ def bound_object
28
+ config[:bound_object] ||= eval_binding.eval('self', __FILE__, __LINE__)
29
+ end
28
30
 
29
31
  # Main loop
30
32
  def in_loop
@@ -43,12 +43,15 @@ module Rib::Multiline
43
43
  # mri and rubinius
44
44
  "syntax error, unexpected \\$end" ,
45
45
  # rubinius
46
+ "expecting \\$end" ,
46
47
  "expecting '.+'( or '.+')*" ,
47
48
  "missing '.+' for '.+' started on line \\d+"].join('|'))
48
49
  when 'jruby'; Regexp.new(
49
50
  [ # string or regexp
50
51
  "unterminated \\w+ meets end of file",
51
52
  # jruby
53
+ "syntax error, unexpected" \
54
+ " t(UPLUS|UMINUS|STAR|REGEXP_BEG|AMPER)",
52
55
  "syntax error, unexpected end-of-file"] .join('|'))
53
56
  end
54
57
 
@@ -84,7 +87,8 @@ module Rib::Multiline
84
87
  if multiline_buffer.empty?
85
88
  super
86
89
  else
87
- "#{' '*(config[:prompt].size-2)}| "
90
+ mprompt = multiline_prompt[0, config[:prompt].size]
91
+ "#{' '*(config[:prompt].size-mprompt.size)}#{mprompt}"
88
92
  end
89
93
  end
90
94
 
@@ -105,6 +109,9 @@ module Rib::Multiline
105
109
  err.is_a?(SyntaxError) && err.message =~ ERROR_REGEXP
106
110
  end
107
111
 
112
+ def multiline_prompt
113
+ config[:multiline_prompt] ||= '| '
114
+ end
108
115
 
109
116
 
110
117
  private
@@ -10,7 +10,12 @@ module Rib::StripBacktrace
10
10
  # strip backtrace until rib
11
11
  def format_error err
12
12
  return super if StripBacktrace.disabled?
13
- message, backtrace = get_error(err, strip_backtrace(err))
13
+ backtrace = if err.kind_of?(SyntaxError)
14
+ []
15
+ else
16
+ err.backtrace
17
+ end
18
+ message, backtrace = get_error(err, strip_backtrace(backtrace))
14
19
  "#{message}\n #{backtrace.join("\n ")}"
15
20
  end
16
21
 
@@ -23,9 +28,9 @@ module Rib::StripBacktrace
23
28
 
24
29
 
25
30
 
26
- private
27
- def strip_backtrace err
28
- strip_home_backtrace(strip_cwd_backtrace(strip_lib_backtrace(err)))
31
+ module_function
32
+ def strip_backtrace backtrace
33
+ strip_home_backtrace(strip_cwd_backtrace(strip_lib_backtrace(backtrace)))
29
34
  end
30
35
 
31
36
  def strip_home_backtrace backtrace
@@ -36,10 +41,8 @@ module Rib::StripBacktrace
36
41
  backtrace.map{ |path| path.sub(Dir.pwd, '.') }
37
42
  end
38
43
 
39
- def strip_lib_backtrace err
40
- return [] if err.kind_of?(SyntaxError)
41
- err.backtrace[
42
- 0..
43
- err.backtrace.rindex{ |l| l =~ /\(#{name}\):\d+:in `.+?'/ } || -1]
44
+ def strip_lib_backtrace backtrace
45
+ backtrace[
46
+ 0..backtrace.rindex{ |l| l =~ /\(#{name}\):\d+:in `.+?'/ } || -1]
44
47
  end
45
48
  end
@@ -29,12 +29,6 @@ module Rib::Underscore
29
29
  super
30
30
  end
31
31
 
32
- # --------------- Plugin API ---------------
33
-
34
- def bound_object
35
- config[:bound_object] ||= eval_binding.eval('self', __FILE__, __LINE__)
36
- end
37
-
38
32
 
39
33
 
40
34
  private
data/lib/rib/debug.rb CHANGED
@@ -2,3 +2,4 @@
2
2
  require 'rib/config'
3
3
  require 'rib/more/anchor'
4
4
  Rib::Anchor.disable
5
+ Rib::Debugger.disable if Rib.const_defined?(:Debugger)
@@ -0,0 +1,146 @@
1
+
2
+ require 'rib/more/anchor'
3
+
4
+ module Rib::Debugger
5
+ extend Rib::Plugin
6
+ Shell.use(self)
7
+
8
+ ExcludedCommands = %w[irb quit exit backtrace eval p pp ps]
9
+ WrappedCommands = %w[help where edit reload]
10
+
11
+ # --------------- Rib API ---------------
12
+
13
+ def before_loop
14
+ return super if Debugger.disabled?
15
+ ::Debugger.handler = self
16
+ bound_object.extend(Imp)
17
+ @debugger_state ||= config[:debugger_state]
18
+ @debugger_watch ||= config[:debugger_watch]
19
+ bound_object.display(debugger_watch.shift) until debugger_watch.empty?
20
+ super
21
+ end
22
+
23
+ # --------------- Plugin API ---------------
24
+
25
+ def debugger_watch
26
+ @debugger_watch ||= []
27
+ end
28
+
29
+ def debugger_state
30
+ @debugger_state ||= config[:debugger_state] ||
31
+ ::Debugger::CommandProcessor::State.new{ |s|
32
+ commands = ::Debugger::Command.commands.select{ |cmd|
33
+ cmd.event &&
34
+ (!config[:debugger_context].dead? || cmd.allow_in_post_mortem) &&
35
+ !ExcludedCommands.include?([cmd.help_command].flatten.first)
36
+ }
37
+
38
+ s.context = config[:debugger_context]
39
+ s.file = config[:debugger_file]
40
+ s.line = config[:debugger_line]
41
+ s.binding = config[:debugger_context].frame_binding(0)
42
+ s.display = []
43
+ s.interface = ::Debugger::LocalInterface.new
44
+ s.commands = commands
45
+ }
46
+ end
47
+
48
+ # Callback for the debugger
49
+ def at_line context, file, line
50
+ return if Debugger.disabled?
51
+ path = "#{file}:#{line}:in #{caller[1][/`.+?'/]}"
52
+ msg0 = if Rib.const_defined?(:StripBacktrace) && StripBacktrace.enabled?
53
+ StripBacktrace.strip_backtrace([path])
54
+ else
55
+ [path]
56
+ end
57
+ msg1 = if Rib.const_defined?(:Color) && Color.enabled?
58
+ Color.colorize_backtrace(msg0)
59
+ else
60
+ [msg0].flatten
61
+ end
62
+
63
+ Rib.say(msg1.first)
64
+
65
+ if @debugger_state
66
+ @debugger_state.context = context
67
+ @debugger_state.file = file
68
+ @debugger_state.line = line
69
+ end
70
+ Rib::Anchor.enable
71
+ Rib.anchor(context.frame_binding(0), :prompt_anchor => false,
72
+ :debugger_context => context,
73
+ :debugger_file => file ,
74
+ :debugger_line => line ,
75
+ :debugger_state => @debugger_state,
76
+ :debugger_watch => @debugger_watch)
77
+ ::Debugger.stop
78
+ rescue Exception => e
79
+ Rib.warn("Error while calling at_line:\n #{format_error(e)}")
80
+ end
81
+
82
+ module Imp
83
+ def debug
84
+ return if Rib::Debugger.disabled?
85
+ ::Debugger.handler = Rib.shell
86
+ ::Debugger.start
87
+ ::Debugger.current_context.stop_frame = 0
88
+ end
89
+
90
+ # You can `Rib.watch` a number of expressions before calling `Rib.debug`
91
+ def watch *strs
92
+ Rib.shell.debugger_watch.concat(strs)
93
+ end
94
+
95
+ def step times=1
96
+ ::Debugger.current_context.step(times)
97
+ display
98
+ throw :rib_exit, Rib::Skip
99
+ end
100
+
101
+ WrappedCommands.each{ |cmd|
102
+ module_eval <<-RUBY
103
+ def #{cmd} *args
104
+ debugger_execute('#{cmd}', args)
105
+ end
106
+ RUBY
107
+ }
108
+
109
+ def display *args
110
+ if args.empty?
111
+ debugger_execute('display', args, 'Display')
112
+ else
113
+ debugger_execute('display', args, 'AddDisplay')
114
+ end
115
+ end
116
+ alias_method :disp, :display
117
+
118
+ def list *args
119
+ debugger_execute('list', args, 'List', Rib.shell.debugger_state.dup)
120
+ end
121
+ alias_method :ls, :list
122
+
123
+ def debugger_execute command, args=[], name=command.capitalize,
124
+ state=Rib.shell.debugger_state
125
+ const = "#{name}Command"
126
+ arg = if args.empty? then '' else " #{args.join(' ')}" end
127
+ cmd = ::Debugger.const_get(const).new(state)
128
+ cmd.match("#{command}#{arg}\n")
129
+ cmd.execute
130
+ Rib::Skip
131
+ end
132
+ end
133
+
134
+ Rib.extend(Imp)
135
+ end
136
+
137
+ begin
138
+ Rib.silence{ require 'debugger' }
139
+ require 'rib/patch/debugger'
140
+ rescue LoadError => e
141
+ Rib.warn("Error: #{e}" ,
142
+ "Please install debugger to use debugger plugin:\n",
143
+ " gem install debugger\n" ,
144
+ "Or add debugger to Gemfile if that's the case")
145
+ Rib::Debugger.disable
146
+ end
@@ -0,0 +1,13 @@
1
+
2
+ # never make those convenient methods public!
3
+ Kernel.module_eval{ private :debugger }
4
+
5
+ # remove alias 'backtrace'
6
+ class ::Debugger::WhereCommand
7
+ def self.help_command
8
+ 'where'
9
+ end
10
+ end
11
+
12
+ # please have a more consistent name
13
+ ::Debugger::EditCommand = ::Debugger::Edit
data/lib/rib/runner.rb CHANGED
@@ -76,13 +76,22 @@ module Rib::Runner
76
76
  loop
77
77
  end
78
78
 
79
- def loop
79
+ def loop retry_times=5
80
80
  Rib.shell.loop
81
- rescue Exception
82
- Rib.warn("Relaunching a new shell...")
83
- Rib.shells.pop
84
- Rib.shells << Rib::Shell.new(Rib.config)
85
- retry
81
+ rescue Exception => e
82
+ if retry_times <= 0
83
+ Rib.warn("Error: #{e}. Too many retries, give up.")
84
+ elsif Rib.shells.last.running?
85
+ Rib.warn("Error: #{e}. Relaunching a new shell... ##{retry_times}")
86
+ Rib.warn("Backtrace: #{e.backtrace}") if $VERBOSE
87
+ Rib.shells.pop
88
+ Rib.shells << Rib::Shell.new(Rib.config)
89
+ retry_times -= 1
90
+ retry
91
+ else
92
+ Rib.warn("Error: #{e}. Closing.")
93
+ Rib.warn("Backtrace: #{e.backtrace}") if $VERBOSE
94
+ end
86
95
  end
87
96
 
88
97
  def parse argv
@@ -39,6 +39,15 @@ shared :multiline do
39
39
  setup_shell
40
40
  end
41
41
 
42
+ should 'work with no prompt' do
43
+ @shell.config[:prompt] = ''
44
+ check <<-RUBY
45
+ def f
46
+ 0
47
+ end
48
+ RUBY
49
+ end
50
+
42
51
  should 'def f' do
43
52
  check <<-RUBY
44
53
  def f
data/lib/rib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rib
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
data/rib.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rib"
5
- s.version = "1.1.0"
5
+ s.version = "1.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2012-07-18"
9
+ s.date = "2013-01-25"
10
10
  s.description = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell\n\nRib is based on the design of [ripl][] and the work of [ripl-rc][], some of\nthe features are also inspired by [pry][]. The aim of Rib is to be fully\nfeatured and yet very easy to opt-out or opt-in other features. It shall\nbe simple, lightweight and modular so that everyone could customize Rib.\n\n[ripl]: https://github.com/cldwalker/ripl\n[ripl-rc]: https://github.com/godfat/ripl-rc\n[pry]: https://github.com/pry/pry"
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.executables = [
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
49
49
  "lib/rib/core/underscore.rb",
50
50
  "lib/rib/debug.rb",
51
51
  "lib/rib/extra/autoindent.rb",
52
+ "lib/rib/extra/debugger.rb",
52
53
  "lib/rib/extra/hirb.rb",
53
54
  "lib/rib/more.rb",
54
55
  "lib/rib/more/anchor.rb",
@@ -56,8 +57,8 @@ Gem::Specification.new do |s|
56
57
  "lib/rib/more/edit.rb",
57
58
  "lib/rib/more/multiline_history.rb",
58
59
  "lib/rib/more/multiline_history_file.rb",
60
+ "lib/rib/patch/debugger.rb",
59
61
  "lib/rib/plugin.rb",
60
- "lib/rib/ripl.rb",
61
62
  "lib/rib/runner.rb",
62
63
  "lib/rib/shell.rb",
63
64
  "lib/rib/test.rb",
@@ -80,7 +81,7 @@ Gem::Specification.new do |s|
80
81
  "test/test_shell.rb"]
81
82
  s.homepage = "https://github.com/godfat/rib"
82
83
  s.require_paths = ["lib"]
83
- s.rubygems_version = "1.8.24"
84
+ s.rubygems_version = "1.8.23"
84
85
  s.summary = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell"
85
86
  s.test_files = [
86
87
  "test/core/test_completion.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
15
15
 
@@ -72,6 +72,7 @@ files:
72
72
  - lib/rib/core/underscore.rb
73
73
  - lib/rib/debug.rb
74
74
  - lib/rib/extra/autoindent.rb
75
+ - lib/rib/extra/debugger.rb
75
76
  - lib/rib/extra/hirb.rb
76
77
  - lib/rib/more.rb
77
78
  - lib/rib/more/anchor.rb
@@ -79,8 +80,8 @@ files:
79
80
  - lib/rib/more/edit.rb
80
81
  - lib/rib/more/multiline_history.rb
81
82
  - lib/rib/more/multiline_history_file.rb
83
+ - lib/rib/patch/debugger.rb
82
84
  - lib/rib/plugin.rb
83
- - lib/rib/ripl.rb
84
85
  - lib/rib/runner.rb
85
86
  - lib/rib/shell.rb
86
87
  - lib/rib/test.rb
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  version: '0'
122
123
  requirements: []
123
124
  rubyforge_project:
124
- rubygems_version: 1.8.24
125
+ rubygems_version: 1.8.23
125
126
  signing_key:
126
127
  specification_version: 3
127
128
  summary: Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
@@ -137,4 +138,3 @@ test_files:
137
138
  - test/test_api.rb
138
139
  - test/test_plugin.rb
139
140
  - test/test_shell.rb
140
- has_rdoc:
data/lib/rib/ripl.rb DELETED
@@ -1,3 +0,0 @@
1
-
2
- Ripl = Rib
3
- Ripl::Shell.singleton_class.send(:public, :include)