#!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/. # Test of scannerless parsing -- diagnostics use 5.010001; use strict; use warnings; use Test::More tests => 12; use English qw( -no_match_vars ); use lib 'inc'; use Marpa::R2::Test; use Marpa::R2; my $dsl = <<'END_OF_RULES'; :start ::= Script Script ::= Calculation* action => do_list Calculation ::= Expression | ('say') Expression Expression ::= Number | ('+') Expression Expression action => do_add Number ~ [\d] + :discard ~ whitespace whitespace ~ [\s]+ # allow comments :discard ~ ~ | ~ '#' ~ '#' ~ * ~ [\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}] ~ [^\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}] END_OF_RULES my $grammar = Marpa::R2::Scanless::G->new( { action_object => 'My_Actions', default_action => 'do_arg0', source => \$dsl, } ); my $g0_rules_description; # Marpa::R2::Display # name: Scanless g0_rule() synopsis my @g0_rule_ids = $grammar->g0_rule_ids(); for my $g0_rule_id (@g0_rule_ids) { $g0_rules_description .= "$g0_rule_id " . ( join q{ }, map {"<$_>"} $grammar->g0_rule($g0_rule_id) ) . "\n"; } # Marpa::R2::Display::End Marpa::R2::Test::is( $g0_rules_description, <<'END_OF_DESCRIPTION', 0 <[Lex-0]> <[[s]]> <[[a]]> <[[y]]> 1 <[Lex-1]> <[[\+]]> 2 <[[\d]]> 3 <[:discard]> 4 <[[\s]]> 5 <[:discard]> 6 7 8 <[[\#]]> 9 <[[\#]]> 10 11 <[[\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}]]> 12 <[[^\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}]]> 13 <[:start_lex]> 14 <[:start_lex]> <[:discard]> 15 <[:start_lex]> <[Lex-0]> 16 <[:start_lex]> <[Lex-1]> END_OF_DESCRIPTION 'g0_rule_ids() and g0_rule()' ); my $g1_rules_description; # Marpa::R2::Display # name: Scanless rule() synopsis my @g1_rule_ids = $grammar->g1_rule_ids(); for my $g1_rule_id (@g1_rule_ids) { $g1_rules_description .= "$g1_rule_id " . ( join q{ }, map {"<$_>"} $grammar->rule($g1_rule_id) ) . "\n"; } # Marpa::R2::Display::End Marpa::R2::Test::is( $g1_rules_description, <<'END_OF_DESCRIPTION', 0