| 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 |
# This test dumps the contents of the bocage and its iterator. |
| 18 |
# The example grammar is Aycock/Horspool's |
| 19 |
# "Practical Earley Parsing", |
| 20 |
# _The Computer Journal_, Vol. 45, No. 6, pp. 620-630, |
| 21 |
# in its "NNF" form |
| 22 |
|
| 23 |
use 5.010001; |
| 24 |
use strict; |
| 25 |
use warnings; |
| 26 |
|
| 27 |
use Test::More tests => 18; |
| 28 |
use lib 'inc'; |
| 29 |
use Marpa::R2::Test; |
| 30 |
use Marpa::R2; |
| 31 |
|
| 32 |
## no critic (Subroutines::RequireArgUnpacking) |
| 33 |
|
| 34 |
sub default_action { |
| 35 |
shift; |
| 36 |
my $v_count = scalar @_; |
| 37 |
return q{} if $v_count <= 0; |
| 38 |
return $_[0] if $v_count == 1; |
| 39 |
return '(' . ( join q{;}, @_ ) . ')'; |
| 40 |
} ## end sub default_action |
| 41 |
|
| 42 |
## use critic |
| 43 |
|
| 44 |
my $grammar = Marpa::R2::Grammar->new( |
| 45 |
{ start => 'S', |
| 46 |
rules => [ |
| 47 |
[ 'S', [qw/A A A A/] ], |
| 48 |
[ 'A', [qw/a/] ], |
| 49 |
[ 'A', [qw/E/] ], |
| 50 |
['E'], |
| 51 |
], |
| 52 |
default_action => 'main::default_action', |
| 53 |
} |
| 54 |
); |
| 55 |
|
| 56 |
$grammar->set( { terminals => ['a'], } ); |
| 57 |
|
| 58 |
$grammar->precompute(); |
| 59 |
|
| 60 |
Marpa::R2::Test::is( $grammar->show_rules, <<'EOS', 'Aycock/Horspool Rules' ); |
| 61 |
0: S -> A A A A |
| 62 |
1: A -> a |
| 63 |
2: A -> E /* !used */ |
| 64 |
3: E -> /* empty !used */ |
| 65 |
EOS |
| 66 |
|
| 67 |
Marpa::R2::Test::is( $grammar->show_symbols, |
| 68 |
<<'EOS', 'Aycock/Horspool Symbols' ); |
| 69 |
0: S |
| 70 |
1: A |
| 71 |
2: a, terminal |
| 72 |
3: E, nulling |
| 73 |
EOS |
| 74 |
|
| 75 |
Marpa::R2::Test::is( |
| 76 |
$grammar->show_nulling_symbols, |
| 77 |
q{E}, |
| 78 |
'Aycock/Horspool Nulling Symbols' |
| 79 |
); |
| 80 |
Marpa::R2::Test::is( |
| 81 |
$grammar->show_productive_symbols, |
| 82 |
q{A E S a}, |
| 83 |
'Aycock/Horspool Productive Symbols' |
| 84 |
); |
| 85 |
Marpa::R2::Test::is( |
| 86 |
$grammar->show_accessible_symbols, |
| 87 |
q{A E S a}, |
| 88 |
'Aycock/Horspool Accessible Symbols' |
| 89 |
); |
| 90 |
|
| 91 |
Marpa::R2::Test::is( $grammar->show_ahms(), |
| 92 |
<<'EOS', 'AHMs' ); |
| 93 |
AHM 0: postdot = "A" |
| 94 |
S ::= . A S[R0:1] |
| 95 |
AHM 1: postdot = "S[R0:1]" |
| 96 |
S ::= A . S[R0:1] |
| 97 |
AHM 2: completion |
| 98 |
S ::= A S[R0:1] . |
| 99 |
AHM 3: postdot = "A" |
| 100 |
S ::= . A A[] A[] A[] |
| 101 |
AHM 4: completion |
| 102 |
S ::= A A[] A[] A[] . |
| 103 |
AHM 5: postdot = "S[R0:1]" |
| 104 |
S ::= A[] . S[R0:1] |
| 105 |
AHM 6: completion |
| 106 |
S ::= A[] S[R0:1] . |
| 107 |
AHM 7: postdot = "A" |
| 108 |
S[R0:1] ::= . A S[R0:2] |
| 109 |
AHM 8: postdot = "S[R0:2]" |
| 110 |
S[R0:1] ::= A . S[R0:2] |
| 111 |
AHM 9: completion |
| 112 |
S[R0:1] ::= A S[R0:2] . |
| 113 |
AHM 10: postdot = "A" |
| 114 |
S[R0:1] ::= . A A[] A[] |
| 115 |
AHM 11: completion |
| 116 |
S[R0:1] ::= A A[] A[] . |
| 117 |
AHM 12: postdot = "S[R0:2]" |
| 118 |
S[R0:1] ::= A[] . S[R0:2] |
| 119 |
AHM 13: completion |
| 120 |
S[R0:1] ::= A[] S[R0:2] . |
| 121 |
AHM 14: postdot = "A" |
| 122 |
S[R0:2] ::= . A A |
| 123 |
AHM 15: postdot = "A" |
| 124 |
S[R0:2] ::= A . A |
| 125 |
AHM 16: completion |
| 126 |
S[R0:2] ::= A A . |
| 127 |
AHM 17: postdot = "A" |
| 128 |
S[R0:2] ::= . A A[] |
| 129 |
AHM 18: completion |
| 130 |
S[R0:2] ::= A A[] . |
| 131 |
AHM 19: postdot = "A" |
| 132 |
S[R0:2] ::= A[] . A |
| 133 |
AHM 20: completion |
| 134 |
S[R0:2] ::= A[] A . |
| 135 |
AHM 21: postdot = "a" |
| 136 |
A ::= . a |
| 137 |
AHM 22: completion |
| 138 |
A ::= a . |
| 139 |
AHM 23: postdot = "S" |
| 140 |
S['] ::= . S |
| 141 |
AHM 24: completion |
| 142 |
S['] ::= S . |
| 143 |
EOS |
| 144 |
|
| 145 |
my $recce = Marpa::R2::Recognizer->new( { grammar => $grammar } ); |
| 146 |
|
| 147 |
my $expected_earley_sets = <<'END_OF_SETS'; |
| 148 |
Last Completed: 3; Furthest: 3 |
| 149 |
Earley Set 0 |
| 150 |
ahm23: R10:0@0-0 |
| 151 |
R10:0: S['] ::= . S |
| 152 |
ahm0: R0:0@0-0 |
| 153 |
R0:0: S ::= . A S[R0:1] |
| 154 |
ahm3: R1:0@0-0 |
| 155 |
R1:0: S ::= . A A[] A[] A[] |
| 156 |
ahm5: R2:1@0-0 |
| 157 |
R2:1: S ::= A[] . S[R0:1] |
| 158 |
ahm7: R3:0@0-0 |
| 159 |
R3:0: S[R0:1] ::= . A S[R0:2] |
| 160 |
ahm10: R4:0@0-0 |
| 161 |
R4:0: S[R0:1] ::= . A A[] A[] |
| 162 |
ahm12: R5:1@0-0 |
| 163 |
R5:1: S[R0:1] ::= A[] . S[R0:2] |
| 164 |
ahm14: R6:0@0-0 |
| 165 |
R6:0: S[R0:2] ::= . A A |
| 166 |
ahm17: R7:0@0-0 |
| 167 |
R7:0: S[R0:2] ::= . A A[] |
| 168 |
ahm19: R8:1@0-0 |
| 169 |
R8:1: S[R0:2] ::= A[] . A |
| 170 |
ahm21: R9:0@0-0 |
| 171 |
R9:0: A ::= . a |
| 172 |
Earley Set 1 |
| 173 |
ahm22: R9$@0-1 |
| 174 |
R9$: A ::= a . |
| 175 |
[c=R9:0@0-0; s=a; t=\'a'] |
| 176 |
ahm20: R8$@0-1 |
| 177 |
R8$: S[R0:2] ::= A[] A . |
| 178 |
[p=R8:1@0-0; c=R9$@0-1] |
| 179 |
ahm18: R7$@0-1 |
| 180 |
R7$: S[R0:2] ::= A A[] . |
| 181 |
[p=R7:0@0-0; c=R9$@0-1] |
| 182 |
ahm15: R6:1@0-1 |
| 183 |
R6:1: S[R0:2] ::= A . A |
| 184 |
[p=R6:0@0-0; c=R9$@0-1] |
| 185 |
ahm11: R4$@0-1 |
| 186 |
R4$: S[R0:1] ::= A A[] A[] . |
| 187 |
[p=R4:0@0-0; c=R9$@0-1] |
| 188 |
ahm8: R3:1@0-1 |
| 189 |
R3:1: S[R0:1] ::= A . S[R0:2] |
| 190 |
[p=R3:0@0-0; c=R9$@0-1] |
| 191 |
ahm4: R1$@0-1 |
| 192 |
R1$: S ::= A A[] A[] A[] . |
| 193 |
[p=R1:0@0-0; c=R9$@0-1] |
| 194 |
ahm1: R0:1@0-1 |
| 195 |
R0:1: S ::= A . S[R0:1] |
| 196 |
[p=R0:0@0-0; c=R9$@0-1] |
| 197 |
ahm24: R10$@0-1 |
| 198 |
R10$: S['] ::= S . |
| 199 |
[p=R10:0@0-0; c=R1$@0-1] [p=R10:0@0-0; c=R2$@0-1] |
| 200 |
ahm6: R2$@0-1 |
| 201 |
R2$: S ::= A[] S[R0:1] . |
| 202 |
[p=R2:1@0-0; c=R4$@0-1] [p=R2:1@0-0; c=R5$@0-1] |
| 203 |
ahm13: R5$@0-1 |
| 204 |
R5$: S[R0:1] ::= A[] S[R0:2] . |
| 205 |
[p=R5:1@0-0; c=R7$@0-1] [p=R5:1@0-0; c=R8$@0-1] |
| 206 |
ahm21: R9:0@1-1 |
| 207 |
R9:0: A ::= . a |
| 208 |
ahm14: R6:0@1-1 |
| 209 |
R6:0: S[R0:2] ::= . A A |
| 210 |
ahm17: R7:0@1-1 |
| 211 |
R7:0: S[R0:2] ::= . A A[] |
| 212 |
ahm19: R8:1@1-1 |
| 213 |
R8:1: S[R0:2] ::= A[] . A |
| 214 |
ahm7: R3:0@1-1 |
| 215 |
R3:0: S[R0:1] ::= . A S[R0:2] |
| 216 |
ahm10: R4:0@1-1 |
| 217 |
R4:0: S[R0:1] ::= . A A[] A[] |
| 218 |
ahm12: R5:1@1-1 |
| 219 |
R5:1: S[R0:1] ::= A[] . S[R0:2] |
| 220 |
Earley Set 2 |
| 221 |
ahm22: R9$@1-2 |
| 222 |
R9$: A ::= a . |
| 223 |
[c=R9:0@1-1; s=a; t=\'a'] |
| 224 |
ahm11: R4$@1-2 |
| 225 |
R4$: S[R0:1] ::= A A[] A[] . |
| 226 |
[p=R4:0@1-1; c=R9$@1-2] |
| 227 |
ahm8: R3:1@1-2 |
| 228 |
R3:1: S[R0:1] ::= A . S[R0:2] |
| 229 |
[p=R3:0@1-1; c=R9$@1-2] |
| 230 |
ahm20: R8$@1-2 |
| 231 |
R8$: S[R0:2] ::= A[] A . |
| 232 |
[p=R8:1@1-1; c=R9$@1-2] |
| 233 |
ahm18: R7$@1-2 |
| 234 |
R7$: S[R0:2] ::= A A[] . |
| 235 |
[p=R7:0@1-1; c=R9$@1-2] |
| 236 |
ahm15: R6:1@1-2 |
| 237 |
R6:1: S[R0:2] ::= A . A |
| 238 |
[p=R6:0@1-1; c=R9$@1-2] |
| 239 |
ahm16: R6$@0-2 |
| 240 |
R6$: S[R0:2] ::= A A . |
| 241 |
[p=R6:1@0-1; c=R9$@1-2] |
| 242 |
ahm13: R5$@0-2 |
| 243 |
R5$: S[R0:1] ::= A[] S[R0:2] . |
| 244 |
[p=R5:1@0-0; c=R6$@0-2] |
| 245 |
ahm6: R2$@0-2 |
| 246 |
R2$: S ::= A[] S[R0:1] . |
| 247 |
[p=R2:1@0-0; c=R3$@0-2] [p=R2:1@0-0; c=R5$@0-2] |
| 248 |
ahm24: R10$@0-2 |
| 249 |
R10$: S['] ::= S . |
| 250 |
[p=R10:0@0-0; c=R0$@0-2] [p=R10:0@0-0; c=R2$@0-2] |
| 251 |
ahm13: R5$@1-2 |
| 252 |
R5$: S[R0:1] ::= A[] S[R0:2] . |
| 253 |
[p=R5:1@1-1; c=R7$@1-2] [p=R5:1@1-1; c=R8$@1-2] |
| 254 |
ahm9: R3$@0-2 |
| 255 |
R3$: S[R0:1] ::= A S[R0:2] . |
| 256 |
[p=R3:1@0-1; c=R7$@1-2] [p=R3:1@0-1; c=R8$@1-2] |
| 257 |
ahm2: R0$@0-2 |
| 258 |
R0$: S ::= A S[R0:1] . |
| 259 |
[p=R0:1@0-1; c=R4$@1-2] [p=R0:1@0-1; c=R5$@1-2] |
| 260 |
ahm14: R6:0@2-2 |
| 261 |
R6:0: S[R0:2] ::= . A A |
| 262 |
ahm17: R7:0@2-2 |
| 263 |
R7:0: S[R0:2] ::= . A A[] |
| 264 |
ahm19: R8:1@2-2 |
| 265 |
R8:1: S[R0:2] ::= A[] . A |
| 266 |
ahm21: R9:0@2-2 |
| 267 |
R9:0: A ::= . a |
| 268 |
Earley Set 3 |
| 269 |
ahm22: R9$@2-3 |
| 270 |
R9$: A ::= a . |
| 271 |
[c=R9:0@2-2; s=a; t=\'a'] |
| 272 |
ahm20: R8$@2-3 |
| 273 |
R8$: S[R0:2] ::= A[] A . |
| 274 |
[p=R8:1@2-2; c=R9$@2-3] |
| 275 |
ahm18: R7$@2-3 |
| 276 |
R7$: S[R0:2] ::= A A[] . |
| 277 |
[p=R7:0@2-2; c=R9$@2-3] |
| 278 |
ahm15: R6:1@2-3 |
| 279 |
R6:1: S[R0:2] ::= A . A |
| 280 |
[p=R6:0@2-2; c=R9$@2-3] |
| 281 |
ahm16: R6$@1-3 |
| 282 |
R6$: S[R0:2] ::= A A . |
| 283 |
[p=R6:1@1-2; c=R9$@2-3] |
| 284 |
ahm13: R5$@1-3 |
| 285 |
R5$: S[R0:1] ::= A[] S[R0:2] . |
| 286 |
[p=R5:1@1-1; c=R6$@1-3] |
| 287 |
ahm9: R3$@0-3 |
| 288 |
R3$: S[R0:1] ::= A S[R0:2] . |
| 289 |
[p=R3:1@0-1; c=R6$@1-3] |
| 290 |
ahm6: R2$@0-3 |
| 291 |
R2$: S ::= A[] S[R0:1] . |
| 292 |
[p=R2:1@0-0; c=R3$@0-3] |
| 293 |
ahm24: R10$@0-3 |
| 294 |
R10$: S['] ::= S . |
| 295 |
[p=R10:0@0-0; c=R0$@0-3] [p=R10:0@0-0; c=R2$@0-3] |
| 296 |
ahm2: R0$@0-3 |
| 297 |
R0$: S ::= A S[R0:1] . |
| 298 |
[p=R0:1@0-1; c=R3$@1-3] [p=R0:1@0-1; c=R5$@1-3] |
| 299 |
ahm9: R3$@1-3 |
| 300 |
R3$: S[R0:1] ::= A S[R0:2] . |
| 301 |
[p=R3:1@1-2; c=R7$@2-3] [p=R3:1@1-2; c=R8$@2-3] |
| 302 |
ahm21: R9:0@3-3 |
| 303 |
R9:0: A ::= . a |
| 304 |
END_OF_SETS |
| 305 |
|
| 306 |
my %tree_expected = (); |
| 307 |
|
| 308 |
$tree_expected{'(;a;a;a)'} = <<'END_OF_TEXT'; |
| 309 |
0: o17[-] R10:1@0-3 p=ok c=ok |
| 310 |
o17[0]* ::= a17 R10:1@0-3C2@0 |
| 311 |
o17[1] ::= a18 R10:1@0-3C0@0 |
| 312 |
1: o16[c0] R2:2@0-3 p=ok c=ok |
| 313 |
o16[0]* ::= a16 R2:2@0-3C3@0 |
| 314 |
2: o15[c1] R3:2@0-3 p=ok c=ok |
| 315 |
o15[0]* ::= a15 R3:2@0-3C6@1 |
| 316 |
3: o13[c2] R6:2@1-3 p=ok c=ok |
| 317 |
o13[0]* ::= a13 R6:2@1-3C9@2 |
| 318 |
4: o9[c3] R9:1@2-3 p=ok c=ok |
| 319 |
o9[0]* ::= a9 R9:1@2-3S4@2 |
| 320 |
5: o7[p3] R6:1@1-2 p=ok c=ok |
| 321 |
o7[0]* ::= a7 R6:1@1-2C9@1 |
| 322 |
6: o5[c5] R9:1@1-2 p=ok c=ok |
| 323 |
o5[0]* ::= a5 R9:1@1-2S4@1 |
| 324 |
7: o2[p2] R3:1@0-1 p=ok c=ok |
| 325 |
o2[0]* ::= a2 R3:1@0-1C9@0 |
| 326 |
8: o1[c7] R9:1@0-1 p=ok c=ok |
| 327 |
o1[0]* ::= a1 R9:1@0-1S4@0 |
| 328 |
9: o0[p1] R2:1@0-0 p=ok c=ok |
| 329 |
o0[0]* ::= a0 R2:1@0-0S3@0 |
| 330 |
END_OF_TEXT |
| 331 |
|
| 332 |
$tree_expected{'(a;;a;a)'} = <<'END_OF_TEXT'; |
| 333 |
0: o17[-] R10:1@0-3 p=ok c=ok |
| 334 |
o17[0] ::= a17 R10:1@0-3C2@0 |
| 335 |
o17[1]* ::= a18 R10:1@0-3C0@0 |
| 336 |
1: o18[c0] R0:2@0-3 p=ok c=ok |
| 337 |
o18[0]* ::= a19 R0:2@0-3C5@1 |
| 338 |
o18[1] ::= a20 R0:2@0-3C3@1 |
| 339 |
2: o14[c1] R5:2@1-3 p=ok c=ok |
| 340 |
o14[0]* ::= a14 R5:2@1-3C6@1 |
| 341 |
3: o13[c2] R6:2@1-3 p=ok c=ok |
| 342 |
o13[0]* ::= a13 R6:2@1-3C9@2 |
| 343 |
4: o9[c3] R9:1@2-3 p=ok c=ok |
| 344 |
o9[0]* ::= a9 R9:1@2-3S4@2 |
| 345 |
5: o7[p3] R6:1@1-2 p=ok c=ok |
| 346 |
o7[0]* ::= a7 R6:1@1-2C9@1 |
| 347 |
6: o5[c5] R9:1@1-2 p=ok c=ok |
| 348 |
o5[0]* ::= a5 R9:1@1-2S4@1 |
| 349 |
7: o4[p2] R5:1@1-1 p=ok c=ok |
| 350 |
o4[0]* ::= a4 R5:1@1-1S3@1 |
| 351 |
8: o3[p1] R0:1@0-1 p=ok c=ok |
| 352 |
o3[0]* ::= a3 R0:1@0-1C9@0 |
| 353 |
9: o1[c8] R9:1@0-1 p=ok c=ok |
| 354 |
o1[0]* ::= a1 R9:1@0-1S4@0 |
| 355 |
END_OF_TEXT |
| 356 |
|
| 357 |
$tree_expected{'(a;a;;a)'} = <<'END_OF_TEXT'; |
| 358 |
0: o17[-] R10:1@0-3 p=ok c=ok |
| 359 |
o17[0] ::= a17 R10:1@0-3C2@0 |
| 360 |
o17[1]* ::= a18 R10:1@0-3C0@0 |
| 361 |
1: o18[c0] R0:2@0-3 p=ok c=ok |
| 362 |
o18[0] ::= a19 R0:2@0-3C5@1 |
| 363 |
o18[1]* ::= a20 R0:2@0-3C3@1 |
| 364 |
2: o19[c1] R3:2@1-3 p=ok c=ok |
| 365 |
o19[0] ::= a21 R3:2@1-3C7@2 |
| 366 |
o19[1]* ::= a22 R3:2@1-3C8@2 |
| 367 |
3: o10[c2] R8:2@2-3 p=ok c=ok |
| 368 |
o10[0]* ::= a10 R8:2@2-3C9@2 |
| 369 |
4: o9[c3] R9:1@2-3 p=ok c=ok |
| 370 |
o9[0]* ::= a9 R9:1@2-3S4@2 |
| 371 |
5: o8[p3] R8:1@2-2 p=ok c=ok |
| 372 |
o8[0]* ::= a8 R8:1@2-2S3@2 |
| 373 |
6: o6[p2] R3:1@1-2 p=ok c=ok |
| 374 |
o6[0]* ::= a6 R3:1@1-2C9@1 |
| 375 |
7: o5[c6] R9:1@1-2 p=ok c=ok |
| 376 |
o5[0]* ::= a5 R9:1@1-2S4@1 |
| 377 |
8: o3[p1] R0:1@0-1 p=ok c=ok |
| 378 |
o3[0]* ::= a3 R0:1@0-1C9@0 |
| 379 |
9: o1[c8] R9:1@0-1 p=ok c=ok |
| 380 |
o1[0]* ::= a1 R9:1@0-1S4@0 |
| 381 |
END_OF_TEXT |
| 382 |
|
| 383 |
$tree_expected{'(a;a;a;)'} = <<'END_OF_TEXT'; |
| 384 |
0: o17[-] R10:1@0-3 p=ok c=ok |
| 385 |
o17[0] ::= a17 R10:1@0-3C2@0 |
| 386 |
o17[1]* ::= a18 R10:1@0-3C0@0 |
| 387 |
1: o18[c0] R0:2@0-3 p=ok c=ok |
| 388 |
o18[0] ::= a19 R0:2@0-3C5@1 |
| 389 |
o18[1]* ::= a20 R0:2@0-3C3@1 |
| 390 |
2: o19[c1] R3:2@1-3 p=ok c=ok |
| 391 |
o19[0]* ::= a21 R3:2@1-3C7@2 |
| 392 |
o19[1] ::= a22 R3:2@1-3C8@2 |
| 393 |
3: o12[c2] R7:2@2-3 p=ok c=ok |
| 394 |
o12[0]* ::= a12 R7:2@2-3S3@3 |
| 395 |
4: o11[p3] R7:1@2-3 p=ok c=ok |
| 396 |
o11[0]* ::= a11 R7:1@2-3C9@2 |
| 397 |
5: o9[c4] R9:1@2-3 p=ok c=ok |
| 398 |
o9[0]* ::= a9 R9:1@2-3S4@2 |
| 399 |
6: o6[p2] R3:1@1-2 p=ok c=ok |
| 400 |
o6[0]* ::= a6 R3:1@1-2C9@1 |
| 401 |
7: o5[c6] R9:1@1-2 p=ok c=ok |
| 402 |
o5[0]* ::= a5 R9:1@1-2S4@1 |
| 403 |
8: o3[p1] R0:1@0-1 p=ok c=ok |
| 404 |
o3[0]* ::= a3 R0:1@0-1C9@0 |
| 405 |
9: o1[c8] R9:1@0-1 p=ok c=ok |
| 406 |
o1[0]* ::= a1 R9:1@0-1S4@0 |
| 407 |
END_OF_TEXT |
| 408 |
|
| 409 |
$recce->read( 'a', 'a' ); |
| 410 |
$recce->read( 'a', 'a' ); |
| 411 |
$recce->read( 'a', 'a' ); |
| 412 |
|
| 413 |
Marpa::R2::Test::is( |
| 414 |
$recce->show_earley_sets(1), |
| 415 |
$expected_earley_sets, |
| 416 |
'Aycock/Horspool Earley Sets' |
| 417 |
); |
| 418 |
|
| 419 |
my %expected = |
| 420 |
map { ( $_ => 1 ) } qw( (a;a;a;) (a;a;;a) (a;;a;a) (;a;a;a) ); |
| 421 |
|
| 422 |
$recce->set( { max_parses => 20 } ); |
| 423 |
|
| 424 |
while ( my $value_ref = $recce->value() ) { |
| 425 |
|
| 426 |
my $tree_output = q{}; |
| 427 |
|
| 428 |
my $value = 'No parse'; |
| 429 |
if ($value_ref) { |
| 430 |
$value = ${$value_ref}; |
| 431 |
|
| 432 |
Marpa::R2::Test::is( $recce->show_tree(), $tree_expected{$value}, |
| 433 |
qq{Tree, "$value"} ); |
| 434 |
} |
| 435 |
else { |
| 436 |
Test::More::fail('Tree'); |
| 437 |
} |
| 438 |
|
| 439 |
if ( defined $expected{$value} ) { |
| 440 |
delete $expected{$value}; |
| 441 |
Test::More::pass(qq{Expected result, "$value"}); |
| 442 |
} |
| 443 |
else { |
| 444 |
Test::More::fail(qq{Unexpected result, "$value"}); |
| 445 |
} |
| 446 |
} ## end while ( my $value_ref = $recce->value() ) |
| 447 |
|
| 448 |
for my $value ( keys %expected ) { |
| 449 |
Test::More::fail(qq{Missing result, "$value"}); |
| 450 |
} |
| 451 |
|
| 452 |
my $or_node_output = <<'END_OF_TEXT'; |
| 453 |
R2:1@0-0 |
| 454 |
R0:1@0-1 |
| 455 |
R3:1@0-1 |
| 456 |
R9:1@0-1 |
| 457 |
R0:2@0-3 |
| 458 |
R2:2@0-3 |
| 459 |
R3:2@0-3 |
| 460 |
R10:1@0-3 |
| 461 |
R5:1@1-1 |
| 462 |
R3:1@1-2 |
| 463 |
R6:1@1-2 |
| 464 |
R9:1@1-2 |
| 465 |
R3:2@1-3 |
| 466 |
R5:2@1-3 |
| 467 |
R6:2@1-3 |
| 468 |
R8:1@2-2 |
| 469 |
R7:1@2-3 |
| 470 |
R7:2@2-3 |
| 471 |
R8:2@2-3 |
| 472 |
R9:1@2-3 |
| 473 |
END_OF_TEXT |
| 474 |
|
| 475 |
Marpa::R2::Test::is( $recce->show_or_nodes(), $or_node_output, |
| 476 |
'XS Or nodes' ); |
| 477 |
|
| 478 |
my $and_node_output = <<'END_OF_TEXT'; |
| 479 |
And-node #0: R2:1@0-0S3@0 |
| 480 |
And-node #1: R9:1@0-1S4@0 |
| 481 |
And-node #2: R3:1@0-1C9@0 |
| 482 |
And-node #3: R0:1@0-1C9@0 |
| 483 |
And-node #4: R5:1@1-1S3@1 |
| 484 |
And-node #5: R9:1@1-2S4@1 |
| 485 |
And-node #6: R3:1@1-2C9@1 |
| 486 |
And-node #7: R6:1@1-2C9@1 |
| 487 |
And-node #8: R8:1@2-2S3@2 |
| 488 |
And-node #9: R9:1@2-3S4@2 |
| 489 |
And-node #10: R8:2@2-3C9@2 |
| 490 |
And-node #11: R7:1@2-3C9@2 |
| 491 |
And-node #12: R7:2@2-3S3@3 |
| 492 |
And-node #13: R6:2@1-3C9@2 |
| 493 |
And-node #14: R5:2@1-3C6@1 |
| 494 |
And-node #15: R3:2@0-3C6@1 |
| 495 |
And-node #16: R2:2@0-3C3@0 |
| 496 |
And-node #17: R10:1@0-3C2@0 |
| 497 |
And-node #18: R10:1@0-3C0@0 |
| 498 |
And-node #19: R0:2@0-3C5@1 |
| 499 |
And-node #20: R0:2@0-3C3@1 |
| 500 |
And-node #21: R3:2@1-3C7@2 |
| 501 |
And-node #22: R3:2@1-3C8@2 |
| 502 |
END_OF_TEXT |
| 503 |
|
| 504 |
Marpa::R2::Test::is( $recce->show_and_nodes(), |
| 505 |
$and_node_output, 'XS And nodes' ); |
| 506 |
|
| 507 |
my $bocage_output = <<'END_OF_TEXT'; |
| 508 |
AND#0: parent=OR#0=R2:1@0-0 pred=- cause=S3 |
| 509 |
AND#1: parent=OR#1=R9:1@0-1 pred=- cause=S4 |
| 510 |
AND#2: parent=OR#2=R3:1@0-1 pred=- cause=OR#1=R9:1@0-1 |
| 511 |
AND#3: parent=OR#3=R0:1@0-1 pred=- cause=OR#1=R9:1@0-1 |
| 512 |
AND#4: parent=OR#4=R5:1@1-1 pred=- cause=S3 |
| 513 |
AND#5: parent=OR#5=R9:1@1-2 pred=- cause=S4 |
| 514 |
AND#6: parent=OR#6=R3:1@1-2 pred=- cause=OR#5=R9:1@1-2 |
| 515 |
AND#7: parent=OR#7=R6:1@1-2 pred=- cause=OR#5=R9:1@1-2 |
| 516 |
AND#8: parent=OR#8=R8:1@2-2 pred=- cause=S3 |
| 517 |
AND#9: parent=OR#9=R9:1@2-3 pred=- cause=S4 |
| 518 |
AND#10: parent=OR#10=R8:2@2-3 pred=OR#8=R8:1@2-2 cause=OR#9=R9:1@2-3 |
| 519 |
AND#11: parent=OR#11=R7:1@2-3 pred=- cause=OR#9=R9:1@2-3 |
| 520 |
AND#12: parent=OR#12=R7:2@2-3 pred=OR#11=R7:1@2-3 cause=S3 |
| 521 |
AND#13: parent=OR#13=R6:2@1-3 pred=OR#7=R6:1@1-2 cause=OR#9=R9:1@2-3 |
| 522 |
AND#14: parent=OR#14=R5:2@1-3 pred=OR#4=R5:1@1-1 cause=OR#13=R6:2@1-3 |
| 523 |
AND#15: parent=OR#15=R3:2@0-3 pred=OR#2=R3:1@0-1 cause=OR#13=R6:2@1-3 |
| 524 |
AND#16: parent=OR#16=R2:2@0-3 pred=OR#0=R2:1@0-0 cause=OR#15=R3:2@0-3 |
| 525 |
AND#17: parent=OR#17=R10:1@0-3 pred=- cause=OR#16=R2:2@0-3 |
| 526 |
AND#18: parent=OR#17=R10:1@0-3 pred=- cause=OR#18=R0:2@0-3 |
| 527 |
AND#19: parent=OR#18=R0:2@0-3 pred=OR#3=R0:1@0-1 cause=OR#14=R5:2@1-3 |
| 528 |
AND#20: parent=OR#18=R0:2@0-3 pred=OR#3=R0:1@0-1 cause=OR#19=R3:2@1-3 |
| 529 |
AND#21: parent=OR#19=R3:2@1-3 pred=OR#6=R3:1@1-2 cause=OR#12=R7:2@2-3 |
| 530 |
AND#22: parent=OR#19=R3:2@1-3 pred=OR#6=R3:1@1-2 cause=OR#10=R8:2@2-3 |
| 531 |
END_OF_TEXT |
| 532 |
|
| 533 |
Marpa::R2::Test::is( $recce->show_bocage(), $bocage_output, 'XS Bocage' ); |
| 534 |
|
| 535 |
1; # In case used as "do" file |
| 536 |
|
| 537 |
# Local Variables: |
| 538 |
# mode: cperl |
| 539 |
# cperl-indent-level: 4 |
| 540 |
# fill-column: 100 |
| 541 |
# End: |
| 542 |
# vim: expandtab shiftwidth=4: |