#!perl
use strict;
use warnings FATAL => 'all';
use MarpaX::Languages::SQL2003::AST;
use POSIX qw/EXIT_SUCCESS EXIT_FAILURE/;
use Getopt::Long;
use Pod::Usage;
use IO::String;
use File::Slurp qw/read_file/;

# ABSTRACT: SQL AST as an XML

our $VERSION = '0.003'; # TRIAL VERSION

# PODNAME: sql2003toxml

my $help = 0;
GetOptions ('help!' => \$help);

if ($help || $#ARGV > 0) {
  my $pod = do {local $/; <DATA>};
  my $podfh = IO::String->new($pod);
  pod2usage(-verbose => 2, -noperldoc => 1, -input => $podfh, -exitval => $help ? EXIT_SUCCESS : EXIT_FAILURE);
}

print MarpaX::Languages::SQL2003::AST->new()->asXML(@ARGV ? read_file(shift) : <STDIN>)->toString(1) . "\n";

exit(EXIT_SUCCESS);

=pod

=encoding UTF-8

=head1 NAME

sql2003toxml - SQL AST as an XML

=head1 VERSION

version 0.003

=head1 AUTHOR

Jean-Damien Durand <jeandamiendurand@free.fr>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Jean-Damien Durand.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

__DATA__

# --------------------------------------------------------------------------------------

=head1 NAME

sql2003toxml - SQL AST as an XML

=head1 SYNOPSIS

 sql2003toxml [options] [file]

where options can be:

  --help        This help.

and arguments can be:

  file          Input filename containing SQL statement

=head1 NOTES

=over

=item

  If file is absent or equal to '-', then STDIN is assumed.

=item

  Any ambiguous parse will result in a failure, with a hopefully clear stack trace.

=back

=head1 SEE ALSO

L<MarpaX::Languages::SQL2003::AST>
