use 5.010;
use strict;
use warnings;

use Fatal qw(chdir open);
use English qw( -no_match_vars );
use lib 'lib';
use Marpa;
use Marpa::Raw_Source;

if (@ARGV) {
    open STDOUT, '>', $ARGV[0]
        or Marpa::exception "Cannot write '$ARGV[0]' - $!";
}

say '# This file was automatically generated by Marpa ', $Marpa::VERSION;

print <<'END_OF_PREAMBLE_CODE' or Marpa::exception("print failed: $ERRNO");
use 5.010;

use warnings;
use strict;

# It's all integers, except for the version number
use integer;

package Marpa::Source;

END_OF_PREAMBLE_CODE

## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
say 'our $VERSION = "', $Marpa::VERSION, q{";};
## use critic

print <<'END_OF_PREAMBLE_CODE' or Marpa::exception("print failed: $ERRNO");

package Marpa::Internal::Source;

use English qw( -no_match_vars ) ;
{
    local($RS) = undef;
    $Marpa::Internal::STRINGIFIED_SOURCE_GRAMMAR = \(<DATA>);
}

1;

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

__DATA__

END_OF_PREAMBLE_CODE

say ${ Marpa::stringify_source_grammar() }
    or Marpa::exception("print failed: $ERRNO");
