2017-09-04 09:19:29 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
$:.insert(0, 'lib')
|
|
|
|
|
|
|
|
require 'thor'
|
2017-09-07 15:05:06 +00:00
|
|
|
require 'rly'
|
|
|
|
require 'pry'
|
2017-09-12 13:32:50 +00:00
|
|
|
require 'mm2ep_depend'
|
2017-09-12 14:23:44 +00:00
|
|
|
require 'pp'
|
2017-09-20 15:49:54 +00:00
|
|
|
require 'logger'
|
2017-09-04 09:19:29 +00:00
|
|
|
|
|
|
|
module Mm2ep
|
|
|
|
module Depend
|
|
|
|
|
|
|
|
class ParseCli < Thor
|
2017-09-20 15:49:54 +00:00
|
|
|
desc 'parse OPTIONS INFILE VARS', 'Parse INFILE into tokens and evaluate VARS'
|
|
|
|
method_option :logfile, :aliases => "-l", :desc => "Logger with logfile"
|
|
|
|
method_option :stdout, :aliases => "-f", :desc => "Logger with STDOUT"
|
2017-09-13 12:55:56 +00:00
|
|
|
def parse(infile, *vars)
|
2017-09-20 15:49:54 +00:00
|
|
|
logger = Logger.new('illegal_character.log') if options[:logfile]
|
|
|
|
logger = Logger.new(STDOUT) if options[:stdout]
|
2017-09-12 14:35:11 +00:00
|
|
|
line = File.read(infile).gsub(/\n/,'')
|
2017-09-20 15:49:54 +00:00
|
|
|
lexer = Lexer.new(logger)
|
|
|
|
parser = Parser.new(lexer)
|
2017-09-13 14:51:11 +00:00
|
|
|
tab_vars = {}
|
2017-09-13 12:55:56 +00:00
|
|
|
vars.each do |var|
|
2017-09-13 14:51:11 +00:00
|
|
|
tab_vars[var.split('=')[0]] = var.split('=')[1]
|
2017-09-13 12:55:56 +00:00
|
|
|
end
|
2017-09-20 15:49:54 +00:00
|
|
|
|
2017-09-13 14:51:11 +00:00
|
|
|
# Give vars name and value from shell command to parser
|
2017-09-14 08:50:10 +00:00
|
|
|
parser.names=tab_vars
|
2017-09-13 14:51:11 +00:00
|
|
|
|
2017-09-12 14:35:11 +00:00
|
|
|
token = parser.parse(line.chomp, true)
|
|
|
|
pp token
|
2017-09-12 14:35:59 +00:00
|
|
|
puts "RAW : #{line}"
|
|
|
|
puts "EVAL: #{token.to_s}"
|
2017-09-15 10:52:29 +00:00
|
|
|
parser.check_grammar line, token
|
2017-09-20 10:08:32 +00:00
|
|
|
exit 1 unless !token.nil? && token.errors.empty?
|
2017-09-18 13:30:33 +00:00
|
|
|
|
2017-09-13 12:55:56 +00:00
|
|
|
puts "RESULT: #{token.compute}"
|
2017-09-15 10:52:29 +00:00
|
|
|
|
2017-09-04 09:19:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Mm2ep::Depend::ParseCli.start(ARGV)
|