Debian Codegraph @

t/debug_leo.t

raw
1 #!/usr/bin/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 use 5.010001;
18 use strict;
19 use warnings;
20
21 use Test::More tests => 2;
22
23 use English qw( -no_match_vars );
24 use Fatal qw( open close );
25 use lib 'inc';
26 use Marpa::R2::Test;
27 use Marpa::R2;
28
29 my $progress_report = q{};
30
31 my $grammar = Marpa::R2::Grammar->new(
32 { start => 'S',
33 rules => [
34 { lhs => 'S', rhs => [qw/Top_sequence/] },
35 { lhs => 'Top_sequence', rhs => [qw/Top Top_sequence/] },
36 { lhs => 'Top_sequence', rhs => [qw/Top/] },
37 { lhs => 'Top', rhs => [qw/Upper_Middle/] },
38 { lhs => 'Upper_Middle', rhs => [qw/Lower_Middle/] },
39 { lhs => 'Lower_Middle', rhs => [qw/Bottom/] },
40 { lhs => 'Bottom', rhs => [qw/T/] },
41 ],
42 }
43 );
44
45 # Marpa::R2::Display::End
46
47 $grammar->precompute();
48
49 my $recce = Marpa::R2::Recognizer->new( { grammar => $grammar } );
50
51 my $current_earleme;
52 for (1 .. 20) {
53 $current_earleme = $recce->read( 'T' );
54 }
55
56 # The call to current earlem is Useless,
57 # but provides an example for the docs
58
59 # Marpa::R2::Display
60 # name: current_earleme Example
61
62 $current_earleme = $recce->current_earleme();
63
64 # Marpa::R2::Display::End
65
66 $progress_report = $recce->show_progress();
67
68 my $value_ref = $recce->value;
69 Test::More::ok( $value_ref, 'Parse ok?' );
70
71 # Marpa::R2::Display
72 # name: Debug Leo Example Progress Report
73 # start-after-line: END_PROGRESS_REPORT
74 # end-before-line: '^END_PROGRESS_REPORT$'
75
76 Marpa::R2::Test::is( $progress_report,
77 <<'END_PROGRESS_REPORT', 'sorted progress report' );
78 F0 @0-20 S -> Top_sequence .
79 P1 @20-20 Top_sequence -> . Top Top_sequence
80 R1:1 @19-20 Top_sequence -> Top . Top_sequence
81 F1 x19 @0...18-20 Top_sequence -> Top Top_sequence .
82 P2 @20-20 Top_sequence -> . Top
83 F2 @19-20 Top_sequence -> Top .
84 P3 @20-20 Top -> . Upper_Middle
85 F3 @19-20 Top -> Upper_Middle .
86 P4 @20-20 Upper_Middle -> . Lower_Middle
87 F4 @19-20 Upper_Middle -> Lower_Middle .
88 P5 @20-20 Lower_Middle -> . Bottom
89 F5 @19-20 Lower_Middle -> Bottom .
90 P6 @20-20 Bottom -> . T
91 F6 @19-20 Bottom -> T .
92 END_PROGRESS_REPORT
93
94 # Marpa::R2::Display::End
95
96 1; # In case used as "do" file
97
98 # Local Variables:
99 # mode: cperl
100 # cperl-indent-level: 4
101 # fill-column: 100
102 # End:
103 # vim: expandtab shiftwidth=4: