summaryrefslogtreecommitdiff
path: root/test/reline/yamatanooroti/termination_checker.rb
blob: 9c2c3ae740e602c4c806ec662d5d8151ffe8365f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
    context = Struct.new(:auto_indent_mode, :workspace).new(true, nil)
    set_auto_indent(context)
  end

  def auto_indent(&block)
    Reline.auto_indent_proc = block
  end
end