namarara/exe/mm2ep-depend
2017-09-15 12:52:29 +02:00

41 lines
938 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}"
parser.check_grammar line, token
binding.pry
exit 1 unless token.errors.empty? || token.nil?
puts "RESULT: #{token.compute}"
end
end
end
end
Mm2ep::Depend::ParseCli.start(ARGV)