namarara/exe/mm2ep-depend

38 lines
866 B
Ruby
Executable file

#!/usr/bin/env ruby
$:.insert(0, 'lib')
require 'thor'
require 'rly'
require 'pry'
require 'mm2ep_depend'
require 'pp'
module Mm2ep
module Depend
class ParseCli < Thor
desc 'parse INFILE VARS', 'Parse INFILE into tokens and evaluate vars'
def parse(infile, *vars)
line = File.read(infile).gsub(/\n/,'')
parser = Parser.new(Lexer.new)
tab_vars = {}
vars.each do |var|
tab_vars[var.split('=')[0]] = var.split('=')[1]
end
# Give vars name and value from shell command to parser
parser.names=tab_vars
token = parser.parse(line.chomp, true)
pp token
puts "RAW : #{line}"
puts "EVAL: #{token.to_s}"
exit 1 unless token.errors.empty?
puts "RESULT: #{token.compute}"
end
end
end
end
Mm2ep::Depend::ParseCli.start(ARGV)