ings;
use MarpaX::Demo::JSONParser;
use Try::Tiny;
# ---------------------------
my($app_name) = 'MarpaX-Demo-JSONParser';
my($bnf_name) = shift || 'json.1.bnf'; # Or 'json.2.bnf'.
my($bnf_file) =
$message);
my($result);
# Use try to catch die.
try
{
$message = '';
$result = MarpaX::Demo::JSONParser -> new(bnf_file => $bnf_file) -> parse($string);
}
catch
{
$message = $_;
$result = 0;
}
package MarpaX::Demo::JSONParser::Actions;
use strict;
use warnings;
# Warning: Do not use Moo or anything similar.
# This class needs a sub new() due to the way
# Marpa calls the constructor.
our
aX::Demo::JSONParser::Actions> - A JSON parser with a choice of grammars
=head1 Synopsis
See L<MarpaX::Demo::JSONParser/Synopsis>.
The module is used automatically by L<MarpaX::Demo::JSONParser> as
appropriate.
=head1 Description
See L<MarpaX::Demo::JSONParser/Description>.
=head1 Installation
See L<MarpaX::Demo::JSONParser/Installation>.
=head1 Methods
The functions are called automatica
package MarpaX::Demo::JSONParser;
use strict;
use warnings;
use File::Basename; # For basename.
use File::Slurper 'read_text';
use Marpa::R2;
use MarpaX::Demo::JSONParser::Actions;
use MarpaX::Sim
eq 'json.1.bnf')
{
$self-> grammar
(
Marpa::R2::Scanless::G -> new
({
default_action => 'do_first_arg',
source => \$bnf,
})
)
}
elsif ($self -> base_name eq 'json.2.b
G -> new
({
bless_package => 'MarpaX::Demo::JSONParser::Actions',
source => \$bnf,
})
)
}
elsif ($self -> base_name eq 'json.3.bnf')
{
$self-> parser
(
gen_parser
(