#!/usr/bin/perl

use 5.012;
no warnings "experimental";
use Spp::Builtin qw(to_json);
use Spp;

my $action    = $ARGV[0];
my $file      = $ARGV[1];
my $text_file = $ARGV[2];

# say "action: $action";
given ($action) {
   when ('--repl')   { Spp::repl() }
   when ('--update') { Spp::update() }
   when ('--lint')   { Spp::lint($file) }
   when ('--spp') {
      if (-e $file && -e $text_file) {
         my $ast = Spp::spp($file, $text_file);
         say to_json($ast);
      }
      else {
         say "not exists grammar or text file";
      }
   }
   default { Spp::repl() }
}

