#!/usr/bin/perl

use strict;
use warnings;
use Syntax::Kamelon::Diagnostics;

my $help = <<__EOF;
This program analyzes a syntax definition.
Available options: -help, -xmlfolder, -noindex, -syntax.
You must specify the syntax option.
__EOF

my $noindex = 0;
my $syntax;
my $xmldir;

while (@ARGV) {
	my $o = shift @ARGV;
	if ($o eq '-help') {
		print $help
	} elsif ($o eq '-xmlfolder') {
		$xmldir = shift @ARGV;
	} elsif ($o eq '-noindex') {
		$noindex = 1
	} elsif ($o eq '-syntax') {
		$syntax = shift @ARGV
	} else {
		die "Invalid option $o. Available options: -help, -xmlfolder, -noindex, -syntax";
	}
}
die 'you must specify the -syntax option' unless defined $syntax;

my @o = (noindex => $noindex);
if (defined $xmldir) {
	unless (-e $xmldir) { die "$xmldir folder does not exist" }
	unless (-d $xmldir) { die "$xmldir is not a folder" }
	push @o, 'xmlfolder', $xmldir;
}

my $diag = Syntax::Kamelon::Diagnostics->new(@o);

$diag->Diagnoze($syntax);


