Debian Codegraph @

t/chaf.t

raw
1 #!perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 # Regression test for a chaf bug
18
19 use 5.010001;
20 use strict;
21 use warnings;
22
23 use Test::More tests => 2;
24 use lib 'inc';
25 use Marpa::R2::Test;
26 use Marpa::R2;
27
28 ## no critic (Subroutines::RequireArgUnpacking)
29
30 sub default_action {
31 shift;
32 my $v_count = scalar @_;
33 return q{} if $v_count <= 0;
34 return $_[0] if $v_count == 1;
35 return '(' . ( join q{;}, @_ ) . ')';
36 } ## end sub default_action
37
38 ## use critic
39
40 my $grammar = Marpa::R2::Grammar->new(
41 { start => 'S',
42 rules => [
43 [ 'S', [qw/A B B B C C /] ],
44 [ 'A', [qw/a/] ],
45 [ 'B', [qw/a/] ],
46 [ 'B', [] ],
47 [ 'C', [] ],
48 ],
49 default_action => 'main::default_action',
50 }
51 );
52
53 $grammar->set( { terminals => ['a'], } );
54
55 $grammar->precompute();
56
57 Marpa::R2::Test::is( $grammar->show_rules, <<'EOS', 'Aycock/Horspool Rules' );
58 0: S -> A B B B C C
59 1: A -> a
60 2: B -> a
61 3: B -> /* empty !used */
62 4: C -> /* empty !used */
63 EOS
64
65 my $recce = Marpa::R2::Recognizer->new( { grammar => $grammar } );
66
67 $recce->read( 'a', 'a' );
68
69 my $value_ref = $recce->value();
70 my $value = defined $value_ref ? ${$value_ref} : 'undef';
71 Test::More::is( $value, '(a;;;;;)', 'subp test' );
72
73 1; # In case used as "do" file
74
75 # Local Variables:
76 # mode: cperl
77 # cperl-indent-level: 4
78 # fill-column: 100
79 # End:
80 # vim: expandtab shiftwidth=4: