2021-02-15 10:30:30 -05:00
|
|
|
require 'ripper'
|
|
|
|
require 'irb/ruby-lex'
|
|
|
|
|
|
|
|
class TerminationChecker < RubyLex
|
|
|
|
def terminated?(code)
|
|
|
|
code.gsub!(/\n*$/, '').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
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AutoIndent < RubyLex
|
|
|
|
def initialize
|
|
|
|
set_input(self)
|
2021-08-13 00:44:40 -04:00
|
|
|
context = Struct.new(:auto_indent_mode, :workspace).new(true, nil)
|
2021-02-15 10:30:30 -05:00
|
|
|
set_auto_indent(context)
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_indent(&block)
|
|
|
|
Reline.auto_indent_proc = block
|
|
|
|
end
|
|
|
|
end
|