#!/usr/bin/perl # Copyright 2022 Jeffrey Kegler # This file is part of Marpa::R2. Marpa::R2 is free software: you can # redistribute it and/or modify it under the terms of the GNU Lesser # General Public License as published by the Free Software Foundation, # either version 3 of the License, or (at your option) any later version. # # Marpa::R2 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser # General Public License along with Marpa::R2. If not, see # http://www.gnu.org/licenses/. # Landing page synopsis use 5.010001; use strict; use warnings; use Test::More tests => 1; use lib 'inc'; use Marpa::R2::Test; ## no critic (ErrorHandling::RequireCarping); # Marpa::R2::Display # name: Landing page synopsis use Marpa::R2; my $dsl = <<'END_OF_DSL'; :default ::= action => [name,values] lexeme default = latm => 1 Calculator ::= Expression action => ::first Factor ::= Number action => ::first Term ::= Term '*' Factor action => do_multiply | Factor action => ::first Expression ::= Expression '+' Term action => do_add | Term action => ::first Number ~ digits digits ~ [\d]+ :discard ~ whitespace whitespace ~ [\s]+ END_OF_DSL my $grammar = Marpa::R2::Scanless::G->new( { source => \$dsl } ); my $input = '42 * 1 + 7'; my $value_ref = $grammar->parse( \$input, 'My_Actions' ); sub My_Actions::do_add { my ( undef, $t1, undef, $t2 ) = @_; return $t1 + $t2; } sub My_Actions::do_multiply { my ( undef, $t1, undef, $t2 ) = @_; return $t1 * $t2; } # Marpa::R2::Display::End Test::More::is( ${$value_ref}, 49, 'Landing page synopsis value' ); 1; # In case used as "do" file # Local Variables: # mode: cperl # cperl-indent-level: 4 # fill-column: 100 # End: # vim: expandtab shiftwidth=4: