line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2022 Jeffrey Kegler |
2
|
|
|
|
|
|
|
# This file is part of Marpa::R2. Marpa::R2 is free software: you can |
3
|
|
|
|
|
|
|
# redistribute it and/or modify it under the terms of the GNU Lesser |
4
|
|
|
|
|
|
|
# General Public License as published by the Free Software Foundation, |
5
|
|
|
|
|
|
|
# either version 3 of the License, or (at your option) any later version. |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Marpa::R2 is distributed in the hope that it will be useful, |
8
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
10
|
|
|
|
|
|
|
# Lesser General Public License for more details. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser |
13
|
|
|
|
|
|
|
# General Public License along with Marpa::R2. If not, see |
14
|
|
|
|
|
|
|
# http://www.gnu.org/licenses/. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Marpa::R2::ASF; |
17
|
|
|
|
|
|
|
|
18
|
135
|
|
|
135
|
|
2459
|
use 5.010001; |
|
135
|
|
|
|
|
566
|
|
19
|
135
|
|
|
135
|
|
870
|
use strict; |
|
135
|
|
|
|
|
374
|
|
|
135
|
|
|
|
|
3200
|
|
20
|
135
|
|
|
135
|
|
839
|
use warnings; |
|
135
|
|
|
|
|
540
|
|
|
135
|
|
|
|
|
4073
|
|
21
|
135
|
|
|
135
|
|
793
|
no warnings qw(recursion); |
|
135
|
|
|
|
|
19364
|
|
|
135
|
|
|
|
|
7236
|
|
22
|
|
|
|
|
|
|
|
23
|
135
|
|
|
135
|
|
867
|
use vars qw($VERSION $STRING_VERSION); |
|
135
|
|
|
|
|
325
|
|
|
135
|
|
|
|
|
363205
|
|
24
|
|
|
|
|
|
|
$VERSION = '13.001_000'; |
25
|
|
|
|
|
|
|
$STRING_VERSION = $VERSION; |
26
|
|
|
|
|
|
|
## no critic(BuiltinFunctions::ProhibitStringyEval) |
27
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
28
|
|
|
|
|
|
|
## use critic |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# The code in this file, for now, breaks "the rules". It makes use |
31
|
|
|
|
|
|
|
# of internal methods not documented as part of Libmarpa. |
32
|
|
|
|
|
|
|
# It is intended to create documented Libmarpa methods to underlie |
33
|
|
|
|
|
|
|
# this interface, and rewrite it to use them |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
package Marpa::R2::Internal::ASF; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# This is more complicated that it needs to be for the current implementation. |
38
|
|
|
|
|
|
|
# It allows for LHS terminals (implemented in Libmarpa but not allowed by the SLIF). |
39
|
|
|
|
|
|
|
# It also assumes that every or-node which can be constructed from preceding or-nodes |
40
|
|
|
|
|
|
|
# and the input will be present. This is currently the case, but in the future |
41
|
|
|
|
|
|
|
# rules and/or symbols may have extra-syntactic conditions attached making this |
42
|
|
|
|
|
|
|
# assumption false. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Terms: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# NID (Node ID): Encoded ID of either an or-node or an and-node. |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
# Extensions: |
49
|
|
|
|
|
|
|
# Set "powers": A set of power 0 is an "atom" -- a single NID. |
50
|
|
|
|
|
|
|
# A set of power 1 is a set of NID's -- a nidset. |
51
|
|
|
|
|
|
|
# A set of power 2 is a set of sets of NID's, also called a powerset. |
52
|
|
|
|
|
|
|
# A set of power 3 is a set of powersets, etc. |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
# The whole ID of NID is the external rule id of an or-node, or -1 |
55
|
|
|
|
|
|
|
# if the NID is for a token and-node. |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# Intensions: |
58
|
|
|
|
|
|
|
# A Symch is a nidset, where all the NID's share the same "whole ID" |
59
|
|
|
|
|
|
|
# and the same span. NID's in a symch may differ in their internal rule, |
60
|
|
|
|
|
|
|
# or have different causes. If the symch contains and-node NID's they |
61
|
|
|
|
|
|
|
# will all have the same symbol. |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
# A choicepoint is a powerset -- a set of symches all of which share |
64
|
|
|
|
|
|
|
# the same set of predecessors. (This set of predecessors is a power 3 set of |
65
|
|
|
|
|
|
|
# choicepoints.) All symches in a choicepoint also share the same span, |
66
|
|
|
|
|
|
|
# and the same symch-symbol. A symch's symbol is the LHS of the rule, |
67
|
|
|
|
|
|
|
# or the symbol of the token in the token and-nodes. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub intset_id { |
70
|
13311
|
|
|
13311
|
|
19801
|
my ( $asf, @ids ) = @_; |
71
|
13311
|
|
|
|
|
27185
|
my $key = join q{ }, sort { $a <=> $b } @ids; |
|
98
|
|
|
|
|
426
|
|
72
|
13311
|
|
|
|
|
19549
|
my $intset_by_key = $asf->[Marpa::R2::Internal::ASF::INTSET_BY_KEY]; |
73
|
13311
|
|
|
|
|
19258
|
my $intset_id = $intset_by_key->{$key}; |
74
|
13311
|
100
|
|
|
|
29551
|
return $intset_id if defined $intset_id; |
75
|
1643
|
|
|
|
|
2485
|
$intset_id = $asf->[Marpa::R2::Internal::ASF::NEXT_INTSET_ID]++; |
76
|
1643
|
|
|
|
|
3537
|
$intset_by_key->{$key} = $intset_id; |
77
|
1643
|
|
|
|
|
3152
|
return $intset_id; |
78
|
|
|
|
|
|
|
} ## end sub intset_id |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub Marpa::R2::Nidset::obtain { |
81
|
12453
|
|
|
12453
|
|
22889
|
my ( $class, $asf, @nids ) = @_; |
82
|
12453
|
|
|
|
|
19399
|
my $id = intset_id( $asf, @nids ); |
83
|
12453
|
|
|
|
|
17912
|
my $nidset_by_id = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
84
|
12453
|
|
|
|
|
16478
|
my $nidset = $nidset_by_id->[$id]; |
85
|
12453
|
100
|
|
|
|
24863
|
return $nidset if defined $nidset; |
86
|
937
|
|
|
|
|
1624
|
$nidset = bless [], $class; |
87
|
937
|
|
|
|
|
1678
|
$nidset->[Marpa::R2::Internal::Nidset::ID] = $id; |
88
|
|
|
|
|
|
|
$nidset->[Marpa::R2::Internal::Nidset::NIDS] = |
89
|
937
|
|
|
|
|
2029
|
[ sort { $a <=> $b } @nids ]; |
|
50
|
|
|
|
|
190
|
|
90
|
937
|
|
|
|
|
1540
|
$nidset_by_id->[$id] = $nidset; |
91
|
937
|
|
|
|
|
1660
|
return $nidset; |
92
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Nidset::obtain |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub Marpa::R2::Nidset::nids { |
95
|
858
|
|
|
858
|
|
1308
|
my ($nidset) = @_; |
96
|
858
|
|
|
|
|
2212
|
return $nidset->[Marpa::R2::Internal::Nidset::NIDS]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub Marpa::R2::Nidset::nid { |
100
|
3263
|
|
|
3263
|
|
5259
|
my ( $nidset, $ix ) = @_; |
101
|
3263
|
|
|
|
|
5934
|
return $nidset->[Marpa::R2::Internal::Nidset::NIDS]->[$ix]; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub Marpa::R2::Nidset::count { |
105
|
285
|
|
|
285
|
|
494
|
my ($nidset) = @_; |
106
|
285
|
|
|
|
|
381
|
return scalar @{ $nidset->[Marpa::R2::Internal::Nidset::NIDS] }; |
|
285
|
|
|
|
|
482
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub Marpa::R2::Nidset::id { |
110
|
12453
|
|
|
12453
|
|
18003
|
my ($nidset) = @_; |
111
|
12453
|
|
|
|
|
18209
|
return $nidset->[Marpa::R2::Internal::Nidset::ID]; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub Marpa::R2::Nidset::show { |
115
|
0
|
|
|
0
|
|
0
|
my ($nidset) = @_; |
116
|
0
|
|
|
|
|
0
|
my $id = $nidset->id(); |
117
|
0
|
|
|
|
|
0
|
my $nids = $nidset->nids(); |
118
|
0
|
|
|
|
|
0
|
return "Nidset #$id: " . join q{ }, @{$nids}; |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Nidset::show |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::obtain { |
122
|
858
|
|
|
858
|
|
1559
|
my ( $class, $asf, @nidset_ids ) = @_; |
123
|
858
|
|
|
|
|
1474
|
my $id = intset_id( $asf, @nidset_ids ); |
124
|
858
|
|
|
|
|
1360
|
my $powerset_by_id = $asf->[Marpa::R2::Internal::ASF::POWERSET_BY_ID]; |
125
|
858
|
|
|
|
|
1326
|
my $powerset = $powerset_by_id->[$id]; |
126
|
858
|
50
|
|
|
|
1562
|
return $powerset if defined $powerset; |
127
|
858
|
|
|
|
|
1587
|
$powerset = bless [], $class; |
128
|
858
|
|
|
|
|
1745
|
$powerset->[Marpa::R2::Internal::Powerset::ID] = $id; |
129
|
|
|
|
|
|
|
$powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS] = |
130
|
858
|
|
|
|
|
1740
|
[ sort { $a <=> $b } @nidset_ids ]; |
|
19
|
|
|
|
|
51
|
|
131
|
858
|
|
|
|
|
1624
|
$powerset_by_id->[$id] = $powerset; |
132
|
858
|
|
|
|
|
1552
|
return $powerset; |
133
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Powerset::obtain |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::nidset_ids { |
136
|
0
|
|
|
0
|
|
0
|
my ($powerset) = @_; |
137
|
0
|
|
|
|
|
0
|
return $powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS]; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::count { |
141
|
858
|
|
|
858
|
|
1331
|
my ($powerset) = @_; |
142
|
858
|
|
|
|
|
1139
|
return scalar @{ $powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS] }; |
|
858
|
|
|
|
|
1564
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::nidset_id { |
146
|
0
|
|
|
0
|
|
0
|
my ( $powerset, $ix ) = @_; |
147
|
0
|
|
|
|
|
0
|
my $nidset_ids = $powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS]; |
148
|
0
|
0
|
|
|
|
0
|
return if $ix > $#{$nidset_ids}; |
|
0
|
|
|
|
|
0
|
|
149
|
0
|
|
|
|
|
0
|
return $powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS]->[$ix]; |
150
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Powerset::nidset_id |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::nidset { |
153
|
1160
|
|
|
1160
|
|
1911
|
my ( $powerset, $asf, $ix ) = @_; |
154
|
1160
|
|
|
|
|
1539
|
my $nidset_ids = $powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS]; |
155
|
1160
|
50
|
|
|
|
1486
|
return if $ix > $#{$nidset_ids}; |
|
1160
|
|
|
|
|
2215
|
|
156
|
1160
|
|
|
|
|
1691
|
my $nidset_id = $powerset->[Marpa::R2::Internal::Powerset::NIDSET_IDS]->[$ix]; |
157
|
1160
|
|
|
|
|
1589
|
my $nidset_by_id = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
158
|
1160
|
|
|
|
|
1953
|
return $nidset_by_id->[$nidset_id]; |
159
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Powerset::nidset_id |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::id { |
162
|
0
|
|
|
0
|
|
0
|
my ($powerset) = @_; |
163
|
0
|
|
|
|
|
0
|
return $powerset->[Marpa::R2::Internal::Powerset::ID]; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub Marpa::R2::Powerset::show { |
167
|
0
|
|
|
0
|
|
0
|
my ($powerset) = @_; |
168
|
0
|
|
|
|
|
0
|
my $id = $powerset->id(); |
169
|
0
|
|
|
|
|
0
|
my $nidset_ids = $powerset->nidset_ids(); |
170
|
0
|
|
|
|
|
0
|
return "Powerset #$id: " . join q{ }, @{$nidset_ids}; |
|
0
|
|
|
|
|
0
|
|
171
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Powerset::show |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub set_last_choice { |
174
|
26134
|
|
|
26134
|
|
37309
|
my ( $asf, $nook ) = @_; |
175
|
26134
|
|
|
|
|
35513
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES]; |
176
|
26134
|
|
|
|
|
33203
|
my $or_node_id = $nook->[Marpa::R2::Internal::Nook::OR_NODE]; |
177
|
26134
|
|
|
|
|
32838
|
my $and_nodes = $or_nodes->[$or_node_id]; |
178
|
26134
|
|
|
|
|
33497
|
my $choice = $nook->[Marpa::R2::Internal::Nook::FIRST_CHOICE]; |
179
|
26134
|
100
|
|
|
|
31060
|
return if $choice > $#{$and_nodes}; |
|
26134
|
|
|
|
|
63297
|
|
180
|
13598
|
100
|
|
|
|
22277
|
if ( nook_has_semantic_cause( $asf, $nook ) ) { |
181
|
10934
|
|
|
|
|
14579
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
182
|
10934
|
|
|
|
|
14033
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
183
|
10934
|
|
|
|
|
13925
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
184
|
10934
|
|
|
|
|
12993
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
185
|
10934
|
|
|
|
|
13008
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
186
|
10934
|
|
|
|
|
14045
|
my $and_node_id = $and_nodes->[$choice]; |
187
|
10934
|
|
100
|
|
|
32906
|
my $current_predecessor = |
188
|
|
|
|
|
|
|
$bocage->_marpa_b_and_node_predecessor($and_node_id) // -1; |
189
|
10934
|
|
|
|
|
14279
|
AND_NODE: while (1) { |
190
|
10987
|
|
|
|
|
13886
|
$choice++; |
191
|
10987
|
|
|
|
|
14207
|
$and_node_id = $and_nodes->[$choice]; |
192
|
10987
|
100
|
|
|
|
19754
|
last AND_NODE if not defined $and_node_id; |
193
|
59
|
|
100
|
|
|
249
|
my $next_predecessor = |
194
|
|
|
|
|
|
|
$bocage->_marpa_b_and_node_predecessor($and_node_id) // -1; |
195
|
59
|
100
|
|
|
|
142
|
last AND_NODE if $current_predecessor != $next_predecessor; |
196
|
|
|
|
|
|
|
} ## end AND_NODE: while (1) |
197
|
10934
|
|
|
|
|
16160
|
$choice--; |
198
|
|
|
|
|
|
|
} ## end if ( nook_has_semantic_cause( $asf, $nook ) ) |
199
|
13598
|
|
|
|
|
19049
|
$nook->[Marpa::R2::Internal::Nook::LAST_CHOICE] = $choice; |
200
|
13598
|
|
|
|
|
19719
|
return $choice; |
201
|
|
|
|
|
|
|
} ## end sub set_last_choice |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub nook_new { |
204
|
12536
|
|
|
12536
|
|
20552
|
my ( $asf, $or_node_id, $parent_or_node_id ) = @_; |
205
|
12536
|
|
|
|
|
18512
|
my $nook = []; |
206
|
12536
|
|
|
|
|
22825
|
$nook->[Marpa::R2::Internal::Nook::OR_NODE] = $or_node_id; |
207
|
12536
|
|
100
|
|
|
23619
|
$nook->[Marpa::R2::Internal::Nook::PARENT] = $parent_or_node_id // -1; |
208
|
12536
|
|
|
|
|
16646
|
$nook->[Marpa::R2::Internal::Nook::FIRST_CHOICE] = 0; |
209
|
12536
|
|
|
|
|
23673
|
set_last_choice( $asf, $nook ); |
210
|
12536
|
|
|
|
|
17399
|
return $nook; |
211
|
|
|
|
|
|
|
} ## end sub nook_new |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub nook_increment { |
214
|
13598
|
|
|
13598
|
|
19003
|
my ( $asf, $nook ) = @_; |
215
|
13598
|
|
50
|
|
|
22928
|
$nook->[Marpa::R2::Internal::Nook::LAST_CHOICE] //= 0; |
216
|
13598
|
|
|
|
|
18945
|
$nook->[Marpa::R2::Internal::Nook::FIRST_CHOICE] = |
217
|
|
|
|
|
|
|
$nook->[Marpa::R2::Internal::Nook::LAST_CHOICE] + 1; |
218
|
13598
|
100
|
|
|
|
20395
|
return if not defined set_last_choice( $asf, $nook ); |
219
|
1062
|
|
|
|
|
2080
|
return 1; |
220
|
|
|
|
|
|
|
} ## end sub nook_increment |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub nook_has_semantic_cause { |
223
|
45994
|
|
|
45994
|
|
63765
|
my ( $asf, $nook ) = @_; |
224
|
45994
|
|
|
|
|
61979
|
my $or_node = $nook->[Marpa::R2::Internal::Nook::OR_NODE]; |
225
|
45994
|
|
|
|
|
56553
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
226
|
45994
|
|
|
|
|
54856
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
227
|
45994
|
|
|
|
|
57158
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
228
|
45994
|
|
|
|
|
58978
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
229
|
45994
|
|
|
|
|
56668
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
230
|
|
|
|
|
|
|
|
231
|
45994
|
|
|
|
|
87696
|
my $irl_id = $bocage->_marpa_b_or_node_irl($or_node); |
232
|
45994
|
|
|
|
|
85369
|
my $predot_position = $bocage->_marpa_b_or_node_position($or_node) - 1; |
233
|
45994
|
|
|
|
|
81970
|
my $predot_isyid = |
234
|
|
|
|
|
|
|
$grammar_c->_marpa_g_irl_rhs( $irl_id, $predot_position ); |
235
|
45994
|
|
|
|
|
117219
|
return $grammar_c->_marpa_g_nsy_is_semantic($predot_isyid); |
236
|
|
|
|
|
|
|
} ## end sub nook_has_semantic_cause |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# No check for conflicting usage -- value(), asf(), etc. |
239
|
|
|
|
|
|
|
# at this point |
240
|
|
|
|
|
|
|
sub Marpa::R2::ASF::peak { |
241
|
52
|
|
|
52
|
0
|
176
|
my ($asf) = @_; |
242
|
52
|
|
|
|
|
121
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES]; |
243
|
52
|
|
|
|
|
102
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
244
|
52
|
|
|
|
|
85
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
245
|
|
|
|
|
|
|
|
246
|
52
|
|
|
|
|
84
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
247
|
52
|
50
|
|
|
|
156
|
die 'No Bocage' if not $bocage; |
248
|
52
|
|
|
|
|
208
|
my $augment_or_node_id = $bocage->_marpa_b_top_or_node(); |
249
|
52
|
|
|
|
|
106
|
my $augment_and_node_id = $or_nodes->[$augment_or_node_id]->[0]; |
250
|
52
|
|
|
|
|
168
|
my $start_or_node_id = |
251
|
|
|
|
|
|
|
$bocage->_marpa_b_and_node_cause($augment_and_node_id); |
252
|
|
|
|
|
|
|
|
253
|
52
|
|
|
|
|
202
|
my $base_nidset = Marpa::R2::Nidset->obtain( $asf, $start_or_node_id ); |
254
|
52
|
|
|
|
|
169
|
my $glade_id = $base_nidset->id(); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# Cannot "obtain" the glade if it is not registered |
257
|
52
|
|
|
|
|
152
|
$asf->[Marpa::R2::Internal::ASF::GLADES]->[$glade_id] |
258
|
|
|
|
|
|
|
->[Marpa::R2::Internal::Glade::REGISTERED] = 1; |
259
|
52
|
|
|
|
|
185
|
glade_obtain( $asf, $glade_id ); |
260
|
52
|
|
|
|
|
124
|
return $glade_id; |
261
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::peak |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
our $NID_LEAF_BASE = -43; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# Range from -1 to -42 reserved for special values |
266
|
5459
|
|
|
5459
|
|
13599
|
sub and_node_to_nid { return -$_[0] + $NID_LEAF_BASE; } |
267
|
1346
|
|
|
1346
|
|
2349
|
sub nid_to_and_node { return -$_[0] + $NID_LEAF_BASE; } |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub normalize_asf_blessing { |
270
|
648
|
|
|
648
|
|
1028
|
my ($name) = @_; |
271
|
648
|
|
|
|
|
1826
|
$name =~ s/\A \s * //xms; |
272
|
648
|
|
|
|
|
2092
|
$name =~ s/ \s * \z//xms; |
273
|
648
|
|
|
|
|
1177
|
$name =~ s/ \s+ / /gxms; |
274
|
648
|
|
|
|
|
1317
|
$name =~ s/ \W /_/gxms; |
275
|
648
|
|
|
|
|
2425
|
return $name; |
276
|
|
|
|
|
|
|
} ## end sub normalize_asf_blessing |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::blessings_set { |
279
|
49
|
|
|
49
|
|
156
|
my ( $asf, $default_blessing ) = @_; |
280
|
49
|
|
|
|
|
98
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
281
|
49
|
|
|
|
|
94
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
282
|
49
|
|
|
|
|
89
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
283
|
49
|
|
|
|
|
94
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
284
|
49
|
|
|
|
|
85
|
my $rules = $grammar->[Marpa::R2::Internal::Grammar::RULES]; |
285
|
49
|
|
|
|
|
84
|
my $symbols = $grammar->[Marpa::R2::Internal::Grammar::SYMBOLS]; |
286
|
|
|
|
|
|
|
|
287
|
49
|
|
|
|
|
107
|
my $default_token_blessing_package = |
288
|
|
|
|
|
|
|
$asf->[ Marpa::R2::Internal::ASF::DEFAULT_TOKEN_BLESSING_PACKAGE ]; |
289
|
49
|
|
|
|
|
91
|
my $default_rule_blessing_package = |
290
|
|
|
|
|
|
|
$asf->[Marpa::R2::Internal::ASF::DEFAULT_RULE_BLESSING_PACKAGE]; |
291
|
|
|
|
|
|
|
|
292
|
49
|
|
|
|
|
86
|
my @rule_blessing = (); |
293
|
49
|
|
|
|
|
155
|
my $highest_rule_id = $grammar_c->highest_rule_id(); |
294
|
49
|
|
|
|
|
164
|
RULE: for ( my $rule_id = 0; $rule_id <= $highest_rule_id; $rule_id++ ) { |
295
|
368
|
|
|
|
|
520
|
my $blessing; |
296
|
368
|
|
|
|
|
532
|
my $rule = $rules->[$rule_id]; |
297
|
368
|
50
|
|
|
|
730
|
$blessing = $rule->[Marpa::R2::Internal::Rule::BLESSING] |
298
|
|
|
|
|
|
|
if defined $rule; |
299
|
368
|
100
|
66
|
|
|
1194
|
if ( defined $blessing and q{::} ne substr $blessing, 0, 2 ) { |
300
|
120
|
|
|
|
|
171
|
$rule_blessing[$rule_id] = $blessing; |
301
|
120
|
|
|
|
|
212
|
next RULE; |
302
|
|
|
|
|
|
|
} |
303
|
248
|
|
|
|
|
591
|
my $lhs_id = $grammar_c->rule_lhs($rule_id); |
304
|
248
|
|
|
|
|
655
|
my $name = $grammar->symbol_name($lhs_id); |
305
|
248
|
|
|
|
|
555
|
$rule_blessing[$rule_id] = join q{::}, $default_rule_blessing_package, |
306
|
|
|
|
|
|
|
normalize_asf_blessing($name); |
307
|
|
|
|
|
|
|
} ## end RULE: for ( my $rule_id = 0; $rule_id <= $highest_rule_id; ...) |
308
|
|
|
|
|
|
|
|
309
|
49
|
|
|
|
|
102
|
my @symbol_blessing = (); |
310
|
49
|
|
|
|
|
193
|
my $highest_symbol_id = $grammar_c->highest_symbol_id(); |
311
|
|
|
|
|
|
|
SYMBOL: |
312
|
49
|
|
|
|
|
163
|
for ( my $symbol_id = 0; $symbol_id <= $highest_symbol_id; $symbol_id++ ) |
313
|
|
|
|
|
|
|
{ |
314
|
424
|
|
|
|
|
587
|
my $blessing; |
315
|
424
|
|
|
|
|
628
|
my $symbol = $symbols->[$symbol_id]; |
316
|
424
|
50
|
|
|
|
775
|
$blessing = $symbol->[Marpa::R2::Internal::Symbol::BLESSING] |
317
|
|
|
|
|
|
|
if defined $symbol; |
318
|
424
|
100
|
66
|
|
|
851
|
if ( defined $blessing and q{::} ne substr $blessing, 0, 2 ) { |
319
|
24
|
|
|
|
|
36
|
$symbol_blessing[$symbol_id] = $blessing; |
320
|
24
|
|
|
|
|
56
|
next SYMBOL; |
321
|
|
|
|
|
|
|
} |
322
|
400
|
|
|
|
|
815
|
my $name = $grammar->symbol_name($symbol_id); |
323
|
400
|
|
|
|
|
752
|
$symbol_blessing[$symbol_id] = join q{::}, |
324
|
|
|
|
|
|
|
$default_token_blessing_package, |
325
|
|
|
|
|
|
|
normalize_asf_blessing($name); |
326
|
|
|
|
|
|
|
} ## end SYMBOL: for ( my $symbol_id = 0; $symbol_id <= $highest_symbol_id...) |
327
|
49
|
|
|
|
|
153
|
$asf->[Marpa::R2::Internal::ASF::RULE_BLESSINGS] = \@rule_blessing; |
328
|
49
|
|
|
|
|
104
|
$asf->[Marpa::R2::Internal::ASF::SYMBOL_BLESSINGS] = \@symbol_blessing; |
329
|
49
|
|
|
|
|
123
|
return $asf; |
330
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::blessings_set |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
# Returns undef if no parse |
333
|
|
|
|
|
|
|
sub Marpa::R2::ASF::new { |
334
|
49
|
|
|
49
|
1
|
545
|
my ( $class, @arg_hashes ) = @_; |
335
|
49
|
|
|
|
|
152
|
my $asf = bless [], $class; |
336
|
|
|
|
|
|
|
|
337
|
49
|
|
|
|
|
106
|
my $slr; |
338
|
|
|
|
|
|
|
|
339
|
49
|
|
|
|
|
127
|
for my $arg_hash (@arg_hashes) { |
340
|
49
|
|
|
|
|
90
|
ARG: for my $arg ( keys %{$arg_hash} ) { |
|
49
|
|
|
|
|
166
|
|
341
|
74
|
100
|
|
|
|
202
|
if ( $arg eq 'slr' ) { |
342
|
|
|
|
|
|
|
$asf->[Marpa::R2::Internal::ASF::SLR] = $slr = |
343
|
49
|
|
|
|
|
192
|
$arg_hash->{$arg}; |
344
|
49
|
|
|
|
|
132
|
next ARG; |
345
|
|
|
|
|
|
|
} |
346
|
25
|
50
|
|
|
|
61
|
if ( $arg eq 'factoring_max' ) { |
347
|
|
|
|
|
|
|
$asf->[Marpa::R2::Internal::ASF::FACTORING_MAX] = |
348
|
25
|
|
|
|
|
59
|
$arg_hash->{$arg}; |
349
|
25
|
|
|
|
|
48
|
next ARG; |
350
|
|
|
|
|
|
|
} |
351
|
|
|
|
|
|
|
Marpa::R2::exception( |
352
|
0
|
|
|
|
|
0
|
qq{Unknown named arg to $asf->new(): "$arg"}); |
353
|
|
|
|
|
|
|
} ## end ARG: for my $arg ( keys %{$arg_hash} ) |
354
|
|
|
|
|
|
|
} ## end for my $arg_hash (@arg_hashes) |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
Marpa::R2::exception( |
357
|
49
|
50
|
|
|
|
145
|
q{The "slr" named argument must be specified with the Marpa::R2::ASF::new method} |
358
|
|
|
|
|
|
|
) if not defined $slr; |
359
|
49
|
|
|
|
|
97
|
$asf->[Marpa::R2::Internal::ASF::SLR] = $slr; |
360
|
49
|
|
100
|
|
|
199
|
$asf->[Marpa::R2::Internal::ASF::FACTORING_MAX] //= 42; |
361
|
|
|
|
|
|
|
|
362
|
49
|
|
|
|
|
94
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
363
|
|
|
|
|
|
|
|
364
|
49
|
50
|
|
|
|
132
|
if ( defined $recce->[Marpa::R2::Internal::Recognizer::TREE_MODE] ) { |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
# If we already in ASF mode, or are in valuation mode, we cannot create an ASF |
367
|
0
|
|
|
|
|
0
|
Marpa::R2::exception( |
368
|
|
|
|
|
|
|
"An attempt was made to create an ASF for a SLIF recognizer already in use\n", |
369
|
|
|
|
|
|
|
" The recognizer must be reset first\n", |
370
|
|
|
|
|
|
|
' The current SLIF recognizer mode is "', |
371
|
|
|
|
|
|
|
$recce->[Marpa::R2::Internal::Recognizer::TREE_MODE], |
372
|
|
|
|
|
|
|
qq{"\n} |
373
|
|
|
|
|
|
|
); |
374
|
|
|
|
|
|
|
} ## end if ( defined $recce->[Marpa::R2::Internal::Recognizer::TREE_MODE...]) |
375
|
49
|
|
|
|
|
119
|
$recce->[Marpa::R2::Internal::Recognizer::TREE_MODE] = 'forest'; |
376
|
|
|
|
|
|
|
|
377
|
49
|
|
|
|
|
224
|
( $asf->[Marpa::R2::Internal::ASF::RULE_RESOLUTIONS], |
378
|
|
|
|
|
|
|
$asf->[Marpa::R2::Internal::ASF::LEXEME_RESOLUTIONS] |
379
|
|
|
|
|
|
|
) = Marpa::R2::Internal::Value::resolve_recce( $recce, $slr ); |
380
|
|
|
|
|
|
|
|
381
|
49
|
|
|
|
|
175
|
$asf->[Marpa::R2::Internal::ASF::SYMCH_BLESSING_PACKAGE] = 'My_Symch'; |
382
|
49
|
|
|
|
|
119
|
$asf->[Marpa::R2::Internal::ASF::FACTORING_BLESSING_PACKAGE] = |
383
|
|
|
|
|
|
|
'My_Factoring'; |
384
|
49
|
|
|
|
|
123
|
$asf->[Marpa::R2::Internal::ASF::PROBLEM_BLESSING_PACKAGE] = 'My_Problem'; |
385
|
49
|
|
|
|
|
102
|
$asf->[Marpa::R2::Internal::ASF::DEFAULT_RULE_BLESSING_PACKAGE] = |
386
|
|
|
|
|
|
|
'My_Rule'; |
387
|
49
|
|
|
|
|
100
|
$asf->[Marpa::R2::Internal::ASF::DEFAULT_TOKEN_BLESSING_PACKAGE] = |
388
|
|
|
|
|
|
|
'My_Token'; |
389
|
|
|
|
|
|
|
|
390
|
49
|
|
|
|
|
112
|
$asf->[Marpa::R2::Internal::ASF::NEXT_INTSET_ID] = 0; |
391
|
49
|
|
|
|
|
110
|
$asf->[Marpa::R2::Internal::ASF::INTSET_BY_KEY] = {}; |
392
|
|
|
|
|
|
|
|
393
|
49
|
|
|
|
|
97
|
$asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID] = []; |
394
|
49
|
|
|
|
|
100
|
$asf->[Marpa::R2::Internal::ASF::POWERSET_BY_ID] = []; |
395
|
|
|
|
|
|
|
|
396
|
49
|
|
|
|
|
84
|
$asf->[Marpa::R2::Internal::ASF::GLADES] = []; |
397
|
|
|
|
|
|
|
|
398
|
49
|
|
|
|
|
92
|
my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR]; |
399
|
49
|
|
|
|
|
84
|
my $thin_slr = $slr->[Marpa::R2::Internal::Scanless::R::C]; |
400
|
49
|
|
|
|
|
85
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
401
|
49
|
|
|
|
|
90
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
402
|
49
|
|
|
|
|
84
|
my $recce_c = $recce->[Marpa::R2::Internal::Recognizer::C]; |
403
|
|
|
|
|
|
|
|
404
|
49
|
|
|
|
|
166
|
my $ordering = $recce->ordering_get(); |
405
|
49
|
50
|
|
|
|
140
|
Marpa::R2::exception( "Parse failed\n") if not $ordering; |
406
|
|
|
|
|
|
|
|
407
|
49
|
50
|
|
|
|
239
|
Marpa::R2::exception( |
408
|
|
|
|
|
|
|
"An attempt was make to create an ASF for a null parse\n", |
409
|
|
|
|
|
|
|
" A null parse is a successful parse of a zero-length string\n", |
410
|
|
|
|
|
|
|
" ASF's are not defined for null parses\n" |
411
|
|
|
|
|
|
|
) if $ordering->is_null(); |
412
|
|
|
|
|
|
|
|
413
|
49
|
|
|
|
|
103
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
414
|
|
|
|
|
|
|
|
415
|
49
|
|
|
|
|
122
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES] = []; |
416
|
135
|
|
|
135
|
|
74447
|
use sort 'stable'; |
|
135
|
|
|
|
|
80430
|
|
|
135
|
|
|
|
|
926
|
|
417
|
49
|
|
|
|
|
109
|
OR_NODE: for ( my $or_node_id = 0;; $or_node_id++ ) { |
418
|
1759
|
|
|
|
|
4027
|
my @and_node_ids = |
419
|
|
|
|
|
|
|
$ordering->_marpa_o_or_node_and_node_ids($or_node_id); |
420
|
1759
|
100
|
|
|
|
3167
|
last OR_NODE if not scalar @and_node_ids; |
421
|
2065
|
|
|
|
|
4067
|
my @sorted_and_node_ids = map { $_->[-1] } sort { $a <=> $b } map { |
|
357
|
|
|
|
|
798
|
|
422
|
1710
|
|
100
|
|
|
2426
|
[ ( $bocage->_marpa_b_and_node_predecessor($_) // -1 ), $_ ] |
|
2065
|
|
|
|
|
6835
|
|
423
|
|
|
|
|
|
|
} @and_node_ids; |
424
|
1710
|
|
|
|
|
3602
|
$or_nodes->[$or_node_id] = \@and_node_ids; |
425
|
|
|
|
|
|
|
} ## end OR_NODE: for ( my $or_node_id = 0;; $or_node_id++ ) |
426
|
|
|
|
|
|
|
|
427
|
49
|
|
|
|
|
360
|
blessings_set($asf); |
428
|
49
|
|
|
|
|
192
|
return $asf; |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::new |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
sub Marpa::R2::ASF::glade_is_visited { |
433
|
0
|
|
|
0
|
0
|
0
|
my ( $asf, $glade_id ) = @_; |
434
|
0
|
|
|
|
|
0
|
my $glade = $asf->[Marpa::R2::Internal::ASF::GLADES]->[$glade_id]; |
435
|
0
|
0
|
|
|
|
0
|
return if not $glade; |
436
|
0
|
|
|
|
|
0
|
return $glade->[Marpa::R2::Internal::Glade::VISITED]; |
437
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::glade_is_visited |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
sub Marpa::R2::ASF::glade_visited_clear { |
440
|
0
|
|
|
0
|
0
|
0
|
my ( $asf, $glade_id ) = @_; |
441
|
0
|
0
|
|
|
|
0
|
my $glade_list = |
442
|
|
|
|
|
|
|
defined $glade_id |
443
|
|
|
|
|
|
|
? [ $asf->[Marpa::R2::Internal::ASF::GLADES]->[$glade_id] ] |
444
|
|
|
|
|
|
|
: $asf->[Marpa::R2::Internal::ASF::GLADES]; |
445
|
|
|
|
|
|
|
$_->[Marpa::R2::Internal::Glade::VISITED] = undef |
446
|
0
|
|
|
|
|
0
|
for grep {defined} @{$glade_list}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
447
|
0
|
|
|
|
|
0
|
return; |
448
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::glade_visited_clear |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
sub nid_sort_ix { |
451
|
900
|
|
|
900
|
|
1571
|
my ( $asf, $nid ) = @_; |
452
|
900
|
|
|
|
|
1342
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
453
|
900
|
|
|
|
|
1196
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
454
|
900
|
|
|
|
|
1233
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
455
|
900
|
|
|
|
|
1176
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
456
|
900
|
|
|
|
|
1324
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
457
|
900
|
100
|
|
|
|
2195
|
if ( $nid >= 0 ) { |
458
|
310
|
|
|
|
|
907
|
my $irl_id = $bocage->_marpa_b_or_node_irl($nid); |
459
|
310
|
|
|
|
|
1155
|
return $grammar_c->_marpa_g_source_xrl($irl_id); |
460
|
|
|
|
|
|
|
} |
461
|
590
|
|
|
|
|
1095
|
my $and_node_id = nid_to_and_node($nid); |
462
|
590
|
|
|
|
|
1667
|
my $token_nsy_id = $bocage->_marpa_b_and_node_symbol($and_node_id); |
463
|
590
|
|
|
|
|
1553
|
my $token_id = $grammar_c->_marpa_g_source_xsy($token_nsy_id); |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
# -2 is reserved for 'end of data' |
466
|
590
|
|
|
|
|
1181
|
return -$token_id - 3; |
467
|
|
|
|
|
|
|
} ## end sub nid_sort_ix |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
sub Marpa::R2::ASF::grammar { |
470
|
223
|
|
|
223
|
1
|
535
|
my ($asf) = @_; |
471
|
223
|
|
|
|
|
326
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
472
|
223
|
|
|
|
|
309
|
my $slg = $slr->[Marpa::R2::Internal::Scanless::R::GRAMMAR]; |
473
|
223
|
|
|
|
|
356
|
return $slg; |
474
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::grammar |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
sub nid_rule_id { |
477
|
875
|
|
|
875
|
|
1412
|
my ( $asf, $nid ) = @_; |
478
|
875
|
100
|
|
|
|
3133
|
return if $nid < 0; |
479
|
285
|
|
|
|
|
476
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
480
|
285
|
|
|
|
|
409
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
481
|
285
|
|
|
|
|
368
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
482
|
285
|
|
|
|
|
451
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
483
|
285
|
|
|
|
|
388
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
484
|
285
|
|
|
|
|
725
|
my $irl_id = $bocage->_marpa_b_or_node_irl($nid); |
485
|
285
|
|
|
|
|
640
|
my $xrl_id = $grammar_c->_marpa_g_source_xrl($irl_id); |
486
|
285
|
|
|
|
|
731
|
return $xrl_id; |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
sub or_node_es_span { |
490
|
1651
|
|
|
1651
|
|
2544
|
my ( $asf, $choicepoint ) = @_; |
491
|
1651
|
|
|
|
|
2209
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
492
|
1651
|
|
|
|
|
2355
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
493
|
1651
|
|
|
|
|
2210
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
494
|
1651
|
|
|
|
|
3904
|
my $origin_es = $bocage->_marpa_b_or_node_origin($choicepoint); |
495
|
1651
|
|
|
|
|
3486
|
my $current_es = $bocage->_marpa_b_or_node_set($choicepoint); |
496
|
1651
|
|
|
|
|
4700
|
return $origin_es, $current_es - $origin_es; |
497
|
|
|
|
|
|
|
} ## end sub or_node_es_span |
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub token_es_span { |
500
|
638
|
|
|
638
|
|
974
|
my ( $asf, $and_node_id ) = @_; |
501
|
638
|
|
|
|
|
938
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
502
|
638
|
|
|
|
|
875
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
503
|
638
|
|
|
|
|
909
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
504
|
638
|
|
|
|
|
857
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
505
|
638
|
|
|
|
|
864
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
506
|
638
|
|
|
|
|
1754
|
my $predecessor_id = $bocage->_marpa_b_and_node_predecessor($and_node_id); |
507
|
638
|
|
|
|
|
1360
|
my $parent_or_node_id = $bocage->_marpa_b_and_node_parent($and_node_id); |
508
|
|
|
|
|
|
|
|
509
|
638
|
100
|
|
|
|
1334
|
if ( defined $predecessor_id ) { |
510
|
249
|
|
|
|
|
586
|
my $origin_es = $bocage->_marpa_b_or_node_set($predecessor_id); |
511
|
249
|
|
|
|
|
482
|
my $current_es = $bocage->_marpa_b_or_node_set($parent_or_node_id); |
512
|
249
|
|
|
|
|
616
|
return ( $origin_es, $current_es - $origin_es ); |
513
|
|
|
|
|
|
|
} |
514
|
389
|
|
|
|
|
706
|
return or_node_es_span( $asf, $parent_or_node_id ); |
515
|
|
|
|
|
|
|
} ## end sub token_es_span |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
sub nid_literal { |
518
|
1805
|
|
|
1805
|
|
2839
|
my ( $asf, $nid ) = @_; |
519
|
1805
|
|
|
|
|
2595
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
520
|
1805
|
100
|
|
|
|
3518
|
if ( $nid <= $NID_LEAF_BASE ) { |
521
|
606
|
|
|
|
|
1041
|
my $and_node_id = nid_to_and_node($nid); |
522
|
606
|
|
|
|
|
1164
|
my ( $start, $length ) = token_es_span( $asf, $and_node_id ); |
523
|
606
|
100
|
|
|
|
1977
|
return q{} if $length == 0; |
524
|
186
|
|
|
|
|
661
|
return $slr->substring( $start, $length ); |
525
|
|
|
|
|
|
|
} ## end if ( $nid <= $NID_LEAF_BASE ) |
526
|
1199
|
50
|
|
|
|
2293
|
if ( $nid >= 0 ) { |
527
|
1199
|
|
|
|
|
2101
|
return $slr->substring( or_node_es_span( $asf, $nid ) ); |
528
|
|
|
|
|
|
|
} |
529
|
0
|
|
|
|
|
0
|
Marpa::R2::exception("No literal for node ID: $nid"); |
530
|
|
|
|
|
|
|
} |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
sub nid_span { |
533
|
95
|
|
|
95
|
|
163
|
my ( $asf, $nid ) = @_; |
534
|
95
|
|
|
|
|
144
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
535
|
95
|
100
|
|
|
|
246
|
if ( $nid <= $NID_LEAF_BASE ) { |
536
|
32
|
|
|
|
|
52
|
my $and_node_id = nid_to_and_node($nid); |
537
|
32
|
|
|
|
|
57
|
my ( $start, $length ) = token_es_span( $asf, $and_node_id ); |
538
|
32
|
50
|
|
|
|
99
|
return ($start, 0) if $length == 0; |
539
|
0
|
|
|
|
|
0
|
return $slr->es_to_input_span( $start, $length ); |
540
|
|
|
|
|
|
|
} ## end if ( $nid <= $NID_LEAF_BASE ) |
541
|
63
|
50
|
|
|
|
119
|
if ( $nid >= 0 ) { |
542
|
63
|
|
|
|
|
143
|
return $slr->es_to_input_span( or_node_es_span( $asf, $nid ) ); |
543
|
|
|
|
|
|
|
} |
544
|
0
|
|
|
|
|
0
|
Marpa::R2::exception("No literal for node ID: $nid"); |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
sub nid_token_id { |
548
|
178
|
|
|
178
|
|
313
|
my ( $asf, $nid ) = @_; |
549
|
178
|
100
|
|
|
|
453
|
return if $nid > $NID_LEAF_BASE; |
550
|
118
|
|
|
|
|
216
|
my $and_node_id = nid_to_and_node($nid); |
551
|
118
|
|
|
|
|
226
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
552
|
118
|
|
|
|
|
165
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
553
|
118
|
|
|
|
|
172
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
554
|
118
|
|
|
|
|
164
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
555
|
118
|
|
|
|
|
156
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
556
|
118
|
|
|
|
|
307
|
my $token_nsy_id = $bocage->_marpa_b_and_node_symbol($and_node_id); |
557
|
118
|
|
|
|
|
287
|
my $token_id = $grammar_c->_marpa_g_source_xsy($token_nsy_id); |
558
|
118
|
|
|
|
|
228
|
return $token_id; |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
sub nid_symbol_id { |
562
|
178
|
|
|
178
|
|
332
|
my ( $asf, $nid ) = @_; |
563
|
178
|
|
|
|
|
355
|
my $token_id = nid_token_id($asf, $nid); |
564
|
178
|
100
|
|
|
|
472
|
return $token_id if defined $token_id; |
565
|
60
|
50
|
|
|
|
115
|
Marpa::R2::exception("No symbol ID for node ID: $nid") if $nid < 0; |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# Not a token, so return the LHS of the rule |
568
|
60
|
|
|
|
|
100
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
569
|
60
|
|
|
|
|
90
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
570
|
60
|
|
|
|
|
85
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
571
|
60
|
|
|
|
|
131
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
572
|
60
|
|
|
|
|
88
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
573
|
60
|
|
|
|
|
170
|
my $irl_id = $bocage->_marpa_b_or_node_irl($nid); |
574
|
60
|
|
|
|
|
159
|
my $xrl_id = $grammar_c->_marpa_g_source_xrl($irl_id); |
575
|
60
|
|
|
|
|
151
|
my $lhs_id = $grammar_c->rule_lhs($xrl_id); |
576
|
60
|
|
|
|
|
189
|
return $lhs_id; |
577
|
|
|
|
|
|
|
} |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
sub nid_symbol_name { |
580
|
0
|
|
|
0
|
|
0
|
my ( $asf, $nid ) = @_; |
581
|
0
|
|
|
|
|
0
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
582
|
0
|
|
|
|
|
0
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
583
|
0
|
|
|
|
|
0
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
584
|
0
|
|
|
|
|
0
|
my $symbol_id = nid_symbol_id($asf, $nid); |
585
|
0
|
|
|
|
|
0
|
return $grammar->symbol_name($symbol_id); |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
sub nid_token_name { |
589
|
0
|
|
|
0
|
|
0
|
my ( $asf, $nid ) = @_; |
590
|
0
|
|
|
|
|
0
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
591
|
0
|
|
|
|
|
0
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
592
|
0
|
|
|
|
|
0
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
593
|
0
|
|
|
|
|
0
|
my $token_id = nid_token_id($asf, $nid); |
594
|
0
|
0
|
|
|
|
0
|
return if not defined $token_id; |
595
|
0
|
|
|
|
|
0
|
return $grammar->symbol_name($token_id); |
596
|
|
|
|
|
|
|
} |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
# Memoization is heavily used -- it needs to be to keep the worst cases from |
599
|
|
|
|
|
|
|
# going exponential. The need to memoize is the reason for the very heavy use of |
600
|
|
|
|
|
|
|
# hashes. For example, quite often an HOH (hash of hashes) is used where |
601
|
|
|
|
|
|
|
# an HoL (hash of lists) would usually be preferred. But the HOL would leave me |
602
|
|
|
|
|
|
|
# with the problem of having duplicates, which if followed up upon, would make |
603
|
|
|
|
|
|
|
# the algorithm go exponential. |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
# For the "seen" hashes, the intent, in C, is to use a bit vector. Since typically |
606
|
|
|
|
|
|
|
# choicepoints will only use a tiny fraction of the or- and and-node space, I'll create |
607
|
|
|
|
|
|
|
# a per-choicepoint index in the bit vector for each or- and and-node. The index will |
608
|
|
|
|
|
|
|
# per-ASF, and to avoid the overhead of clearing it, it will track, or each node, the |
609
|
|
|
|
|
|
|
# current CP indexing it. It is assumed that the indexes need only remain valid within |
610
|
|
|
|
|
|
|
# the method call that constructs the CPI (choicepoint iterator). |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
sub first_factoring { |
613
|
310
|
|
|
310
|
|
520
|
my ($choicepoint, $nid_of_choicepoint) = @_; |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
# Current NID of current SYMCH |
616
|
|
|
|
|
|
|
# The caller should ensure that we are never called unless the current |
617
|
|
|
|
|
|
|
# NID is for a rule. |
618
|
310
|
50
|
|
|
|
641
|
Marpa::R2::exception( |
619
|
|
|
|
|
|
|
"Internal error: first_factoring() called for negative NID: $nid_of_choicepoint" |
620
|
|
|
|
|
|
|
) if $nid_of_choicepoint < 0; |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
# Due to skipping, even the top or-node can have no valid choices |
623
|
310
|
|
|
|
|
459
|
my $asf = $choicepoint->[Marpa::R2::Internal::Choicepoint::ASF]; |
624
|
310
|
|
|
|
|
474
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES]; |
625
|
310
|
50
|
|
|
|
412
|
if ( not scalar @{ $or_nodes->[$nid_of_choicepoint] } ) { |
|
310
|
|
|
|
|
701
|
|
626
|
0
|
|
|
|
|
0
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK] = |
627
|
|
|
|
|
|
|
undef; |
628
|
0
|
|
|
|
|
0
|
return; |
629
|
|
|
|
|
|
|
} |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::OR_NODE_IN_USE] |
632
|
310
|
|
|
|
|
806
|
->{$nid_of_choicepoint} = 1; |
633
|
310
|
|
|
|
|
627
|
my $nook = nook_new( $asf, $nid_of_choicepoint ); |
634
|
310
|
|
|
|
|
691
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK] = |
635
|
|
|
|
|
|
|
[$nook]; |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
# Iterate as long as we cannot finish this stack |
638
|
310
|
|
|
|
|
776
|
while ( not factoring_finish($choicepoint, $nid_of_choicepoint) ) { |
639
|
0
|
0
|
|
|
|
0
|
return if not factoring_iterate($choicepoint); |
640
|
|
|
|
|
|
|
} |
641
|
310
|
|
|
|
|
543
|
return 1; |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
} |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
sub next_factoring { |
646
|
1372
|
|
|
1372
|
|
2471
|
my ($choicepoint, $nid_of_choicepoint) = @_; |
647
|
1372
|
|
|
|
|
2145
|
my $factoring_stack = |
648
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK]; |
649
|
1372
|
50
|
|
|
|
2733
|
Marpa::R2::exception( |
650
|
|
|
|
|
|
|
'Attempt to iterate factoring of uninitialized checkpoint') |
651
|
|
|
|
|
|
|
if not $factoring_stack; |
652
|
|
|
|
|
|
|
|
653
|
1372
|
|
|
|
|
2499
|
while ( factoring_iterate($choicepoint) ) { |
654
|
1062
|
50
|
|
|
|
2086
|
return 1 if factoring_finish($choicepoint, $nid_of_choicepoint); |
655
|
|
|
|
|
|
|
} |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
# Found nothing to iterate |
658
|
310
|
|
|
|
|
523
|
return; |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
sub factoring_iterate { |
662
|
1372
|
|
|
1372
|
|
2304
|
my ($choicepoint) = @_; |
663
|
1372
|
|
|
|
|
2051
|
my $asf = $choicepoint->[Marpa::R2::Internal::Choicepoint::ASF]; |
664
|
1372
|
|
|
|
|
1817
|
my $factoring_stack = |
665
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK]; |
666
|
1372
|
|
|
|
|
1711
|
FIND_NODE_TO_ITERATE: while (1) { |
667
|
13908
|
100
|
|
|
|
15892
|
if ( not scalar @{$factoring_stack} ) { |
|
13908
|
|
|
|
|
23563
|
|
668
|
310
|
|
|
|
|
501
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK] |
669
|
|
|
|
|
|
|
= undef; |
670
|
310
|
|
|
|
|
783
|
return; |
671
|
|
|
|
|
|
|
} |
672
|
13598
|
|
|
|
|
19568
|
my $top_nook = $factoring_stack->[-1]; |
673
|
13598
|
100
|
|
|
|
19697
|
if ( nook_increment( $asf, $top_nook ) ) { |
674
|
1062
|
|
|
|
|
2035
|
last FIND_NODE_TO_ITERATE; # in C, a "break" will do this |
675
|
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
# Could not iterate |
678
|
|
|
|
|
|
|
# "Dirty" the corresponding bits in the parent and pop this nook |
679
|
12536
|
|
|
|
|
16788
|
my $stack_ix_of_parent_nook = |
680
|
|
|
|
|
|
|
$top_nook->[Marpa::R2::Internal::Nook::PARENT]; |
681
|
12536
|
100
|
|
|
|
20362
|
if ( $stack_ix_of_parent_nook >= 0 ) { |
682
|
12226
|
|
|
|
|
15828
|
my $parent_nook = $factoring_stack->[$stack_ix_of_parent_nook]; |
683
|
12226
|
100
|
|
|
|
20264
|
$parent_nook->[Marpa::R2::Internal::Nook::CAUSE_IS_EXPANDED] = 0 |
684
|
|
|
|
|
|
|
if $top_nook->[Marpa::R2::Internal::Nook::IS_CAUSE]; |
685
|
12226
|
100
|
|
|
|
21342
|
$parent_nook->[Marpa::R2::Internal::Nook::PREDECESSOR_IS_EXPANDED] |
686
|
|
|
|
|
|
|
= 0 |
687
|
|
|
|
|
|
|
if $top_nook->[Marpa::R2::Internal::Nook::IS_PREDECESSOR]; |
688
|
|
|
|
|
|
|
} ## end if ( $stack_ix_of_parent_nook >= 0 ) |
689
|
|
|
|
|
|
|
|
690
|
12536
|
|
|
|
|
16655
|
my $top_or_node = $top_nook->[Marpa::R2::Internal::Nook::OR_NODE]; |
691
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::OR_NODE_IN_USE] |
692
|
12536
|
|
|
|
|
19858
|
->{$top_or_node} = undef; |
693
|
12536
|
|
|
|
|
14330
|
pop @{$factoring_stack}; |
|
12536
|
|
|
|
|
21581
|
|
694
|
|
|
|
|
|
|
} ## end FIND_NODE_TO_ITERATE: while (1) |
695
|
1062
|
|
|
|
|
2109
|
return 1; |
696
|
|
|
|
|
|
|
} ## end sub factoring_iterate |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
sub factoring_finish { |
699
|
1372
|
|
|
1372
|
|
2400
|
my ($choicepoint, $nid_of_choicepoint) = @_; |
700
|
1372
|
|
|
|
|
2043
|
my $asf = $choicepoint->[Marpa::R2::Internal::Choicepoint::ASF]; |
701
|
1372
|
|
|
|
|
1924
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES]; |
702
|
1372
|
|
|
|
|
1776
|
my $factoring_stack = |
703
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK]; |
704
|
|
|
|
|
|
|
|
705
|
1372
|
|
|
|
|
1928
|
my $nidset_by_id = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
706
|
1372
|
|
|
|
|
1921
|
my $powerset_by_id = $asf->[Marpa::R2::Internal::ASF::POWERSET_BY_ID]; |
707
|
|
|
|
|
|
|
|
708
|
1372
|
|
|
|
|
1765
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
709
|
1372
|
|
|
|
|
1754
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
710
|
1372
|
|
|
|
|
1880
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
711
|
1372
|
|
|
|
|
1867
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
712
|
1372
|
|
|
|
|
1815
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
713
|
|
|
|
|
|
|
|
714
|
1372
|
|
|
|
|
2014
|
my @worklist = ( 0 .. $#{$factoring_stack} ); |
|
1372
|
|
|
|
|
2732
|
|
715
|
|
|
|
|
|
|
|
716
|
1372
|
|
|
|
|
2898
|
DO_WORKLIST: while ( scalar @worklist ) { |
717
|
31030
|
|
|
|
|
40940
|
my $stack_ix_of_work_nook = $worklist[-1]; |
718
|
31030
|
|
|
|
|
40181
|
my $work_nook = $factoring_stack->[$stack_ix_of_work_nook]; |
719
|
31030
|
|
|
|
|
41937
|
my $work_or_node = $work_nook->[Marpa::R2::Internal::Nook::OR_NODE]; |
720
|
31030
|
|
|
|
|
38162
|
my $working_choice = |
721
|
|
|
|
|
|
|
$work_nook->[Marpa::R2::Internal::Nook::FIRST_CHOICE]; |
722
|
31030
|
|
|
|
|
40319
|
my $work_and_node_id = $or_nodes->[$work_or_node]->[$working_choice]; |
723
|
31030
|
|
|
|
|
57686
|
my $child_or_node; |
724
|
|
|
|
|
|
|
my $child_is_cause; |
725
|
31030
|
|
|
|
|
0
|
my $child_is_predecessor; |
726
|
|
|
|
|
|
|
FIND_CHILD_OR_NODE: { |
727
|
|
|
|
|
|
|
|
728
|
31030
|
100
|
|
|
|
36150
|
if ( !$work_nook->[Marpa::R2::Internal::Nook::CAUSE_IS_EXPANDED] ) |
|
31030
|
|
|
|
|
52520
|
|
729
|
|
|
|
|
|
|
{ |
730
|
13592
|
100
|
|
|
|
21283
|
if ( not nook_has_semantic_cause( $asf, $work_nook ) ) { |
731
|
2664
|
|
|
|
|
5363
|
$child_or_node = |
732
|
|
|
|
|
|
|
$bocage->_marpa_b_and_node_cause($work_and_node_id); |
733
|
2664
|
|
|
|
|
3653
|
$child_is_cause = 1; |
734
|
2664
|
|
|
|
|
3706
|
last FIND_CHILD_OR_NODE; |
735
|
|
|
|
|
|
|
} ## end if ( not nook_has_semantic_cause( $asf, $work_nook )) |
736
|
|
|
|
|
|
|
} ## end if ( !$work_nook->[...]) |
737
|
28366
|
|
|
|
|
40991
|
$work_nook->[Marpa::R2::Internal::Nook::CAUSE_IS_EXPANDED] = 1; |
738
|
28366
|
100
|
|
|
|
46897
|
if ( !$work_nook |
739
|
|
|
|
|
|
|
->[Marpa::R2::Internal::Nook::PREDECESSOR_IS_EXPANDED] ) |
740
|
|
|
|
|
|
|
{ |
741
|
18794
|
|
|
|
|
34127
|
$child_or_node = |
742
|
|
|
|
|
|
|
$bocage->_marpa_b_and_node_predecessor($work_and_node_id); |
743
|
18794
|
100
|
|
|
|
32644
|
if ( defined $child_or_node ) { |
744
|
9562
|
|
|
|
|
12845
|
$child_is_predecessor = 1; |
745
|
9562
|
|
|
|
|
12904
|
last FIND_CHILD_OR_NODE; |
746
|
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
} ## end if ( !$work_nook->[...]) |
748
|
18804
|
|
|
|
|
23875
|
$work_nook->[Marpa::R2::Internal::Nook::PREDECESSOR_IS_EXPANDED] = |
749
|
|
|
|
|
|
|
1; |
750
|
18804
|
|
|
|
|
22240
|
pop @worklist; |
751
|
18804
|
|
|
|
|
37660
|
next DO_WORKLIST; |
752
|
|
|
|
|
|
|
} ## end FIND_CHILD_OR_NODE: |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
return 0 |
755
|
|
|
|
|
|
|
if |
756
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::OR_NODE_IN_USE] |
757
|
12226
|
50
|
|
|
|
24722
|
->{$child_or_node}; |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
return 0 |
760
|
12226
|
50
|
|
|
|
14852
|
if not scalar @{ $or_nodes->[$work_or_node] }; |
|
12226
|
|
|
|
|
22610
|
|
761
|
|
|
|
|
|
|
|
762
|
12226
|
|
|
|
|
20227
|
my $new_nook = |
763
|
|
|
|
|
|
|
nook_new( $asf, $child_or_node, $stack_ix_of_work_nook ); |
764
|
12226
|
100
|
|
|
|
20901
|
if ($child_is_cause) { |
765
|
2664
|
|
|
|
|
4268
|
$new_nook->[Marpa::R2::Internal::Nook::IS_CAUSE] = 1; |
766
|
2664
|
|
|
|
|
3976
|
$work_nook->[Marpa::R2::Internal::Nook::CAUSE_IS_EXPANDED] = 1; |
767
|
|
|
|
|
|
|
} |
768
|
12226
|
100
|
|
|
|
19378
|
if ($child_is_predecessor) { |
769
|
9562
|
|
|
|
|
15472
|
$new_nook->[Marpa::R2::Internal::Nook::IS_PREDECESSOR] = 1; |
770
|
9562
|
|
|
|
|
13194
|
$work_nook->[Marpa::R2::Internal::Nook::PREDECESSOR_IS_EXPANDED] = |
771
|
|
|
|
|
|
|
1; |
772
|
|
|
|
|
|
|
} |
773
|
12226
|
|
|
|
|
14705
|
push @{$factoring_stack}, $new_nook; |
|
12226
|
|
|
|
|
17571
|
|
774
|
12226
|
|
|
|
|
15697
|
push @worklist, $#{$factoring_stack}; |
|
12226
|
|
|
|
|
26472
|
|
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
} ## end DO_WORKLIST: while ( scalar @worklist ) |
777
|
|
|
|
|
|
|
|
778
|
1372
|
|
|
|
|
4083
|
return 1; |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
} ## end sub factoring_finish |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
sub and_nodes_to_cause_nids { |
783
|
10936
|
|
|
10936
|
|
19107
|
my ( $asf, @and_node_ids ) = @_; |
784
|
10936
|
|
|
|
|
14227
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
785
|
10936
|
|
|
|
|
13597
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
786
|
10936
|
|
|
|
|
13896
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
787
|
10936
|
|
|
|
|
14646
|
my %causes = (); |
788
|
10936
|
|
|
|
|
16245
|
for my $and_node_id (@and_node_ids) { |
789
|
10989
|
|
66
|
|
|
28920
|
my $cause_nid = $bocage->_marpa_b_and_node_cause($and_node_id) |
790
|
|
|
|
|
|
|
// and_node_to_nid($and_node_id); |
791
|
10989
|
|
|
|
|
24306
|
$causes{$cause_nid} = 1; |
792
|
|
|
|
|
|
|
} |
793
|
10936
|
|
|
|
|
32510
|
return [ keys %causes ]; |
794
|
|
|
|
|
|
|
} ## end sub and_nodes_to_cause_nids |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
sub glade_id_factors { |
797
|
1682
|
|
|
1682
|
|
2646
|
my ($choicepoint) = @_; |
798
|
1682
|
|
|
|
|
2436
|
my $asf = $choicepoint->[Marpa::R2::Internal::Choicepoint::ASF]; |
799
|
1682
|
|
|
|
|
2163
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
800
|
1682
|
|
|
|
|
2190
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
801
|
1682
|
|
|
|
|
2289
|
my $grammar = $recce->[Marpa::R2::Internal::Recognizer::GRAMMAR]; |
802
|
1682
|
|
|
|
|
2220
|
my $grammar_c = $grammar->[Marpa::R2::Internal::Grammar::C]; |
803
|
1682
|
|
|
|
|
2078
|
my $bocage = $recce->[Marpa::R2::Internal::Recognizer::B_C]; |
804
|
1682
|
|
|
|
|
2124
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES]; |
805
|
|
|
|
|
|
|
|
806
|
1682
|
|
|
|
|
2143
|
my @result; |
807
|
1682
|
|
|
|
|
2385
|
my $factoring_stack = |
808
|
|
|
|
|
|
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK]; |
809
|
1682
|
100
|
|
|
|
3938
|
return if not $factoring_stack; |
810
|
|
|
|
|
|
|
FACTOR: |
811
|
1372
|
|
|
|
|
2138
|
for ( |
812
|
|
|
|
|
|
|
my $factor_ix = 0; |
813
|
20176
|
|
|
|
|
38568
|
$factor_ix <= $#{$factoring_stack}; |
814
|
|
|
|
|
|
|
$factor_ix++ |
815
|
|
|
|
|
|
|
) |
816
|
|
|
|
|
|
|
{ |
817
|
18804
|
|
|
|
|
25428
|
my $nook = $factoring_stack->[$factor_ix]; |
818
|
18804
|
100
|
|
|
|
27513
|
next FACTOR if not nook_has_semantic_cause( $asf, $nook ); |
819
|
10936
|
|
|
|
|
16666
|
my $or_node = $nook->[Marpa::R2::Internal::Nook::OR_NODE]; |
820
|
10936
|
|
|
|
|
14878
|
my $and_nodes = $or_nodes->[$or_node]; |
821
|
|
|
|
|
|
|
my $cause_nids = and_nodes_to_cause_nids( |
822
|
|
|
|
|
|
|
$asf, |
823
|
10936
|
|
|
|
|
17977
|
map { $and_nodes->[$_] } ( |
|
10989
|
|
|
|
|
22259
|
|
824
|
|
|
|
|
|
|
$nook->[Marpa::R2::Internal::Nook::FIRST_CHOICE] |
825
|
|
|
|
|
|
|
.. $nook->[Marpa::R2::Internal::Nook::LAST_CHOICE] |
826
|
|
|
|
|
|
|
) |
827
|
|
|
|
|
|
|
); |
828
|
10936
|
|
|
|
|
15514
|
my $base_nidset = Marpa::R2::Nidset->obtain( $asf, @{$cause_nids} ); |
|
10936
|
|
|
|
|
21232
|
|
829
|
10936
|
|
|
|
|
19209
|
my $glade_id = $base_nidset->id(); |
830
|
|
|
|
|
|
|
|
831
|
10936
|
|
|
|
|
17845
|
$asf->[Marpa::R2::Internal::ASF::GLADES]->[$glade_id] |
832
|
|
|
|
|
|
|
->[Marpa::R2::Internal::Glade::REGISTERED] = 1; |
833
|
10936
|
|
|
|
|
24106
|
push @result, $glade_id; |
834
|
|
|
|
|
|
|
} ## end FACTOR: for ( my $factor_ix = 0; $factor_ix <= $#{...}) |
835
|
1372
|
|
|
|
|
4196
|
return \@result; |
836
|
|
|
|
|
|
|
} ## end sub glade_id_factors |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
sub glade_obtain { |
839
|
3893
|
|
|
3893
|
|
5751
|
my ( $asf, $glade_id ) = @_; |
840
|
|
|
|
|
|
|
|
841
|
3893
|
|
|
|
|
5580
|
my $factoring_max = $asf->[Marpa::R2::Internal::ASF::FACTORING_MAX]; |
842
|
|
|
|
|
|
|
|
843
|
3893
|
|
|
|
|
5035
|
my $glades = $asf->[Marpa::R2::Internal::ASF::GLADES]; |
844
|
3893
|
|
|
|
|
5238
|
my $glade = $glades->[$glade_id]; |
845
|
3893
|
50
|
33
|
|
|
11634
|
if ( not defined $glade |
846
|
|
|
|
|
|
|
or not $glade->[Marpa::R2::Internal::Glade::REGISTERED] ) |
847
|
|
|
|
|
|
|
{ |
848
|
0
|
|
|
|
|
0
|
say Data::Dumper::Dumper($glade); |
849
|
0
|
|
|
|
|
0
|
Marpa::R2::exception( |
850
|
|
|
|
|
|
|
"Attempt to use an invalid glade, one whose ID is $glade_id"); |
851
|
|
|
|
|
|
|
} ## end if ( not defined $glade or not $glade->[...]) |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
# Return the glade if it is already set up |
854
|
3893
|
100
|
|
|
|
8405
|
return $glade if $glade->[Marpa::R2::Internal::Glade::SYMCHES]; |
855
|
|
|
|
|
|
|
|
856
|
858
|
|
|
|
|
1246
|
my $base_nidset = |
857
|
|
|
|
|
|
|
$asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]->[$glade_id]; |
858
|
858
|
|
|
|
|
1247
|
my $choicepoint; |
859
|
|
|
|
|
|
|
my $choicepoint_powerset; |
860
|
|
|
|
|
|
|
{ |
861
|
858
|
|
|
|
|
1132
|
my @source_data = (); |
|
858
|
|
|
|
|
1231
|
|
862
|
858
|
|
|
|
|
1123
|
for my $source_nid ( @{ $base_nidset->nids() } ) { |
|
858
|
|
|
|
|
1764
|
|
863
|
900
|
|
|
|
|
1746
|
my $sort_ix = nid_sort_ix( $asf, $source_nid ); |
864
|
900
|
|
|
|
|
2622
|
push @source_data, [ $sort_ix, $source_nid ]; |
865
|
|
|
|
|
|
|
} |
866
|
858
|
|
|
|
|
1908
|
my @sorted_source_data = sort { $a->[0] <=> $b->[0] } @source_data; |
|
44
|
|
|
|
|
190
|
|
867
|
858
|
|
|
|
|
1211
|
my $nid_ix = 0; |
868
|
|
|
|
|
|
|
my ( $sort_ix_of_this_nid, $this_nid ) = |
869
|
858
|
|
|
|
|
1241
|
@{ $sorted_source_data[ $nid_ix++ ] }; |
|
858
|
|
|
|
|
1802
|
|
870
|
858
|
|
|
|
|
1170
|
my @nids_with_current_sort_ix = (); |
871
|
858
|
|
|
|
|
1257
|
my $current_sort_ix = $sort_ix_of_this_nid; |
872
|
858
|
|
|
|
|
1161
|
my @symch_ids = (); |
873
|
858
|
|
|
|
|
1093
|
NID: while (1) { |
874
|
|
|
|
|
|
|
|
875
|
1758
|
100
|
|
|
|
3348
|
if ( $sort_ix_of_this_nid != $current_sort_ix ) { |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
# Currently only whole id break logic |
878
|
875
|
|
|
|
|
1908
|
my $nidset_for_sort_ix = Marpa::R2::Nidset->obtain( $asf, |
879
|
|
|
|
|
|
|
@nids_with_current_sort_ix ); |
880
|
875
|
|
|
|
|
1910
|
push @symch_ids, $nidset_for_sort_ix->id(); |
881
|
875
|
|
|
|
|
1378
|
@nids_with_current_sort_ix = (); |
882
|
875
|
|
|
|
|
1281
|
$current_sort_ix = $sort_ix_of_this_nid; |
883
|
|
|
|
|
|
|
} ## end if ( $sort_ix_of_this_nid != $current_sort_ix ) |
884
|
1758
|
100
|
|
|
|
3717
|
last NID if not defined $this_nid; |
885
|
900
|
|
|
|
|
1331
|
push @nids_with_current_sort_ix, $this_nid; |
886
|
900
|
|
|
|
|
1298
|
my $sorted_entry = $sorted_source_data[ $nid_ix++ ]; |
887
|
900
|
100
|
|
|
|
1596
|
if ( defined $sorted_entry ) { |
888
|
42
|
|
|
|
|
88
|
( $sort_ix_of_this_nid, $this_nid ) = @{$sorted_entry}; |
|
42
|
|
|
|
|
91
|
|
889
|
42
|
|
|
|
|
117
|
next NID; |
890
|
|
|
|
|
|
|
} |
891
|
858
|
|
|
|
|
1246
|
$this_nid = undef; |
892
|
858
|
|
|
|
|
1189
|
$sort_ix_of_this_nid = -2; |
893
|
|
|
|
|
|
|
} ## end NID: while (1) |
894
|
858
|
|
|
|
|
2044
|
$choicepoint_powerset = Marpa::R2::Powerset->obtain( $asf, @symch_ids ); |
895
|
858
|
|
|
|
|
1570
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::ASF] = $asf; |
896
|
858
|
|
|
|
|
1912
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK] = |
897
|
|
|
|
|
|
|
undef; |
898
|
|
|
|
|
|
|
} |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
# Check if choicepoint already seen? |
901
|
858
|
|
|
|
|
1201
|
my @symches = (); |
902
|
858
|
|
|
|
|
1709
|
my $symch_count = $choicepoint_powerset->count(); |
903
|
858
|
|
|
|
|
1878
|
SYMCH: for ( my $symch_ix = 0; $symch_ix < $symch_count; $symch_ix++ ) { |
904
|
875
|
|
|
|
|
1332
|
$choicepoint->[Marpa::R2::Internal::Choicepoint::FACTORING_STACK] = |
905
|
|
|
|
|
|
|
undef; |
906
|
875
|
|
|
|
|
1786
|
my $symch_nidset = $choicepoint_powerset->nidset($asf, $symch_ix); |
907
|
875
|
|
|
|
|
1686
|
my $choicepoint_nid = $symch_nidset->nid(0); |
908
|
875
|
|
100
|
|
|
1809
|
my $symch_rule_id = nid_rule_id($asf, $choicepoint_nid) // -1; |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
# Initial undef indicates no factorings omitted |
911
|
875
|
|
|
|
|
1778
|
my @factorings = ( $symch_rule_id, undef ); |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
# For a token |
914
|
|
|
|
|
|
|
# There will not be multiple factorings or nids, |
915
|
|
|
|
|
|
|
# it is assumed, for a token |
916
|
875
|
100
|
|
|
|
1636
|
if ( $symch_rule_id < 0 ) { |
917
|
590
|
|
|
|
|
1124
|
my $base_nidset = Marpa::R2::Nidset->obtain( $asf, $choicepoint_nid ); |
918
|
590
|
|
|
|
|
1076
|
my $glade_id = $base_nidset->id(); |
919
|
|
|
|
|
|
|
|
920
|
590
|
|
|
|
|
1039
|
$asf->[Marpa::R2::Internal::ASF::GLADES]->[$glade_id] |
921
|
|
|
|
|
|
|
->[Marpa::R2::Internal::Glade::REGISTERED] = 1; |
922
|
590
|
|
|
|
|
1150
|
push @factorings, [$glade_id]; |
923
|
590
|
|
|
|
|
1064
|
push @symches, \@factorings; |
924
|
590
|
|
|
|
|
1723
|
next SYMCH; |
925
|
|
|
|
|
|
|
} ## end if ( $symch_rule_id < 0 ) |
926
|
|
|
|
|
|
|
|
927
|
285
|
|
|
|
|
563
|
my $symch = $choicepoint_powerset->nidset($asf, $symch_ix); |
928
|
285
|
|
|
|
|
592
|
my $nid_count = $symch->count(); |
929
|
285
|
|
|
|
|
410
|
my $factorings_omitted; |
930
|
|
|
|
|
|
|
FACTORINGS_LOOP: |
931
|
285
|
|
|
|
|
616
|
for ( my $nid_ix = 0; $nid_ix < $nid_count; $nid_ix++ ) { |
932
|
310
|
|
|
|
|
573
|
$choicepoint_nid = $symch_nidset->nid($nid_ix); |
933
|
310
|
|
|
|
|
793
|
first_factoring($choicepoint, $choicepoint_nid); |
934
|
310
|
|
|
|
|
664
|
my $factoring = glade_id_factors($choicepoint); |
935
|
|
|
|
|
|
|
|
936
|
310
|
|
|
|
|
644
|
FACTOR: while ( defined $factoring ) { |
937
|
1372
|
50
|
|
|
|
2879
|
if ( scalar @factorings > $factoring_max ) { |
938
|
|
|
|
|
|
|
|
939
|
|
|
|
|
|
|
# update factorings omitted flag |
940
|
0
|
|
|
|
|
0
|
$factorings[1] = 1; |
941
|
0
|
|
|
|
|
0
|
last FACTORINGS_LOOP; |
942
|
|
|
|
|
|
|
} |
943
|
1372
|
|
|
|
|
2096
|
my @factoring = (); |
944
|
1372
|
|
|
|
|
1754
|
for ( |
945
|
1372
|
|
|
|
|
3027
|
my $item_ix = $#{$factoring}; |
946
|
|
|
|
|
|
|
$item_ix >= 0; |
947
|
|
|
|
|
|
|
$item_ix-- |
948
|
|
|
|
|
|
|
) |
949
|
|
|
|
|
|
|
{ |
950
|
10936
|
|
|
|
|
19761
|
push @factoring, $factoring->[$item_ix]; |
951
|
|
|
|
|
|
|
} ## end for ( my $item_ix = $#{$factoring}; $item_ix >= 0; ...) |
952
|
1372
|
|
|
|
|
2327
|
push @factorings, \@factoring; |
953
|
1372
|
|
|
|
|
3176
|
next_factoring($choicepoint, $choicepoint_nid); |
954
|
1372
|
|
|
|
|
2531
|
$factoring = glade_id_factors($choicepoint); |
955
|
|
|
|
|
|
|
} ## end FACTOR: while ( defined $factoring ) |
956
|
|
|
|
|
|
|
} ## end FACTORINGS_LOOP: for ( my $nid_ix = 0; $nid_ix < $nid_count; $nid_ix...) |
957
|
285
|
|
|
|
|
918
|
push @symches, \@factorings; |
958
|
|
|
|
|
|
|
} ## end SYMCH: for ( my $symch_ix = 0; $symch_ix < $symch_count; ...) |
959
|
|
|
|
|
|
|
|
960
|
858
|
|
|
|
|
1626
|
$glade->[Marpa::R2::Internal::Glade::SYMCHES] = \@symches; |
961
|
|
|
|
|
|
|
|
962
|
858
|
|
|
|
|
1358
|
$glade->[Marpa::R2::Internal::Glade::ID] = $glade_id; |
963
|
858
|
|
|
|
|
1217
|
$asf->[Marpa::R2::Internal::ASF::GLADES]->[$glade_id] = $glade; |
964
|
858
|
|
|
|
|
2229
|
return $glade; |
965
|
|
|
|
|
|
|
} ## end sub glade_obtain |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
sub Marpa::R2::ASF::glade_symch_count { |
968
|
829
|
|
|
829
|
0
|
1369
|
my ( $asf, $glade_id ) = @_; |
969
|
829
|
|
|
|
|
1494
|
my $glade = glade_obtain( $asf, $glade_id ); |
970
|
829
|
50
|
|
|
|
1600
|
Marpa::R2::exception("No glade found for glade ID $glade_id)") if not defined $glade; |
971
|
829
|
|
|
|
|
1048
|
return scalar @{ $glade->[Marpa::R2::Internal::Glade::SYMCHES] }; |
|
829
|
|
|
|
|
1819
|
|
972
|
|
|
|
|
|
|
} |
973
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
sub Marpa::R2::ASF::glade_literal { |
975
|
1805
|
|
|
1805
|
0
|
2714
|
my ( $asf, $glade_id ) = @_; |
976
|
1805
|
|
|
|
|
2834
|
my $nidset_by_id = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
977
|
1805
|
|
|
|
|
2473
|
my $nidset = $nidset_by_id->[$glade_id]; |
978
|
1805
|
50
|
|
|
|
3384
|
Marpa::R2::exception("No glade found for glade ID $glade_id)") if not defined $nidset; |
979
|
1805
|
|
|
|
|
3671
|
my $nid0 = $nidset->nid(0); |
980
|
1805
|
|
|
|
|
3547
|
return nid_literal($asf, $nid0); |
981
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::glade_literal |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
sub Marpa::R2::ASF::glade_span { |
984
|
95
|
|
|
95
|
0
|
165
|
my ( $asf, $glade_id ) = @_; |
985
|
95
|
|
|
|
|
138
|
my $nidset_by_id = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
986
|
95
|
|
|
|
|
129
|
my $nidset = $nidset_by_id->[$glade_id]; |
987
|
95
|
50
|
|
|
|
177
|
Marpa::R2::exception("No glade found for glade ID $glade_id)") if not defined $nidset; |
988
|
95
|
|
|
|
|
170
|
my $nid0 = $nidset->nid(0); |
989
|
95
|
|
|
|
|
202
|
return nid_span($asf, $nid0); |
990
|
|
|
|
|
|
|
} |
991
|
|
|
|
|
|
|
|
992
|
|
|
|
|
|
|
sub Marpa::R2::ASF::glade_symbol_id { |
993
|
178
|
|
|
178
|
0
|
349
|
my ( $asf, $glade_id ) = @_; |
994
|
178
|
|
|
|
|
270
|
my $nidset_by_id = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
995
|
178
|
|
|
|
|
257
|
my $nidset = $nidset_by_id->[$glade_id]; |
996
|
178
|
50
|
|
|
|
383
|
Marpa::R2::exception("No glade found for glade ID $glade_id)") if not defined $nidset; |
997
|
178
|
|
|
|
|
347
|
my $nid0 = $nidset->nid(0); |
998
|
178
|
|
|
|
|
448
|
return nid_symbol_id($asf, $nid0); |
999
|
|
|
|
|
|
|
} |
1000
|
|
|
|
|
|
|
|
1001
|
|
|
|
|
|
|
sub Marpa::R2::ASF::symch_rule_id { |
1002
|
170
|
|
|
170
|
0
|
468
|
my ( $asf, $glade_id, $symch_ix ) = @_; |
1003
|
170
|
|
|
|
|
317
|
my $glade = glade_obtain( $asf, $glade_id ); |
1004
|
170
|
|
|
|
|
276
|
my $symches = $glade->[Marpa::R2::Internal::Glade::SYMCHES]; |
1005
|
170
|
50
|
|
|
|
241
|
return if $symch_ix > $#{$symches}; |
|
170
|
|
|
|
|
375
|
|
1006
|
170
|
|
|
|
|
268
|
my ($rule_id) = @{ $symches->[$symch_ix] }; |
|
170
|
|
|
|
|
317
|
|
1007
|
170
|
|
|
|
|
350
|
return $rule_id; |
1008
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::symch_rule_id |
1009
|
|
|
|
|
|
|
|
1010
|
|
|
|
|
|
|
sub Marpa::R2::ASF::symch_factoring_count { |
1011
|
1819
|
|
|
1819
|
0
|
3079
|
my ( $asf, $glade_id, $symch_ix ) = @_; |
1012
|
1819
|
|
|
|
|
3286
|
my $glade = glade_obtain( $asf, $glade_id ); |
1013
|
1819
|
50
|
|
|
|
3573
|
Marpa::R2::exception("No glade found for glade ID $glade_id)") if not defined $glade; |
1014
|
1819
|
|
|
|
|
2545
|
my $symches = $glade->[Marpa::R2::Internal::Glade::SYMCHES]; |
1015
|
1819
|
50
|
|
|
|
2446
|
return if $symch_ix > $#{$symches}; |
|
1819
|
|
|
|
|
3716
|
|
1016
|
1819
|
|
|
|
|
2285
|
return $#{ $symches->[$symch_ix] } - 1; # length minus 2 |
|
1819
|
|
|
|
|
3741
|
|
1017
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::symch_factoring_count |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
sub Marpa::R2::ASF::factoring_downglades { |
1020
|
290
|
|
|
290
|
0
|
593
|
my ( $asf, $glade_id, $symch_ix, $factoring_ix ) = @_; |
1021
|
290
|
|
|
|
|
499
|
my $glade = glade_obtain( $asf, $glade_id ); |
1022
|
290
|
50
|
|
|
|
552
|
Marpa::R2::exception("No glade found for glade ID $glade_id)") if not defined $glade; |
1023
|
290
|
|
|
|
|
389
|
my $symches = $glade->[Marpa::R2::Internal::Glade::SYMCHES]; |
1024
|
|
|
|
|
|
|
Marpa::R2::exception("No symch #$symch_ix exists for glade ID $glade_id") |
1025
|
290
|
50
|
|
|
|
417
|
if $symch_ix > $#{$symches}; |
|
290
|
|
|
|
|
533
|
|
1026
|
290
|
|
|
|
|
439
|
my $symch = $symches->[$symch_ix]; |
1027
|
290
|
|
|
|
|
369
|
my ( $rule_id, undef, @factorings ) = @{$symch}; |
|
290
|
|
|
|
|
544
|
|
1028
|
290
|
50
|
|
|
|
594
|
Marpa::R2::exception("No downglades for glade ID $glade_id, symch #$symch_ix: it is a token symch") |
1029
|
|
|
|
|
|
|
if $rule_id < 0; |
1030
|
290
|
50
|
|
|
|
539
|
return if $factoring_ix >= scalar @factorings; |
1031
|
290
|
|
|
|
|
400
|
my $factoring = $factorings[$factoring_ix]; |
1032
|
290
|
|
|
|
|
526
|
return $factoring; |
1033
|
|
|
|
|
|
|
} |
1034
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
sub Marpa::R2::ASF::factoring_symbol_count { |
1036
|
85
|
|
|
85
|
0
|
162
|
my ( $asf, $glade_id, $symch_ix, $factoring_ix ) = @_; |
1037
|
85
|
|
|
|
|
168
|
my $factoring = $asf->factoring_downglades($glade_id, $symch_ix, $factoring_ix); |
1038
|
85
|
50
|
|
|
|
157
|
return if not defined $factoring; |
1039
|
85
|
|
|
|
|
105
|
return scalar @{$factoring}; |
|
85
|
|
|
|
|
138
|
|
1040
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::factoring_symbol_count |
1041
|
|
|
|
|
|
|
|
1042
|
|
|
|
|
|
|
sub Marpa::R2::ASF::factor_downglade { |
1043
|
152
|
|
|
152
|
0
|
288
|
my ( $asf, $glade_id, $symch_ix, $factoring_ix, $symbol_ix ) = @_; |
1044
|
152
|
|
|
|
|
261
|
my $factoring = $asf->factoring_downglades($glade_id, $symch_ix, $factoring_ix); |
1045
|
152
|
50
|
|
|
|
273
|
return if not defined $factoring; |
1046
|
152
|
|
|
|
|
255
|
return $factoring->[$symbol_ix]; |
1047
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::factor_downglade |
1048
|
|
|
|
|
|
|
|
1049
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::ambiguities { |
1050
|
8
|
|
|
8
|
|
44
|
my ($asf) = @_; |
1051
|
8
|
|
|
|
|
40
|
my $peak = $asf->peak(); |
1052
|
8
|
|
|
|
|
34
|
return Marpa::R2::Internal::ASF::glade_ambiguities( $asf, $peak, [] ); |
1053
|
|
|
|
|
|
|
} |
1054
|
|
|
|
|
|
|
|
1055
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::glade_ambiguities { |
1056
|
28
|
|
|
28
|
|
59
|
my ( $asf, $glade, $seen ) = @_; |
1057
|
28
|
50
|
|
|
|
62
|
return [] if $seen->[$glade]; # empty on revisit |
1058
|
28
|
|
|
|
|
47
|
$seen->[$glade] = 1; |
1059
|
28
|
|
|
|
|
93
|
my $grammar = $asf->grammar(); |
1060
|
28
|
|
|
|
|
74
|
my $symch_count = $asf->glade_symch_count($glade); |
1061
|
28
|
100
|
|
|
|
78
|
if ( $symch_count > 1 ) { |
1062
|
4
|
|
|
|
|
22
|
my $literal = $asf->glade_literal($glade); |
1063
|
4
|
|
|
|
|
19
|
my $symbol_id = $asf->glade_symbol_id($glade); |
1064
|
4
|
|
|
|
|
29
|
my $display_form = $grammar->symbol_display_form($symbol_id); |
1065
|
4
|
|
|
|
|
28
|
return [ [ 'symch', $glade, ] ]; |
1066
|
|
|
|
|
|
|
} ## end if ( $symch_count > 1 ) |
1067
|
24
|
|
|
|
|
76
|
my $rule_id = $asf->symch_rule_id( $glade, 0 ); |
1068
|
24
|
100
|
|
|
|
63
|
return [] if $rule_id < 0; # no ambiguities if a token |
1069
|
|
|
|
|
|
|
|
1070
|
|
|
|
|
|
|
# ignore any truncation of the factorings |
1071
|
|
|
|
|
|
|
|
1072
|
19
|
|
|
|
|
53
|
my $factoring_count = $asf->symch_factoring_count( $glade, 0 ); |
1073
|
19
|
100
|
|
|
|
49
|
if ( $factoring_count <= 1 ) { |
1074
|
15
|
|
|
|
|
56
|
my $downglades = $asf->factoring_downglades( $glade, 0, 0 ); |
1075
|
|
|
|
|
|
|
my @problems = |
1076
|
15
|
|
|
|
|
44
|
map { @{ glade_ambiguities( $asf, $_, $seen ) } } @{$downglades}; |
|
19
|
|
|
|
|
27
|
|
|
19
|
|
|
|
|
162
|
|
|
15
|
|
|
|
|
35
|
|
1077
|
15
|
|
|
|
|
71
|
return \@problems; |
1078
|
|
|
|
|
|
|
} ## end if ( $factoring_count <= 1 ) |
1079
|
4
|
|
|
|
|
23
|
my @results = (); |
1080
|
|
|
|
|
|
|
|
1081
|
4
|
|
|
|
|
15
|
my $downglades = $asf->factoring_downglades( $glade, 0, 0 ); |
1082
|
4
|
|
|
|
|
8
|
my $min_factors = $#{$downglades} + 1; |
|
4
|
|
|
|
|
19
|
|
1083
|
4
|
|
|
|
|
19
|
my ( $upglade_start, $upglade_length ) = $asf->glade_span($glade); |
1084
|
4
|
|
|
|
|
9
|
my $sync_location = $upglade_start + $upglade_length; |
1085
|
|
|
|
|
|
|
|
1086
|
4
|
|
|
|
|
11
|
my @factors_by_factoring = ($downglades); |
1087
|
4
|
|
|
|
|
20
|
for ( |
1088
|
|
|
|
|
|
|
my $factoring_ix = 1; |
1089
|
|
|
|
|
|
|
$factoring_ix < $factoring_count; |
1090
|
|
|
|
|
|
|
$factoring_ix++ |
1091
|
|
|
|
|
|
|
) |
1092
|
|
|
|
|
|
|
{ |
1093
|
12
|
|
|
|
|
38
|
my $downglades = |
1094
|
|
|
|
|
|
|
$asf->factoring_downglades( $glade, 0, $factoring_ix ); |
1095
|
12
|
|
|
|
|
17
|
my $factor_count = $#{$downglades} + 1; |
|
12
|
|
|
|
|
34
|
|
1096
|
12
|
100
|
|
|
|
29
|
$min_factors = |
1097
|
|
|
|
|
|
|
$min_factors > $factor_count ? $factor_count : $min_factors; |
1098
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
# Determine a first potential |
1100
|
|
|
|
|
|
|
# "sync location of the factors" from |
1101
|
|
|
|
|
|
|
# the earliest start of the first downglade of any factoring. |
1102
|
|
|
|
|
|
|
# Currently this will be the start of the parent glade, but this |
1103
|
|
|
|
|
|
|
# method will be safe against any future hacks. |
1104
|
12
|
|
|
|
|
34
|
my ($this_sync_location) = $asf->glade_span( $downglades->[0] ); |
1105
|
12
|
|
|
|
|
51
|
$sync_location = |
1106
|
|
|
|
|
|
|
List::Util::min( $this_sync_location, $sync_location ); |
1107
|
|
|
|
|
|
|
|
1108
|
12
|
|
|
|
|
37
|
push @factors_by_factoring, $downglades; |
1109
|
|
|
|
|
|
|
} ## end for ( my $factoring_ix = 1; $factoring_ix < $factoring_count...) |
1110
|
|
|
|
|
|
|
|
1111
|
4
|
|
|
|
|
15
|
my @factor_ix = (0) x $factoring_count; |
1112
|
4
|
|
|
|
|
9
|
SYNC_PASS: while (1) { |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
# Assume synced and unambiguous until we see otherwise. |
1115
|
14
|
|
|
|
|
30
|
my $is_synced = 1; |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
# First find a synch'ed set of factors, if we can |
1118
|
|
|
|
|
|
|
FACTORING: |
1119
|
14
|
|
|
|
|
35
|
for ( |
1120
|
|
|
|
|
|
|
my $factoring_ix = 0; |
1121
|
|
|
|
|
|
|
$factoring_ix < $factoring_count; |
1122
|
|
|
|
|
|
|
$factoring_ix++ |
1123
|
|
|
|
|
|
|
) |
1124
|
|
|
|
|
|
|
{ |
1125
|
43
|
|
|
|
|
63
|
my $this_factor_ix = $factor_ix[$factoring_ix]; |
1126
|
43
|
|
|
|
|
61
|
my $this_downglade = |
1127
|
|
|
|
|
|
|
$factors_by_factoring[$factoring_ix][$this_factor_ix]; |
1128
|
43
|
|
|
|
|
79
|
my ($this_start) = $asf->glade_span($this_downglade); |
1129
|
|
|
|
|
|
|
|
1130
|
|
|
|
|
|
|
# To keep time complexity down we limit the number of times we deal |
1131
|
|
|
|
|
|
|
# with a factoring at a sync location to 3, worst case -- a pass which |
1132
|
|
|
|
|
|
|
# identifies it as a potential sync location, a pass which |
1133
|
|
|
|
|
|
|
# (if possible) brings all the factors to that location, and a |
1134
|
|
|
|
|
|
|
# pass which leaves all factor IX's where they are, and determines |
1135
|
|
|
|
|
|
|
# we have found a sync location. This makes out time O(f*n), where |
1136
|
|
|
|
|
|
|
# f is the factoring count and n is the mininum number of factors. |
1137
|
|
|
|
|
|
|
|
1138
|
43
|
|
|
|
|
102
|
while ( $this_start < $sync_location ) { |
1139
|
11
|
|
|
|
|
29
|
$factor_ix[$factoring_ix]++; |
1140
|
11
|
100
|
|
|
|
34
|
last SYNC_PASS if $factor_ix[$factoring_ix] >= $min_factors; |
1141
|
7
|
|
|
|
|
16
|
$this_start = $asf->glade_span($this_downglade); |
1142
|
|
|
|
|
|
|
} ## end if ( $this_start < $sync_location ) |
1143
|
39
|
100
|
|
|
|
103
|
if ( $this_start > $sync_location ) { |
1144
|
7
|
|
|
|
|
17
|
$is_synced = 0; |
1145
|
7
|
|
|
|
|
29
|
$sync_location = $this_start; |
1146
|
|
|
|
|
|
|
} |
1147
|
|
|
|
|
|
|
} ## end FACTORING: for ( my $factoring_ix = 0; $factoring_ix < ...) |
1148
|
|
|
|
|
|
|
|
1149
|
10
|
100
|
|
|
|
40
|
next SYNC_PASS if not $is_synced; |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
# If here, every factor starts at the sync location |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
SYNCED_RESULT: { |
1154
|
|
|
|
|
|
|
|
1155
|
6
|
|
|
|
|
12
|
my $ambiguous_factors; |
|
6
|
|
|
|
|
10
|
|
1156
|
6
|
|
|
|
|
9
|
my $first_factor_ix = $factor_ix[0]; |
1157
|
6
|
|
|
|
|
12
|
my $first_downglade = $factors_by_factoring[0][$first_factor_ix]; |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
FACTORING: |
1160
|
6
|
|
|
|
|
19
|
for ( |
1161
|
|
|
|
|
|
|
my $factoring_ix = 1; |
1162
|
|
|
|
|
|
|
$factoring_ix < $factoring_count; |
1163
|
|
|
|
|
|
|
$factoring_ix++ |
1164
|
|
|
|
|
|
|
) |
1165
|
|
|
|
|
|
|
{ |
1166
|
8
|
|
|
|
|
21
|
my $this_factor_ix = $factor_ix[$factoring_ix]; |
1167
|
8
|
|
|
|
|
19
|
my $this_downglade = |
1168
|
|
|
|
|
|
|
$factors_by_factoring[$factoring_ix][$this_factor_ix]; |
1169
|
8
|
100
|
|
|
|
37
|
if ( $this_downglade != $first_downglade ) { |
1170
|
5
|
|
|
|
|
19
|
$ambiguous_factors = [ |
1171
|
|
|
|
|
|
|
$first_factor_ix, $factoring_ix, |
1172
|
|
|
|
|
|
|
$this_factor_ix |
1173
|
|
|
|
|
|
|
]; |
1174
|
5
|
|
|
|
|
11
|
last FACTORING; |
1175
|
|
|
|
|
|
|
} ## end if ( $this_downglade != $first_downglade ) |
1176
|
|
|
|
|
|
|
|
1177
|
|
|
|
|
|
|
} ## end FACTORING: for ( my $factoring_ix = 1; $factoring_ix < ...) |
1178
|
|
|
|
|
|
|
|
1179
|
|
|
|
|
|
|
# If here, all the the downglades are identical |
1180
|
6
|
100
|
|
|
|
19
|
if ( not defined $ambiguous_factors ) { |
1181
|
|
|
|
|
|
|
push @results, |
1182
|
1
|
|
|
|
|
4
|
@{ glade_ambiguities( $asf, $first_downglade, $seen ) }; |
|
1
|
|
|
|
|
11
|
|
1183
|
1
|
|
|
|
|
16
|
last SYNCED_RESULT; |
1184
|
|
|
|
|
|
|
} |
1185
|
|
|
|
|
|
|
|
1186
|
|
|
|
|
|
|
# First factoring IX is always zero |
1187
|
|
|
|
|
|
|
push @results, |
1188
|
5
|
|
|
|
|
23
|
[ 'factoring', $glade, 0, @{$ambiguous_factors} ]; |
|
5
|
|
|
|
|
16
|
|
1189
|
|
|
|
|
|
|
} ## end SYNCED_RESULT: |
1190
|
|
|
|
|
|
|
|
1191
|
6
|
|
|
|
|
39
|
$factor_ix[$_]++ for 0 .. $factoring_count; |
1192
|
6
|
50
|
|
|
|
34
|
last SYNC_PASS if List::Util::max(@factor_ix) >= $min_factors; |
1193
|
|
|
|
|
|
|
|
1194
|
|
|
|
|
|
|
} ## end SYNC_PASS: while (1) |
1195
|
|
|
|
|
|
|
|
1196
|
4
|
|
|
|
|
30
|
return \@results; |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::glade_ambiguities |
1199
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
# A generic display routine for ambiguities -- complex application will |
1201
|
|
|
|
|
|
|
# want to replace this, using it perhaps as a fallback. |
1202
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::ambiguities_show { |
1203
|
8
|
|
|
8
|
|
73
|
my ( $asf, $ambiguities ) = @_; |
1204
|
8
|
|
|
|
|
27
|
my $grammar = $asf->grammar(); |
1205
|
8
|
|
|
|
|
24
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
1206
|
8
|
|
|
|
|
29
|
my $p_input = $slr->[Marpa::R2::Internal::Scanless::R::P_INPUT_STRING]; |
1207
|
8
|
|
|
|
|
21
|
my $result = q{}; |
1208
|
8
|
|
|
|
|
15
|
AMBIGUITY: for my $ambiguity ( @{$ambiguities} ) { |
|
8
|
|
|
|
|
23
|
|
1209
|
9
|
|
|
|
|
25
|
my $type = $ambiguity->[0]; |
1210
|
9
|
100
|
|
|
|
34
|
if ( $type eq 'symch' ) { |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
# Not tested !!!! |
1213
|
4
|
|
|
|
|
7
|
my ( undef, $glade ) = @{$ambiguity}; |
|
4
|
|
|
|
|
8
|
|
1214
|
4
|
|
|
|
|
10
|
my $symbol_display_form = |
1215
|
|
|
|
|
|
|
$grammar->symbol_display_form( |
1216
|
|
|
|
|
|
|
$asf->glade_symbol_id($glade) ); |
1217
|
4
|
|
|
|
|
38
|
my ( $start, $length ) = $asf->glade_span($glade); |
1218
|
4
|
|
|
|
|
25
|
my ( $start_line, $start_column ) = $slr->line_column($start); |
1219
|
4
|
|
|
|
|
19
|
my ( $end_line, $end_column ) = |
1220
|
|
|
|
|
|
|
$slr->line_column( $start + $length - 1 ); |
1221
|
4
|
|
|
|
|
27
|
my $display_length = List::Util::min( $length, 60 ); |
1222
|
4
|
|
|
|
|
20
|
$result |
1223
|
|
|
|
|
|
|
.= qq{Ambiguous symch at Glade=$glade, Symbol=<$symbol_display_form>:\n}; |
1224
|
4
|
|
|
|
|
24
|
$result |
1225
|
|
|
|
|
|
|
.= qq{ The ambiguity is from line $start_line, column $start_column } |
1226
|
|
|
|
|
|
|
. qq{to line $end_line, column $end_column\n}; |
1227
|
4
|
50
|
|
|
|
13
|
my $literal_label = |
1228
|
|
|
|
|
|
|
$display_length == $length ? 'Text is: ' : 'Text begins: '; |
1229
|
4
|
|
|
|
|
18
|
$result |
1230
|
|
|
|
|
|
|
.= q{ } |
1231
|
|
|
|
|
|
|
. $literal_label |
1232
|
|
|
|
|
|
|
. Marpa::R2::Internal::Scanless::input_escape( $p_input, |
1233
|
|
|
|
|
|
|
$start, $display_length ) |
1234
|
|
|
|
|
|
|
. qq{\n}; |
1235
|
|
|
|
|
|
|
|
1236
|
4
|
|
|
|
|
15
|
my $symch_count = $asf->glade_symch_count($glade); |
1237
|
4
|
|
|
|
|
29
|
my $display_symch_count = List::Util::min( 5, $symch_count ); |
1238
|
4
|
50
|
|
|
|
30
|
$result .= |
1239
|
|
|
|
|
|
|
$symch_count == $display_symch_count |
1240
|
|
|
|
|
|
|
? " There are $symch_count symches\n" |
1241
|
|
|
|
|
|
|
: " There are $symch_count symches -- showing only the first $display_symch_count\n"; |
1242
|
4
|
|
|
|
|
17
|
SYMCH_IX: for my $symch_ix ( 0 .. $display_symch_count - 1 ) { |
1243
|
8
|
|
|
|
|
24
|
my $rule_id = $asf->symch_rule_id( $glade, $symch_ix ); |
1244
|
8
|
50
|
|
|
|
35
|
if ( $rule_id < 0 ) { |
1245
|
0
|
|
|
|
|
0
|
$result .= " Symch $symch_ix is a token\n"; |
1246
|
0
|
|
|
|
|
0
|
next SYMCH_IX; |
1247
|
|
|
|
|
|
|
} |
1248
|
8
|
|
|
|
|
51
|
$result .= " Symch $symch_ix is a rule: " |
1249
|
|
|
|
|
|
|
. $grammar->rule_show($rule_id) . "\n"; |
1250
|
|
|
|
|
|
|
} ## end SYMCH_IX: for my $symch_ix ( 0 .. $display_symch_count - 1 ) |
1251
|
|
|
|
|
|
|
|
1252
|
4
|
|
|
|
|
15
|
next AMBIGUITY; |
1253
|
|
|
|
|
|
|
} ## end if ( $type eq 'symch' ) |
1254
|
5
|
50
|
|
|
|
35
|
if ( $type eq 'factoring' ) { |
1255
|
5
|
|
|
|
|
12
|
my $factoring_ix1 = 0; |
1256
|
|
|
|
|
|
|
my ( undef, $glade, $symch_ix, $factor_ix1, $factoring_ix2, |
1257
|
|
|
|
|
|
|
$factor_ix2 ) |
1258
|
5
|
|
|
|
|
9
|
= @{$ambiguity}; |
|
5
|
|
|
|
|
10
|
|
1259
|
5
|
|
|
|
|
16
|
my $first_downglades = |
1260
|
|
|
|
|
|
|
$asf->factoring_downglades( $glade, $symch_ix, 0 ); |
1261
|
5
|
|
|
|
|
17
|
my $first_downglade = $first_downglades->[$factor_ix1]; |
1262
|
|
|
|
|
|
|
{ |
1263
|
5
|
|
|
|
|
7
|
my $these_downglades = |
|
5
|
|
|
|
|
17
|
|
1264
|
|
|
|
|
|
|
$asf->factoring_downglades( $glade, $symch_ix, |
1265
|
|
|
|
|
|
|
$factoring_ix2 ); |
1266
|
5
|
|
|
|
|
26
|
my $this_downglade = $these_downglades->[$factor_ix2]; |
1267
|
5
|
|
|
|
|
45
|
my $symbol_display_form = |
1268
|
|
|
|
|
|
|
$grammar->symbol_display_form( |
1269
|
|
|
|
|
|
|
$asf->glade_symbol_id($first_downglade) ); |
1270
|
5
|
|
|
|
|
25
|
my ( $start, $first_length ) = |
1271
|
|
|
|
|
|
|
$asf->glade_span($first_downglade); |
1272
|
5
|
|
|
|
|
15
|
my ( undef, $this_length ) = |
1273
|
|
|
|
|
|
|
$asf->glade_span($this_downglade); |
1274
|
5
|
|
|
|
|
40
|
my ( $start_line, $start_column ) = $slr->line_column($start); |
1275
|
5
|
|
|
|
|
23
|
my $display_length = |
1276
|
|
|
|
|
|
|
List::Util::min( $first_length, $this_length, 60 ); |
1277
|
5
|
|
|
|
|
29
|
$result |
1278
|
|
|
|
|
|
|
.= qq{Length of symbol "$symbol_display_form" at line $start_line, column $start_column is ambiguous\n}; |
1279
|
|
|
|
|
|
|
|
1280
|
5
|
100
|
|
|
|
22
|
if ( $display_length > 0 ) { |
1281
|
1
|
|
|
|
|
10
|
$result .= qq{ Choices start with: } |
1282
|
|
|
|
|
|
|
. Marpa::R2::Internal::Scanless::input_escape( |
1283
|
|
|
|
|
|
|
$p_input, $start, $display_length ) |
1284
|
|
|
|
|
|
|
. qq{\n}; |
1285
|
|
|
|
|
|
|
} ## end if ( $display_length > 0 ) |
1286
|
|
|
|
|
|
|
|
1287
|
5
|
|
|
|
|
13
|
my @display_downglade = ( $first_downglade, $this_downglade ); |
1288
|
|
|
|
|
|
|
DISPLAY_GLADE: |
1289
|
5
|
|
|
|
|
21
|
for ( |
1290
|
|
|
|
|
|
|
my $glade_ix = 0; |
1291
|
|
|
|
|
|
|
$glade_ix <= $#display_downglade; |
1292
|
|
|
|
|
|
|
$glade_ix++ |
1293
|
|
|
|
|
|
|
) |
1294
|
|
|
|
|
|
|
{ |
1295
|
|
|
|
|
|
|
# Choices may be zero length |
1296
|
10
|
|
|
|
|
18
|
my $choice_number = $glade_ix + 1; |
1297
|
10
|
|
|
|
|
19
|
my $glade_id = $display_downglade[$glade_ix]; |
1298
|
10
|
|
|
|
|
21
|
my ( undef, $length ) = $asf->glade_span($glade_id); |
1299
|
10
|
100
|
|
|
|
32
|
if ( $length <= 0 ) { |
1300
|
4
|
|
|
|
|
15
|
$result |
1301
|
|
|
|
|
|
|
.= qq{ Choice $choice_number is zero length\n}; |
1302
|
4
|
|
|
|
|
12
|
next DISPLAY_GLADE; |
1303
|
|
|
|
|
|
|
} |
1304
|
6
|
|
|
|
|
31
|
my ( $end_line, $end_column ) = |
1305
|
|
|
|
|
|
|
$slr->line_column( $start + $length - 1 ); |
1306
|
6
|
|
|
|
|
31
|
$result |
1307
|
|
|
|
|
|
|
.= qq{ Choice $choice_number, length=$length, ends at line $end_line, column $end_column\n}; |
1308
|
6
|
50
|
|
|
|
29
|
if ( $length > 60 ) { |
1309
|
0
|
|
|
|
|
0
|
$result .= qq{ Choice $choice_number ending: } |
1310
|
|
|
|
|
|
|
. Marpa::R2::Internal::Scanless::reversed_input_escape( |
1311
|
|
|
|
|
|
|
$p_input, $start + $length, 60 ) |
1312
|
|
|
|
|
|
|
. qq{\n}; |
1313
|
0
|
|
|
|
|
0
|
next DISPLAY_GLADE; |
1314
|
|
|
|
|
|
|
} ## end if ( $length > 60 ) |
1315
|
6
|
|
|
|
|
32
|
$result .= qq{ Choice $choice_number: } |
1316
|
|
|
|
|
|
|
. Marpa::R2::Internal::Scanless::input_escape( |
1317
|
|
|
|
|
|
|
$p_input, $start, $length ) |
1318
|
|
|
|
|
|
|
. qq{\n}; |
1319
|
|
|
|
|
|
|
|
1320
|
|
|
|
|
|
|
} ## end DISPLAY_GLADE: for ( my $glade_ix = 0; $glade_ix <= ...) |
1321
|
5
|
|
|
|
|
19
|
next AMBIGUITY; |
1322
|
|
|
|
|
|
|
} ## end FACTORING: for ( my $factoring_ix = 1; $factoring_ix < ...) |
1323
|
0
|
|
|
|
|
0
|
next AMBIGUITY; |
1324
|
|
|
|
|
|
|
} ## end if ( $type eq 'factoring' ) |
1325
|
|
|
|
|
|
|
$result |
1326
|
0
|
|
|
|
|
0
|
.= qq{Ambiguities of type "$type" not implemented:\n} |
1327
|
|
|
|
|
|
|
. Data::Dumper::dumper($ambiguity); |
1328
|
0
|
|
|
|
|
0
|
next AMBIGUITY; |
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
} ## end AMBIGUITY: for my $ambiguity ( @{$ambiguities} ) |
1331
|
8
|
|
|
|
|
359
|
return $result; |
1332
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::ambiguities_show |
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
# The higher level calls |
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
sub Marpa::R2::ASF::traverse { |
1337
|
31
|
|
|
31
|
1
|
1093
|
my ( $asf, $per_traverse_object, $method ) = @_; |
1338
|
31
|
50
|
|
|
|
111
|
if ( ref $method ne 'CODE' ) { |
1339
|
0
|
|
|
|
|
0
|
Marpa::R2::exception( |
1340
|
|
|
|
|
|
|
'Argument to $asf->traverse() must be an anonymous subroutine'); |
1341
|
|
|
|
|
|
|
} |
1342
|
31
|
50
|
|
|
|
81
|
if ( not ref $per_traverse_object ) { |
1343
|
0
|
|
|
|
|
0
|
Marpa::R2::exception( |
1344
|
|
|
|
|
|
|
'Argument to $asf->traverse() must be a reference'); |
1345
|
|
|
|
|
|
|
} |
1346
|
31
|
|
|
|
|
102
|
my $peak = $asf->peak(); |
1347
|
31
|
|
|
|
|
85
|
my $peak_glade = glade_obtain( $asf, $peak ); |
1348
|
31
|
|
|
|
|
133
|
my $traverser = bless [], "Marpa::R2::Internal::ASF::Traverse"; |
1349
|
31
|
|
|
|
|
84
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::ASF] = $asf; |
1350
|
31
|
|
|
|
|
73
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::CODE] = $method; |
1351
|
31
|
|
|
|
|
53
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::PER_TRAVERSE_OBJECT] = $per_traverse_object; |
1352
|
31
|
|
|
|
|
64
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::VALUES] = []; |
1353
|
31
|
|
|
|
|
64
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE] = $peak_glade; |
1354
|
31
|
|
|
|
|
62
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX] = 0; |
1355
|
31
|
|
|
|
|
57
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX] = 0; |
1356
|
31
|
|
|
|
|
114
|
return $method->( $traverser, $per_traverse_object ); |
1357
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::traverse |
1358
|
|
|
|
|
|
|
|
1359
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::all_choices { |
1360
|
12
|
|
|
12
|
|
103
|
my ( $traverser ) = @_; |
1361
|
|
|
|
|
|
|
|
1362
|
12
|
|
|
|
|
31
|
my @values = Marpa::R2::Internal::ASF::Traverse::rh_values( $traverser ); |
1363
|
12
|
|
|
|
|
23
|
my @results = ( [] ); |
1364
|
12
|
|
|
|
|
32
|
for my $rh_ix ( 0 .. @values - 1 ) { |
1365
|
24
|
|
|
|
|
33
|
my @new_results = (); |
1366
|
24
|
|
|
|
|
32
|
for my $old_result (@results) { |
1367
|
26
|
|
|
|
|
37
|
my $child_value = $values[$rh_ix]; |
1368
|
26
|
50
|
|
|
|
68
|
$child_value = [ $child_value ] unless ref $child_value eq 'ARRAY'; |
1369
|
26
|
|
|
|
|
34
|
for my $new_value ( @{ $child_value } ) { |
|
26
|
|
|
|
|
44
|
|
1370
|
30
|
|
|
|
|
33
|
push @new_results, [ @{$old_result}, $new_value ]; |
|
30
|
|
|
|
|
86
|
|
1371
|
|
|
|
|
|
|
} |
1372
|
|
|
|
|
|
|
} |
1373
|
24
|
|
|
|
|
55
|
@results = @new_results; |
1374
|
|
|
|
|
|
|
} ## end for my $rh_ix ( 0 .. $length - 1 ) |
1375
|
|
|
|
|
|
|
|
1376
|
12
|
|
|
|
|
30
|
return @results; |
1377
|
|
|
|
|
|
|
} |
1378
|
|
|
|
|
|
|
|
1379
|
|
|
|
|
|
|
|
1380
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::literal { |
1381
|
1742
|
|
|
1742
|
|
7617
|
my ( $traverser ) = @_; |
1382
|
1742
|
|
|
|
|
2702
|
my $asf = $traverser->[Marpa::R2::Internal::ASF::Traverse::ASF]; |
1383
|
1742
|
|
|
|
|
2407
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1384
|
1742
|
|
|
|
|
2385
|
my $glade_id = $glade->[Marpa::R2::Internal::Glade::ID]; |
1385
|
1742
|
|
|
|
|
3261
|
return $asf->glade_literal($glade_id); |
1386
|
|
|
|
|
|
|
} |
1387
|
|
|
|
|
|
|
|
1388
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::span { |
1389
|
4
|
|
|
4
|
|
35
|
my ( $traverser ) = @_; |
1390
|
4
|
|
|
|
|
6
|
my $asf = $traverser->[Marpa::R2::Internal::ASF::Traverse::ASF]; |
1391
|
4
|
|
|
|
|
8
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1392
|
4
|
|
|
|
|
5
|
my $glade_id = $glade->[Marpa::R2::Internal::Glade::ID]; |
1393
|
4
|
|
|
|
|
12
|
return $asf->glade_span($glade_id); |
1394
|
|
|
|
|
|
|
} |
1395
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::symbol_id { |
1397
|
103
|
|
|
103
|
|
320
|
my ( $traverser ) = @_; |
1398
|
103
|
|
|
|
|
148
|
my $asf = $traverser->[Marpa::R2::Internal::ASF::Traverse::ASF]; |
1399
|
103
|
|
|
|
|
131
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1400
|
103
|
|
|
|
|
141
|
my $glade_id = $glade->[Marpa::R2::Internal::Glade::ID]; |
1401
|
103
|
|
|
|
|
202
|
return $asf->glade_symbol_id($glade_id); |
1402
|
|
|
|
|
|
|
} |
1403
|
|
|
|
|
|
|
|
1404
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::rule_id { |
1405
|
1799
|
|
|
1799
|
|
8803
|
my ( $traverser ) = @_; |
1406
|
1799
|
|
|
|
|
2570
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1407
|
1799
|
|
|
|
|
2436
|
my $symch_ix = |
1408
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX]; |
1409
|
1799
|
|
|
|
|
2486
|
my $symch = $glade->[Marpa::R2::Internal::Glade::SYMCHES]->[$symch_ix]; |
1410
|
1799
|
|
|
|
|
2476
|
my ( $rule_id ) = @{$symch}; |
|
1799
|
|
|
|
|
2973
|
|
1411
|
1799
|
100
|
|
|
|
4209
|
return if $rule_id < 0; |
1412
|
1252
|
|
|
|
|
2127
|
return $rule_id; |
1413
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::Traverse::rule_id |
1414
|
|
|
|
|
|
|
|
1415
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::rh_length { |
1416
|
1249
|
|
|
1249
|
|
4148
|
my ( $traverser ) = @_; |
1417
|
1249
|
|
|
|
|
1780
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1418
|
1249
|
|
|
|
|
1690
|
my $symch_ix = |
1419
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX]; |
1420
|
1249
|
|
|
|
|
1803
|
my $symch = $glade->[Marpa::R2::Internal::Glade::SYMCHES]->[$symch_ix]; |
1421
|
1249
|
|
|
|
|
1548
|
my ( $rule_id, undef, @factorings ) = @{$symch}; |
|
1249
|
|
|
|
|
7980
|
|
1422
|
1249
|
50
|
|
|
|
2594
|
Marpa::R2::exception( |
1423
|
|
|
|
|
|
|
'$glade->rh_length($rh_ix) called for a token -- that is not allowed') |
1424
|
|
|
|
|
|
|
if $rule_id < 0; |
1425
|
1249
|
|
|
|
|
1848
|
my $factoring_ix = |
1426
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX]; |
1427
|
1249
|
|
|
|
|
1627
|
my $factoring = $factorings[$factoring_ix]; |
1428
|
1249
|
|
|
|
|
1583
|
return scalar @{$factoring}; |
|
1249
|
|
|
|
|
6936
|
|
1429
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::Traverse::rh_length |
1430
|
|
|
|
|
|
|
|
1431
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::rh_value { |
1432
|
10708
|
|
|
10708
|
|
26718
|
my ( $traverser, $rh_ix ) = @_; |
1433
|
10708
|
|
|
|
|
14391
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1434
|
10708
|
|
|
|
|
13094
|
my $symch_ix = |
1435
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX]; |
1436
|
10708
|
|
|
|
|
13830
|
my $symch = $glade->[Marpa::R2::Internal::Glade::SYMCHES]->[$symch_ix]; |
1437
|
10708
|
|
|
|
|
12805
|
my ( $rule_id, undef, @factorings ) = @{$symch}; |
|
10708
|
|
|
|
|
55323
|
|
1438
|
10708
|
50
|
|
|
|
19580
|
Marpa::R2::exception( |
1439
|
|
|
|
|
|
|
'$glade->rh_value($rh_ix) called for a token -- that is not allowed') |
1440
|
|
|
|
|
|
|
if $rule_id < 0; |
1441
|
10708
|
|
|
|
|
15383
|
my $factoring_ix = |
1442
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX]; |
1443
|
10708
|
|
|
|
|
13508
|
my $factoring = $factorings[$factoring_ix]; |
1444
|
10708
|
50
|
|
|
|
12774
|
return if $rh_ix > $#{$factoring}; |
|
10708
|
|
|
|
|
17525
|
|
1445
|
10708
|
|
|
|
|
16166
|
my $downglade_id = $factoring->[$rh_ix]; |
1446
|
10708
|
|
|
|
|
14268
|
my $memoized_value = $traverser->[Marpa::R2::Internal::ASF::Traverse::VALUES]->[$downglade_id]; |
1447
|
10708
|
100
|
|
|
|
57963
|
return $memoized_value if defined $memoized_value; |
1448
|
702
|
|
|
|
|
951
|
my $asf = $traverser->[Marpa::R2::Internal::ASF::Traverse::ASF]; |
1449
|
702
|
|
|
|
|
1204
|
my $downglade = glade_obtain( $asf, $downglade_id ); |
1450
|
702
|
|
|
|
|
1279
|
my $blessing = ref $traverser; |
1451
|
|
|
|
|
|
|
|
1452
|
|
|
|
|
|
|
# A shallow clone |
1453
|
702
|
|
|
|
|
925
|
my $child_traverser = bless [ @{$traverser} ], $blessing; |
|
702
|
|
|
|
|
1717
|
|
1454
|
702
|
|
|
|
|
1141
|
$child_traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE] = |
1455
|
|
|
|
|
|
|
$downglade; |
1456
|
702
|
|
|
|
|
947
|
$child_traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX] = 0; |
1457
|
702
|
|
|
|
|
912
|
$child_traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX] = 0; |
1458
|
702
|
|
|
|
|
966
|
my $code = $traverser->[Marpa::R2::Internal::ASF::Traverse::CODE]; |
1459
|
702
|
|
|
|
|
2127
|
my $value = $code->( |
1460
|
|
|
|
|
|
|
$child_traverser, |
1461
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::PER_TRAVERSE_OBJECT] |
1462
|
|
|
|
|
|
|
); |
1463
|
702
|
50
|
|
|
|
2973
|
Marpa::R2::exception( |
1464
|
|
|
|
|
|
|
'The ASF traversing method returned undef -- that is not allowed') |
1465
|
|
|
|
|
|
|
if not defined $value; |
1466
|
702
|
|
|
|
|
1307
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::VALUES]->[$downglade_id] |
1467
|
|
|
|
|
|
|
= $value; |
1468
|
702
|
|
|
|
|
3736
|
return $value; |
1469
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::Traverse::rh_value |
1470
|
|
|
|
|
|
|
|
1471
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::rh_values { |
1472
|
17
|
|
|
17
|
|
44
|
my ( $traverser ) = @_; |
1473
|
17
|
|
|
|
|
36
|
return map { Marpa::R2::Internal::ASF::Traverse::rh_value( $traverser, $_ ) } |
|
35
|
|
|
|
|
85
|
|
1474
|
|
|
|
|
|
|
0 .. Marpa::R2::Internal::ASF::Traverse::rh_length( $traverser ) - 1; |
1475
|
|
|
|
|
|
|
} |
1476
|
|
|
|
|
|
|
|
1477
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::next_factoring { |
1478
|
1721
|
|
|
1721
|
|
2590
|
my ($traverser) = @_; |
1479
|
1721
|
|
|
|
|
2519
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1480
|
1721
|
|
|
|
|
2285
|
my $glade_id = $glade->[Marpa::R2::Internal::Glade::ID]; |
1481
|
1721
|
|
|
|
|
2389
|
my $asf = $traverser->[Marpa::R2::Internal::ASF::Traverse::ASF]; |
1482
|
1721
|
|
|
|
|
2447
|
my $symch_ix = $traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX]; |
1483
|
1721
|
|
|
|
|
3036
|
my $last_factoring = |
1484
|
|
|
|
|
|
|
$asf->symch_factoring_count( $glade_id, $symch_ix ) - 1; |
1485
|
1721
|
|
|
|
|
2520
|
my $factoring_ix = |
1486
|
|
|
|
|
|
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX]; |
1487
|
1721
|
100
|
|
|
|
5527
|
return if $factoring_ix >= $last_factoring; |
1488
|
1056
|
|
|
|
|
1400
|
$factoring_ix++; |
1489
|
1056
|
|
|
|
|
1380
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX] = |
1490
|
|
|
|
|
|
|
$factoring_ix; |
1491
|
1056
|
|
|
|
|
2693
|
return $factoring_ix; |
1492
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::Traverse::next_factoring |
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::next_symch { |
1495
|
665
|
|
|
665
|
|
1140
|
my ($traverser) = @_; |
1496
|
665
|
|
|
|
|
964
|
my $glade = $traverser->[Marpa::R2::Internal::ASF::Traverse::GLADE]; |
1497
|
665
|
|
|
|
|
882
|
my $glade_id = $glade->[Marpa::R2::Internal::Glade::ID]; |
1498
|
665
|
|
|
|
|
916
|
my $asf = $traverser->[Marpa::R2::Internal::ASF::Traverse::ASF]; |
1499
|
665
|
|
|
|
|
916
|
my $symch_ix = $traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX]; |
1500
|
665
|
|
|
|
|
1176
|
my $last_symch = $asf->glade_symch_count( $glade_id ) - 1; |
1501
|
665
|
100
|
|
|
|
2162
|
return if $symch_ix >= $last_symch; |
1502
|
7
|
|
|
|
|
13
|
$symch_ix++; |
1503
|
7
|
|
|
|
|
12
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::SYMCH_IX] = $symch_ix; |
1504
|
7
|
|
|
|
|
15
|
$traverser->[Marpa::R2::Internal::ASF::Traverse::FACTORING_IX] = 0; |
1505
|
7
|
|
|
|
|
19
|
return $symch_ix; |
1506
|
|
|
|
|
|
|
} ## end sub Marpa::R2::Internal::ASF::Traverse::next_symch |
1507
|
|
|
|
|
|
|
|
1508
|
|
|
|
|
|
|
sub Marpa::R2::Internal::ASF::Traverse::next { |
1509
|
1721
|
|
|
1721
|
|
3656
|
my ($traverser) = @_; |
1510
|
1721
|
|
100
|
|
|
3159
|
return $traverser->next_factoring() // $traverser->next_symch(); |
1511
|
|
|
|
|
|
|
} |
1512
|
|
|
|
|
|
|
|
1513
|
|
|
|
|
|
|
# GLADE_SEEN is a local -- this is to silence warnings |
1514
|
|
|
|
|
|
|
our %GLADE_SEEN; |
1515
|
|
|
|
|
|
|
|
1516
|
|
|
|
|
|
|
sub form_choice { |
1517
|
35
|
|
|
35
|
|
65
|
my ( $parent_choice, $sub_choice ) = @_; |
1518
|
35
|
100
|
|
|
|
86
|
return $sub_choice if not defined $parent_choice; |
1519
|
10
|
|
|
|
|
31
|
return join q{.}, $parent_choice, $sub_choice; |
1520
|
|
|
|
|
|
|
} |
1521
|
|
|
|
|
|
|
|
1522
|
|
|
|
|
|
|
sub Marpa::R2::ASF::dump_glade { |
1523
|
163
|
|
|
163
|
0
|
289
|
my ( $asf, $glade_id, $parent_choice, $item_ix ) = @_; |
1524
|
163
|
100
|
|
|
|
371
|
if ( $GLADE_SEEN{$glade_id} ) { |
1525
|
44
|
|
|
|
|
134
|
return [ [0, $glade_id, "already displayed"] ]; |
1526
|
|
|
|
|
|
|
} |
1527
|
119
|
|
|
|
|
237
|
$GLADE_SEEN{$glade_id} = 1; |
1528
|
|
|
|
|
|
|
|
1529
|
119
|
|
|
|
|
227
|
my $grammar = $asf->grammar(); |
1530
|
119
|
|
|
|
|
215
|
my @lines = (); |
1531
|
119
|
|
|
|
|
166
|
my $symch_indent = 0; |
1532
|
|
|
|
|
|
|
|
1533
|
119
|
|
|
|
|
240
|
my $symch_count = $asf->glade_symch_count($glade_id); |
1534
|
119
|
|
|
|
|
186
|
my $symch_choice = $parent_choice; |
1535
|
119
|
100
|
|
|
|
239
|
if ( $symch_count > 1 ) { |
1536
|
3
|
|
50
|
|
|
10
|
$item_ix //= 0; |
1537
|
3
|
|
|
|
|
17
|
push @lines, |
1538
|
|
|
|
|
|
|
[ 0, undef, "Symbol #$item_ix " |
1539
|
|
|
|
|
|
|
. $grammar->symbol_display_form($asf->glade_symbol_id($glade_id)) |
1540
|
|
|
|
|
|
|
. " has $symch_count symches" ]; |
1541
|
3
|
|
|
|
|
9
|
$symch_indent += 2; |
1542
|
3
|
|
|
|
|
9
|
$symch_choice = form_choice( $parent_choice, $item_ix ); |
1543
|
|
|
|
|
|
|
} ## end if ( $symch_count > 1 ) |
1544
|
119
|
|
|
|
|
266
|
for ( my $symch_ix = 0; $symch_ix < $symch_count; $symch_ix++ ) { |
1545
|
122
|
100
|
|
|
|
263
|
my $current_choice = |
1546
|
|
|
|
|
|
|
$symch_count > 1 |
1547
|
|
|
|
|
|
|
? form_choice( $symch_choice, $symch_ix ) |
1548
|
|
|
|
|
|
|
: $symch_choice; |
1549
|
122
|
|
|
|
|
174
|
my $indent = $symch_indent; |
1550
|
122
|
100
|
|
|
|
206
|
if ( $symch_count > 1 ) { |
1551
|
6
|
|
|
|
|
18
|
push @lines, [ $symch_indent , undef, "Symch #$current_choice" ]; |
1552
|
|
|
|
|
|
|
} |
1553
|
122
|
|
|
|
|
275
|
my $rule_id = $asf->symch_rule_id( $glade_id, $symch_ix ); |
1554
|
122
|
100
|
|
|
|
229
|
if ( $rule_id >= 0 ) { |
1555
|
67
|
|
|
|
|
297
|
push @lines, |
1556
|
|
|
|
|
|
|
[ |
1557
|
|
|
|
|
|
|
$symch_indent, $glade_id, |
1558
|
|
|
|
|
|
|
"Rule $rule_id: " . $grammar->rule_show($rule_id) |
1559
|
|
|
|
|
|
|
]; |
1560
|
67
|
|
|
|
|
128
|
for my $line ( |
1561
|
67
|
|
|
|
|
173
|
@{ dump_factorings( |
1562
|
|
|
|
|
|
|
$asf, $glade_id, $symch_ix, $current_choice |
1563
|
|
|
|
|
|
|
) } |
1564
|
|
|
|
|
|
|
) |
1565
|
|
|
|
|
|
|
{ |
1566
|
515
|
|
|
|
|
640
|
my ( $line_indent, @rest_of_line ) = @{$line}; |
|
515
|
|
|
|
|
924
|
|
1567
|
515
|
|
|
|
|
1323
|
push @lines, [ $line_indent + $symch_indent + 2, @rest_of_line ]; |
1568
|
|
|
|
|
|
|
} ## end for my $line ( dump_factorings( $asf, $glade_id, ...)) |
1569
|
|
|
|
|
|
|
} ## end if ( $rule_id >= 0 ) |
1570
|
|
|
|
|
|
|
else { |
1571
|
55
|
|
|
|
|
127
|
my $line = dump_terminal( $asf, $glade_id, $current_choice ); |
1572
|
55
|
|
|
|
|
82
|
my ( $line_indent, @rest_of_line ) = @{$line}; |
|
55
|
|
|
|
|
142
|
|
1573
|
55
|
|
|
|
|
296
|
push @lines, [ $line_indent + $symch_indent, @rest_of_line ]; |
1574
|
|
|
|
|
|
|
} ## end else [ if ( $rule_id >= 0 ) ] |
1575
|
|
|
|
|
|
|
} ## end for ( my $symch_ix = 0; $symch_ix < $symch_count; $symch_ix...) |
1576
|
119
|
|
|
|
|
298
|
return \@lines; |
1577
|
|
|
|
|
|
|
} |
1578
|
|
|
|
|
|
|
|
1579
|
|
|
|
|
|
|
# Show all the factorings of a SYMCH |
1580
|
|
|
|
|
|
|
sub dump_factorings { |
1581
|
67
|
|
|
67
|
|
141
|
my ( $asf, $glade_id, $symch_ix, $parent_choice ) = @_; |
1582
|
|
|
|
|
|
|
|
1583
|
67
|
|
|
|
|
96
|
my @lines; |
1584
|
67
|
|
|
|
|
142
|
my $factoring_count = $asf->symch_factoring_count( $glade_id, $symch_ix ); |
1585
|
67
|
|
|
|
|
154
|
for ( |
1586
|
|
|
|
|
|
|
my $factoring_ix = 0; |
1587
|
|
|
|
|
|
|
$factoring_ix < $factoring_count; |
1588
|
|
|
|
|
|
|
$factoring_ix++ |
1589
|
|
|
|
|
|
|
) |
1590
|
|
|
|
|
|
|
{ |
1591
|
85
|
|
|
|
|
123
|
my $indent = 0; |
1592
|
85
|
|
|
|
|
128
|
my $current_choice = $parent_choice; |
1593
|
85
|
100
|
|
|
|
161
|
if ( $factoring_count > 1 ) { |
1594
|
26
|
|
|
|
|
39
|
$indent = 2; |
1595
|
26
|
|
|
|
|
65
|
$current_choice = form_choice( $parent_choice, $factoring_ix ); |
1596
|
26
|
|
|
|
|
78
|
push @lines, [ 0, undef, "Factoring #$current_choice" ]; |
1597
|
|
|
|
|
|
|
} |
1598
|
85
|
|
|
|
|
198
|
my $symbol_count = |
1599
|
|
|
|
|
|
|
$asf->factoring_symbol_count( $glade_id, $symch_ix, |
1600
|
|
|
|
|
|
|
$factoring_ix ); |
1601
|
85
|
|
|
|
|
216
|
SYMBOL: for my $symbol_ix ( 0 .. $symbol_count - 1 ) { |
1602
|
152
|
|
|
|
|
362
|
my $downglade = |
1603
|
|
|
|
|
|
|
$asf->factor_downglade( $glade_id, $symch_ix, $factoring_ix, |
1604
|
|
|
|
|
|
|
$symbol_ix ); |
1605
|
152
|
|
|
|
|
206
|
for my $line ( |
1606
|
152
|
|
|
|
|
370
|
@{ $asf->dump_glade( $downglade, $current_choice, |
1607
|
|
|
|
|
|
|
$symbol_ix ) |
1608
|
|
|
|
|
|
|
} |
1609
|
|
|
|
|
|
|
) |
1610
|
|
|
|
|
|
|
{ |
1611
|
489
|
|
|
|
|
615
|
my ( $line_indent, @rest_of_line ) = @{$line}; |
|
489
|
|
|
|
|
914
|
|
1612
|
489
|
|
|
|
|
1721
|
push @lines, [ $line_indent + $indent, @rest_of_line ]; |
1613
|
|
|
|
|
|
|
|
1614
|
|
|
|
|
|
|
} ## end for my $line ( @{ $asf->dump_glade( $downglade, ...)}) |
1615
|
|
|
|
|
|
|
} ## end SYMBOL: for my $symbol_ix ( 0 .. $symbol_count - 1 ) |
1616
|
|
|
|
|
|
|
} ## end for ( my $factoring_ix = 0; $factoring_ix < $factoring_count...) |
1617
|
67
|
|
|
|
|
147
|
return \@lines; |
1618
|
|
|
|
|
|
|
} ## end sub dump_factorings |
1619
|
|
|
|
|
|
|
|
1620
|
|
|
|
|
|
|
sub dump_terminal { |
1621
|
55
|
|
|
55
|
|
109
|
my ( $asf, $glade_id, $symch_ix, $parent_choice ) = @_; |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
# There can only be one symbol in a terminal and therefore only one factoring |
1624
|
55
|
|
|
|
|
74
|
my $current_choice = $parent_choice; |
1625
|
55
|
|
|
|
|
116
|
my $literal = $asf->glade_literal($glade_id); |
1626
|
55
|
|
|
|
|
127
|
my $symbol_id = $asf->glade_symbol_id($glade_id); |
1627
|
55
|
|
|
|
|
111
|
my $grammar = $asf->grammar(); |
1628
|
55
|
|
|
|
|
161
|
my $display_form = $grammar->symbol_display_form($symbol_id); |
1629
|
55
|
|
|
|
|
251
|
return [0, $glade_id, qq{Symbol $display_form: "$literal"}]; |
1630
|
|
|
|
|
|
|
} ## end sub dump_terminal |
1631
|
|
|
|
|
|
|
|
1632
|
|
|
|
|
|
|
sub Marpa::R2::ASF::dump { |
1633
|
11
|
|
|
11
|
0
|
82
|
my ($asf) = @_; |
1634
|
11
|
|
|
|
|
38
|
my $peak = $asf->peak(); |
1635
|
11
|
|
|
|
|
27
|
local %GLADE_SEEN = (); ## no critic (Variables::ProhibitLocalVars) |
1636
|
11
|
|
|
|
|
36
|
my $lines = $asf->dump_glade( $peak ); |
1637
|
11
|
|
|
|
|
19
|
my $next_sequenced_id = 1; # one-based |
1638
|
11
|
|
|
|
|
19
|
my %sequenced_id = (); |
1639
|
11
|
|
66
|
|
|
20
|
$sequenced_id{$_} //= $next_sequenced_id++ for grep { defined } map { $_->[1] } @{$lines}; |
|
201
|
|
|
|
|
549
|
|
|
201
|
|
|
|
|
326
|
|
|
11
|
|
|
|
|
24
|
|
1640
|
11
|
|
|
|
|
36
|
my $text = q{}; |
1641
|
11
|
|
|
|
|
36
|
for my $line ( @{$lines}[ 1 .. $#$lines ] ) { |
|
11
|
|
|
|
|
41
|
|
1642
|
190
|
|
|
|
|
225
|
my ( $line_indent, $glade_id, $body ) = @{$line}; |
|
190
|
|
|
|
|
313
|
|
1643
|
190
|
|
|
|
|
253
|
$line_indent -= 2; |
1644
|
190
|
|
|
|
|
281
|
$text .= q{ } x $line_indent; |
1645
|
190
|
100
|
|
|
|
392
|
$text .= 'GL' . $sequenced_id{$glade_id} . q{ } if defined $glade_id; |
1646
|
190
|
|
|
|
|
316
|
$text .= "$body\n"; |
1647
|
|
|
|
|
|
|
} |
1648
|
11
|
|
|
|
|
120
|
return $text; |
1649
|
|
|
|
|
|
|
} ## end sub show |
1650
|
|
|
|
|
|
|
|
1651
|
|
|
|
|
|
|
sub Marpa::R2::ASF::show_nidsets { |
1652
|
0
|
|
|
0
|
0
|
|
my ($asf) = @_; |
1653
|
0
|
|
|
|
|
|
my $text = q{}; |
1654
|
0
|
|
|
|
|
|
my $nidsets = $asf->[Marpa::R2::Internal::ASF::NIDSET_BY_ID]; |
1655
|
0
|
|
|
|
|
|
for my $nidset ( grep {defined} @{$nidsets} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1656
|
0
|
|
|
|
|
|
$text .= $nidset->show() . "\n"; |
1657
|
|
|
|
|
|
|
} |
1658
|
0
|
|
|
|
|
|
return $text; |
1659
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::show_nidsets |
1660
|
|
|
|
|
|
|
|
1661
|
|
|
|
|
|
|
sub Marpa::R2::ASF::show_powersets { |
1662
|
0
|
|
|
0
|
0
|
|
my ($asf) = @_; |
1663
|
0
|
|
|
|
|
|
my $text = q{}; |
1664
|
0
|
|
|
|
|
|
my $powersets = $asf->[Marpa::R2::Internal::ASF::POWERSET_BY_ID]; |
1665
|
0
|
|
|
|
|
|
for my $powerset ( grep {defined} @{$powersets} ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
1666
|
0
|
|
|
|
|
|
$text .= $powerset->show() . "\n"; |
1667
|
|
|
|
|
|
|
} |
1668
|
0
|
|
|
|
|
|
return $text; |
1669
|
|
|
|
|
|
|
} ## end sub Marpa::R2::ASF::show_powersets |
1670
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
sub dump_nook { |
1672
|
0
|
|
|
0
|
|
|
my ( $asf, $nook ) = @_; |
1673
|
0
|
|
|
|
|
|
my $slr = $asf->[Marpa::R2::Internal::ASF::SLR]; |
1674
|
0
|
|
|
|
|
|
my $or_nodes = $asf->[Marpa::R2::Internal::ASF::OR_NODES]; |
1675
|
0
|
|
|
|
|
|
my $recce = $slr->[Marpa::R2::Internal::Scanless::R::THICK_G1_RECCE]; |
1676
|
0
|
|
|
|
|
|
my $or_node_id = $nook->[Marpa::R2::Internal::Nook::OR_NODE]; |
1677
|
0
|
|
|
|
|
|
my $and_node_count = scalar @{ $or_nodes->[$or_node_id] }; |
|
0
|
|
|
|
|
|
|
1678
|
0
|
|
|
|
|
|
my $text = 'Nook '; |
1679
|
0
|
|
|
|
|
|
my @text = (); |
1680
|
0
|
0
|
|
|
|
|
push @text, $nook->[Marpa::R2::Internal::Nook::IS_CAUSE] ? q{C} : q{-}; |
1681
|
0
|
0
|
|
|
|
|
push @text, |
1682
|
|
|
|
|
|
|
$nook->[Marpa::R2::Internal::Nook::IS_PREDECESSOR] ? q{P} : q{-}; |
1683
|
0
|
0
|
|
|
|
|
push @text, |
1684
|
|
|
|
|
|
|
$nook->[Marpa::R2::Internal::Nook::CAUSE_IS_EXPANDED] ? q{C+} : q{--}; |
1685
|
0
|
0
|
|
|
|
|
push @text, |
1686
|
|
|
|
|
|
|
$nook->[Marpa::R2::Internal::Nook::PREDECESSOR_IS_EXPANDED] |
1687
|
|
|
|
|
|
|
? q{P+} |
1688
|
|
|
|
|
|
|
: q{--}; |
1689
|
0
|
|
|
|
|
|
$text .= join q{ }, @text; |
1690
|
0
|
|
|
|
|
|
$text |
1691
|
|
|
|
|
|
|
.= ' @' |
1692
|
|
|
|
|
|
|
. $nook->[Marpa::R2::Internal::Nook::FIRST_CHOICE] . q{-} |
1693
|
|
|
|
|
|
|
. $nook->[Marpa::R2::Internal::Nook::LAST_CHOICE] |
1694
|
|
|
|
|
|
|
. qq{ of $and_node_count: }; |
1695
|
0
|
|
|
|
|
|
$text .= $recce->verbose_or_node($or_node_id); |
1696
|
0
|
|
|
|
|
|
return $text; |
1697
|
|
|
|
|
|
|
} ## end sub dump_nook |
1698
|
|
|
|
|
|
|
|
1699
|
|
|
|
|
|
|
# For debugging |
1700
|
|
|
|
|
|
|
sub dump_factoring_stack { |
1701
|
0
|
|
|
0
|
|
|
my ( $asf, $stack ) = @_; |
1702
|
0
|
|
|
|
|
|
my $text = q{}; |
1703
|
0
|
|
|
|
|
|
for ( my $stack_ix = 0; $stack_ix <= $#{$stack}; $stack_ix++ ) { |
|
0
|
|
|
|
|
|
|
1704
|
|
|
|
|
|
|
|
1705
|
|
|
|
|
|
|
# Nook already has newline at end |
1706
|
0
|
|
|
|
|
|
$text .= "$stack_ix: " . dump_nook( $asf, $stack->[$stack_ix] ); |
1707
|
|
|
|
|
|
|
} |
1708
|
0
|
|
|
|
|
|
return $text . "\n"; |
1709
|
|
|
|
|
|
|
} ## end sub dump_factoring_stack |
1710
|
|
|
|
|
|
|
|
1711
|
|
|
|
|
|
|
1; |
1712
|
|
|
|
|
|
|
|
1713
|
|
|
|
|
|
|
# vim: expandtab shiftwidth=4: |