aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb/ruby-lex.rb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-06-14 08:26:06 +0900
committeraycabta <aycabta@gmail.com>2019-06-14 08:26:06 +0900
commitf80771f0a989efdde2276d4d6d213cb096843e92 (patch)
treebf929fc702b512cc48aa9bd168f45433d8b090c9 /lib/irb/ruby-lex.rb
parent3757e492fb815656341dd430465e0f069e1bd562 (diff)
downloadruby-f80771f0a989efdde2276d4d6d213cb096843e92.tar.gz
Use Reline.prompt_proc in IRB
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r--lib/irb/ruby-lex.rb29
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index a57a5dfcd9..2c2dfd850a 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -33,18 +33,26 @@ class RubyLex
if @io.respond_to?(:check_termination)
@io.check_termination do |code|
code.gsub!(/\s*\z/, '').concat("\n")
- @tokens = Ripper.lex(code)
- continue = process_continue
- code_block_open = check_code_block(code)
- indent = process_nesting_level
- ltype = process_literal_type
- if code_block_open or ltype or continue or indent > 0
+ ltype, indent, continue, code_block_open = check_state(code)
+ if ltype or indent > 0 or continue or code_block_open
false
else
true
end
end
end
+ if @io.respond_to?(:dynamic_prompt)
+ @io.dynamic_prompt do |lines, base_line_no|
+ lines << '' if lines.empty?
+ result = []
+ lines.each_index { |i|
+ c = lines[0..i].map{ |l| l + "\n" }.join
+ ltype, indent, continue, code_block_open = check_state(c)
+ result << @prompt.call(ltype, indent, continue, base_line_no + i)
+ }
+ result
+ end
+ end
if p.respond_to?(:call)
@input = p
elsif block_given?
@@ -63,6 +71,15 @@ class RubyLex
end
end
+ def check_state(code)
+ @tokens = Ripper.lex(code)
+ ltype = process_literal_type
+ indent = process_nesting_level
+ continue = process_continue
+ code_block_open = check_code_block(code)
+ [ltype, indent, continue, code_block_open]
+ end
+
def prompt
if @prompt
@prompt.call(@ltype, @indent, @continue, @line_no)