class Pione::Command::PioneLangInteractiveContext

Public Instance Methods

print_result(parser, str) click to toggle source

Print parsing result of the string.

start_readline() click to toggle source
# File lib/pione/command/pione-lang-interactive.rb, line 89
def start_readline
  buf = ""
  mark = ">"

  # start loop
  while line = Readline.readline("#{mark} ".color(:red), true)
    buf += line
    if /[^\s]/.match(buf)
      # don't record if previous line is the same
      if Readline::HISTORY.size > 1 && Readline::HISTORY[-2] == buf
        Readline::HISTORY.pop
      end
      if buf[-1] == "\\"
        buf[-1] = "\n"
        mark = "+"
        next
      else
        # print parsing result
        print_result(Lang::DocumentParser.new.expr, buf)
        buf = ""
        mark = ">"
      end
    else
      # don't record if it is an empty line
      Readline::HISTORY.pop
    end
  end
end