Class: Pione::Command::PioneSyntaxChecker

Inherits:
BasicCommand show all
Defined in:
lib/pione/command/pione-syntax-checker.rb

Overview

PioneSyntaxChecker is a command for checking syntax tree and model of the PIONE document.

Instance Attribute Summary

Attributes inherited from BasicCommand

#option, #running_thread

Instance Method Summary collapse

Methods inherited from BasicCommand

#abort, command_banner, command_front, command_name, #enter_phase, execute, #execution?, execution_phase, #exit, handle_exception, handle_execution_exception, handle_setup_exception, handle_termination_exception, inherited, init, #init?, init_phase, option_parser_mode, #run, run, setup, #setup?, setup_phase, #terminate, terminate, #termination?, termination_phase

Constructor Details

#initialize(*argv) ⇒ PioneSyntaxChecker

instance methods



68
69
70
71
# File 'lib/pione/command/pione-syntax-checker.rb', line 68

def initialize(*argv)
  super
  @history = File.join(Global.dot_pione_dir, "pione-history")
end

Instance Method Details

#execute_exprObject



129
130
131
132
# File 'lib/pione/command/pione-syntax-checker.rb', line 129

def execute_expr
  parser_name = option[:parser] ? option[:parser] : :expr
  print_result(DocumentParser.new.send(parser_name), option[:expr])
end

#execute_fileObject



125
126
127
# File 'lib/pione/command/pione-syntax-checker.rb', line 125

def execute_file
  print_result(DocumentParser.new, Pathname.new(option[:document]).read)
end

#execute_readline_modeObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/pione/command/pione-syntax-checker.rb', line 97

def execute_readline_mode
  buf = ""
  mark = ">"

  # start loop
  while buf += Readline.readline("#{mark} ".color(:red), true)
    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(DocumentParser.new.expr, buf)
        buf = ""
        mark = ">"
      end
    else
      # don't record if it is an empty line
      Readline::HISTORY.pop
    end
  end
end

#setup_ppObject



80
81
82
# File 'lib/pione/command/pione-syntax-checker.rb', line 80

def setup_pp
  require 'pp'
end

#setup_readline_modeObject



84
85
86
87
# File 'lib/pione/command/pione-syntax-checker.rb', line 84

def setup_readline_mode
  require 'readline'
  restore_history
end

#terminate_historyObject



140
141
142
# File 'lib/pione/command/pione-syntax-checker.rb', line 140

def terminate_history
  save_history if readline_mode?
end