line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Filter::Dispatcher::Ops; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
XML::Filter::Dispatcher::Ops - The Syntax Tree |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
None. Used by XML::Filter::Dispatcher. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
## TODO: Replace XFD:: with XML::Filter::Dispatcher |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
## TODO: "helper" subs. functions? dunno. |
16
|
|
|
|
|
|
|
## as-structure() EventPath function |
17
|
|
|
|
|
|
|
## emit XML chunk (well balanced, not wf) |
18
|
|
|
|
|
|
|
## as_document |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
## TODO: use context->{PossibleEventTypes} to |
21
|
|
|
|
|
|
|
## reduce the amount of downstream test code and |
22
|
|
|
|
|
|
|
## perhaps the amount of currying. No need to test |
23
|
|
|
|
|
|
|
## for EventType if we know only one node type is |
24
|
|
|
|
|
|
|
## possible :). |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package XFD; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
5
|
use Carp qw( confess ); ## NOT croak: this module must die "...\n". |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
68
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
4
|
use constant is_tracing => defined $Devel::TraceSAX::VERSION; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
111
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Devel::TraceSAX does not work with perl5.8.0 |
33
|
|
|
|
|
|
|
#use constant is_tracing => 1; |
34
|
|
|
|
|
|
|
#sub emit_trace_SAX_message { warn @_ }; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
## Some debugging aids |
37
|
|
|
|
|
|
|
*_ev = \&XML::Filter::Dispatcher::_ev; |
38
|
|
|
|
|
|
|
*_po = \&XML::Filter::Dispatcher::_po; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
BEGIN { |
41
|
1
|
50
|
|
1
|
|
74
|
eval( is_tracing |
42
|
|
|
|
|
|
|
? 'use Devel::TraceSAX qw( emit_trace_SAX_message ); 1' |
43
|
|
|
|
|
|
|
: 'sub emit_trace_SAX_message; 1' |
44
|
|
|
|
|
|
|
) or die $@; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use vars ( |
51
|
1
|
|
|
|
|
1701
|
'$dispatcher', ## The X::F::D that we're doing the parse for. |
52
|
1
|
|
|
1
|
|
3
|
); |
|
1
|
|
|
|
|
3
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=begin private |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 Precursors and Postponment |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
NOTE: in this blurb, nodes occur in alphabetical order in the document |
59
|
|
|
|
|
|
|
being processed. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
level 0 expressions are able to be evaluated using only the current |
62
|
|
|
|
|
|
|
event and it's 'ancestor events' and, when the match succeeds, the |
63
|
|
|
|
|
|
|
action is executed in the current event's context. The path '/a/b[@c]' |
64
|
|
|
|
|
|
|
is level 0 can be evaluated using just the start_document event and the |
65
|
|
|
|
|
|
|
start_element events for , , and . So are the paths |
66
|
|
|
|
|
|
|
'/a[@a]/b[@b]/c' and '/a[b]/b[c]/c'. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The paths '/a[b]' is not level 0; it requires some evaluation to occur |
69
|
|
|
|
|
|
|
when the start_element event for '/a' is seen and other evaluation when |
70
|
|
|
|
|
|
|
the start_element event for '/a/b' is seen; and when it does match |
71
|
|
|
|
|
|
|
(which will occur in the start event for the first '/a/b'), the action's |
72
|
|
|
|
|
|
|
execution context must be '/a', not '/a/b'. In this case, the match |
73
|
|
|
|
|
|
|
must proceed in stages and the action is postponed until all stages are |
74
|
|
|
|
|
|
|
satisfied. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This is implemented in this code by converting level 1 expressions in to |
77
|
|
|
|
|
|
|
precursors ('/a' and './b' in /a's context in our example) and |
78
|
|
|
|
|
|
|
postponing the main expression (which just fires the action in this |
79
|
|
|
|
|
|
|
case) using an object called a "postponement session" until enough |
80
|
|
|
|
|
|
|
precursors are satisfied. Once enough precursors are satisfied, the |
81
|
|
|
|
|
|
|
action is executed and the postponement is destroyed. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The phrase "enough precursors are satisfied" is used rather than "all |
84
|
|
|
|
|
|
|
precursors are satisfied" because expressions like 'a[ b or c ]' does |
85
|
|
|
|
|
|
|
not need both the './b' or './c' precursors; either one will suffice. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
A postponement session has a value slot for each precursor and a slot for |
88
|
|
|
|
|
|
|
the result context. Each precursor fills is it's slot when it matches, |
89
|
|
|
|
|
|
|
and the primary precursor sets the main expression / action context. As |
90
|
|
|
|
|
|
|
each precursor fires, it checks to see if enough of the slots are filled |
91
|
|
|
|
|
|
|
in and fires the action or main expression if so. Expressions like |
92
|
|
|
|
|
|
|
'//*[b]' and '/a//b[c]' can cause multiple simultaneous postponement |
93
|
|
|
|
|
|
|
sessions for the same expression. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
For expressions like '/a/b[c]/d', the main expression (or result) |
96
|
|
|
|
|
|
|
context may not be set when some of the precursors match: /a/b/c will |
97
|
|
|
|
|
|
|
match before /a/b/d. The precursor for '/a/b/d' is called the primary |
98
|
|
|
|
|
|
|
precursor and sets the result context. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The action (or main expression in an expression line '/a[concat(b,c)]') is |
101
|
|
|
|
|
|
|
evaluated in the result context ('/a' in this case). |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The main expression (or action) should be executed once per primary |
104
|
|
|
|
|
|
|
precursor match in the document where the entire expression is true. |
105
|
|
|
|
|
|
|
So a rule with a pattern '/a/b[c]/d[e]' would fire once for every /a/b/d |
106
|
|
|
|
|
|
|
node in the document where the entire match is true. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
//a[b]/c and //a[c]/b |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The first precursor to match must create a postponement session. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Q: How do we associate the precursors with their appropriate |
113
|
|
|
|
|
|
|
postponement sessions? |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
In expressions like 'concat( /a, /b )', the precursors '/a' and '/b' are |
116
|
|
|
|
|
|
|
numbered 0 and 1 and there is a "main expression" of 'concat( |
117
|
|
|
|
|
|
|
PRECURSOR_0, PRECURSOR_1)', where the PRECURSOR_# is the result of the |
118
|
|
|
|
|
|
|
indicated precursor. The main expression which is computed before |
119
|
|
|
|
|
|
|
firing the action. The action context is "/". |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Expressions like 'concat( a, b )' are similar except that the action |
122
|
|
|
|
|
|
|
context is the parent of the and elements that match. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
In '/a[concat( b, c )]' the precursors are './b', './c' and 'a[concat( |
125
|
|
|
|
|
|
|
PRECURSOR_0, PRECURSOR_1 )]', and the action can only fire when |
126
|
|
|
|
|
|
|
PRECURSOR_2 becomes defined. The action contexst is '/a'. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Each time a context-setting precursor matches, all presursor sessions |
129
|
|
|
|
|
|
|
that it affects become "eligible" for firing. A precursor session fires |
130
|
|
|
|
|
|
|
as soon as enough precursors are satisfied. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 Firing Policy |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This does not apply to level 0 patterns. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
An application may support multiple policies controlling when a |
137
|
|
|
|
|
|
|
postponed expression is finally completely evaluated (ie matches, fails |
138
|
|
|
|
|
|
|
to match, or returns a result). |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
A "prompt evaluation policy" describes implementations where postponed |
141
|
|
|
|
|
|
|
expressions match the first time enough predicates are |
142
|
|
|
|
|
|
|
satisified (when the start_element() arrives, in this case). This |
143
|
|
|
|
|
|
|
is useful to minimize memory and recognize conditions as rapidly as |
144
|
|
|
|
|
|
|
possible. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
A "delayed evaluation policy" describes implementations where postponed |
147
|
|
|
|
|
|
|
expressions are evaluated during the end_...() event for the node |
148
|
|
|
|
|
|
|
deepest in the hierarchy for which an un-postponed test was true. For |
149
|
|
|
|
|
|
|
example, rules with these patterns must fire their actions before the |
150
|
|
|
|
|
|
|
if at all: '/a[b]', '/z/a/[b]'. This may make some |
151
|
|
|
|
|
|
|
implementations easier but is discouraged unless necessary. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
An application must be apply a consistent firing policy policy prompt, |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
An application may also provide for |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
An application must detail whether it supports modes other than "prompt |
158
|
|
|
|
|
|
|
firing" or not and all applications |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=end private |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
############################################################################### |
165
|
|
|
|
|
|
|
## |
166
|
|
|
|
|
|
|
## Boolean Singletons |
167
|
|
|
|
|
|
|
## |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
## These are not used internally; 1 and 0 are. These are used when passing |
170
|
|
|
|
|
|
|
## boolean values in / out to Perl code, so they may be differentiated from |
171
|
|
|
|
|
|
|
## numeric ones. |
172
|
|
|
|
|
|
|
sub true() { \"true" } |
173
|
|
|
|
|
|
|
sub false() { \"false" } |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
############################################################################### |
177
|
|
|
|
|
|
|
## |
178
|
|
|
|
|
|
|
## Helpers |
179
|
|
|
|
|
|
|
## |
180
|
0
|
|
|
0
|
|
0
|
sub _looks_numeric($) { $_[0] =~ /^[ \t\r\n]*-?(?:\d+(?:\.\d+)?|\.\d+)[ \t\r\n]*$/ } |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
0
|
|
0
|
sub _looks_literal($) { $_[0] =~ /^(?:'[^']*'|"[^"]*")(?!\n)\Z/ } |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub _indentomatic() { 1 } ## Turning this off shaves a little parse time. |
185
|
|
|
|
|
|
|
## I leave it on for more readable error |
186
|
|
|
|
|
|
|
## messages, and it's key for debugging since |
187
|
|
|
|
|
|
|
## is so much more readable; in fact, messed |
188
|
|
|
|
|
|
|
## up indenting can indicate serious problems |
189
|
|
|
|
|
|
|
|
190
|
10
|
50
|
|
10
|
|
23
|
sub _indent { Carp::confess "undef" unless defined $_[0]; $_[0] =~ s/^/ /mg; } |
|
10
|
|
|
|
|
209
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub _is_rel_path($) { |
193
|
0
|
|
|
0
|
|
0
|
my $path = shift; |
194
|
|
|
|
|
|
|
|
195
|
0
|
0
|
0
|
|
|
0
|
return 0 |
|
|
|
0
|
|
|
|
|
196
|
|
|
|
|
|
|
if $path->isa( "XFD::PathTest" ) |
197
|
|
|
|
|
|
|
&& $path->isa( "XFD::doc_node" ) ## /... paths |
198
|
|
|
|
|
|
|
&& ! $path->isa( "XFD::union" ); ## (a|b), union called this already. |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
0
|
return 1; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
############################################################################### |
205
|
|
|
|
|
|
|
## |
206
|
|
|
|
|
|
|
## Postponement Records |
207
|
|
|
|
|
|
|
## |
208
|
|
|
|
|
|
|
## When the current location step or operator/function call |
209
|
|
|
|
|
|
|
## in an expression can't be calculated because it needs some |
210
|
|
|
|
|
|
|
## future information, it must be postponed. The portions of |
211
|
|
|
|
|
|
|
## the expression that can't yet be calculated are called |
212
|
|
|
|
|
|
|
## precursors; only when enough of them are calculated can |
213
|
|
|
|
|
|
|
## this expression be calculated. |
214
|
|
|
|
|
|
|
## |
215
|
|
|
|
|
|
|
## A Postponement record contains: |
216
|
|
|
|
|
|
|
## |
217
|
|
|
|
|
|
|
## - A list of contexts for which this postponement eventually |
218
|
|
|
|
|
|
|
## becomes valid. |
219
|
|
|
|
|
|
|
## - A pointer to the parent postponement |
220
|
|
|
|
|
|
|
## - A set of results one for each precursor. |
221
|
|
|
|
|
|
|
## |
222
|
|
|
|
|
|
|
## A postponement record is a simple array with a few set data fields |
223
|
|
|
|
|
|
|
## in the first elements; the remaining elements are used to hold |
224
|
|
|
|
|
|
|
## precursor results. |
225
|
|
|
|
|
|
|
## |
226
|
|
|
|
|
|
|
## This could be an object, but we don't need any inheritence. |
227
|
|
|
|
|
|
|
## |
228
|
|
|
|
|
|
|
sub _p_parent_postponement() { 0 } |
229
|
|
|
|
|
|
|
sub _p_contexts() { 1 } |
230
|
|
|
|
|
|
|
sub _p_first_precursor () { 2 } |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
############################################################################### |
233
|
|
|
|
|
|
|
## |
234
|
|
|
|
|
|
|
## expr_as_incr_code |
235
|
|
|
|
|
|
|
## |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
## |
238
|
|
|
|
|
|
|
## Precursors |
239
|
|
|
|
|
|
|
## ========== |
240
|
|
|
|
|
|
|
## |
241
|
|
|
|
|
|
|
## A precursor is something (so far always a location path sub-expr) that |
242
|
|
|
|
|
|
|
## (usually) needs to be dealt with before a pattern can be evaluated. |
243
|
|
|
|
|
|
|
## A precursor is known as "defined" if it's been evaluated and returned |
244
|
|
|
|
|
|
|
## some result (number, string, boolean, or node). |
245
|
|
|
|
|
|
|
## |
246
|
|
|
|
|
|
|
## The only time a pattern can be fully evaluated in the face of undefined |
247
|
|
|
|
|
|
|
## precursor is when the precursor is supposed to return a node and the |
248
|
|
|
|
|
|
|
## precursor result is being turned in to a boolean. Booleans accept |
249
|
|
|
|
|
|
|
## empty node sets as false values. Right now, all precursors happen to |
250
|
|
|
|
|
|
|
## return node sets of 0 or 1 nodes. |
251
|
|
|
|
|
|
|
## |
252
|
|
|
|
|
|
|
## The precursor values are stored in $ctx because I'm afraid of leaky |
253
|
|
|
|
|
|
|
## closure in older perl. I haven't tested them in this case, but have been |
254
|
|
|
|
|
|
|
## bit before. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
sub _replace_NEXT { |
257
|
0
|
|
|
0
|
|
0
|
my $what_next = ""; |
258
|
0
|
0
|
|
|
|
0
|
$what_next = pop if @_ > 2; |
259
|
0
|
|
|
|
|
0
|
my $next_code = pop; |
260
|
0
|
|
|
|
|
0
|
$_[0] =~ s{(^[ \t]*)?$what_next}{ |
261
|
0
|
0
|
|
|
|
0
|
if ( _indentomatic && defined $1 ) { |
262
|
0
|
|
|
|
|
0
|
_indent $next_code for 1..(length( $1 ) / 2 ); |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
$next_code |
265
|
0
|
|
|
|
|
0
|
}gme; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
############################################################################### |
270
|
|
|
|
|
|
|
## |
271
|
|
|
|
|
|
|
## Parse tree node base class |
272
|
|
|
|
|
|
|
## |
273
|
|
|
|
|
|
|
## This is used for all of the pieces of location paths axis tests, name |
274
|
|
|
|
|
|
|
## and type tests, predicates. It is also used by a few functions |
275
|
|
|
|
|
|
|
## that act on the result of a location path (which is effectively a |
276
|
|
|
|
|
|
|
## node set with just the current node in it). |
277
|
|
|
|
|
|
|
## |
278
|
|
|
|
|
|
|
sub XFD::Op::new { |
279
|
35
|
|
|
35
|
|
48
|
my $class = shift; |
280
|
35
|
|
|
|
|
199
|
return bless [ @_ ], $class; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
0
|
|
0
|
sub XFD::Op::op_type { ( my $type = ref shift ) =~ s/.*:// ; $type } |
|
0
|
|
|
|
|
0
|
|
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
## The optimizer combines common expressions in some cases (it should |
287
|
|
|
|
|
|
|
## do more, right now it only does common leading op codes). To do this |
288
|
|
|
|
|
|
|
## it needs to know the type of the operator and its arguments, if any. |
289
|
|
|
|
|
|
|
## By default, the signature is this op's reference id, which makes each |
290
|
|
|
|
|
|
|
## op look different to the optimizer. |
291
|
0
|
|
|
0
|
|
0
|
sub XFD::Op::optim_signature { int shift } |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
sub XFD::Op::is_constant { |
295
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
296
|
0
|
|
|
|
|
0
|
return ! grep ! $_->is_constant, @$self; |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
## fixup is called on a freshly parsed op tree just before it's |
300
|
|
|
|
|
|
|
## compiled to convert expression like 'A' to be like '//A'. |
301
|
|
|
|
|
|
|
## TODO: Perhaps move this to an XML::Filter::Dispatcher::_fixup(), |
302
|
|
|
|
|
|
|
## like _optimize(). |
303
|
|
|
|
|
|
|
sub XFD::Op::fixup { |
304
|
32
|
|
|
32
|
|
41
|
my $self = shift; |
305
|
32
|
|
|
|
|
40
|
my ( $context ) = @_; |
306
|
|
|
|
|
|
|
|
307
|
32
|
|
|
|
|
62
|
for ( @$self ) { |
308
|
45
|
100
|
66
|
|
|
265
|
if ( defined && UNIVERSAL::isa( $_, "XFD::Op" ) ) { |
309
|
35
|
50
|
33
|
|
|
276
|
if ( ! $context->{BelowRoot} |
|
|
|
66
|
|
|
|
|
310
|
|
|
|
|
|
|
&& ( $_->isa( "XFD::Axis::child" ) |
311
|
|
|
|
|
|
|
|| $_->isa( "XFD::Axis::attribute" ) |
312
|
|
|
|
|
|
|
|| $_->isa( "XFD::Axis::start_element" ) |
313
|
|
|
|
|
|
|
|| $_->isa( "XFD::Axis::end_element" ) |
314
|
|
|
|
|
|
|
# || $_->isa( "XFD::Axis::end" ) |
315
|
|
|
|
|
|
|
) |
316
|
|
|
|
|
|
|
) { |
317
|
|
|
|
|
|
|
## The miniature version of XPath used in |
318
|
|
|
|
|
|
|
## XSLT's match expressions |
319
|
|
|
|
|
|
|
## seems to me to behave like // was prepended if |
320
|
|
|
|
|
|
|
## the expression begins with a child:: or |
321
|
|
|
|
|
|
|
## attribute:: axis (or their abbreviations: no |
322
|
|
|
|
|
|
|
## axis => child:: and @ => attribute::). |
323
|
5
|
|
|
|
|
22
|
my $op = XFD::EventType::node->new; |
324
|
5
|
|
|
|
|
19
|
$op->set_next( $_ ); |
325
|
5
|
|
|
|
|
7
|
$_ = $op; |
326
|
5
|
|
|
|
|
26
|
$op = XFD::Axis::descendant_or_self->new; |
327
|
5
|
|
|
|
|
17
|
$op->set_next( $_ ); |
328
|
5
|
|
|
|
|
8
|
$_ = $op; |
329
|
5
|
|
|
|
|
24
|
$op = XFD::doc_node->new; |
330
|
5
|
|
|
|
|
16
|
$op->set_next( $_ ); |
331
|
5
|
|
|
|
|
6
|
$_ = $op; |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
## This statement is why the descendant-or-self:: insertion |
335
|
|
|
|
|
|
|
## is done in Op::fixup instead of Rule::fixup. We want |
336
|
|
|
|
|
|
|
## this transform to percolate down to the first op of each |
337
|
|
|
|
|
|
|
## branch of these "grouping" ops. |
338
|
35
|
100
|
33
|
|
|
677
|
local $context->{BelowRoot} = 1 |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
339
|
|
|
|
|
|
|
unless $_->isa( "XFD::Parens" ) |
340
|
|
|
|
|
|
|
|| $_->isa( "XFD::union" ) |
341
|
|
|
|
|
|
|
|| $_->isa( "XFD::Action" ) |
342
|
|
|
|
|
|
|
|| $_->isa( "XFD::Rule" ); |
343
|
|
|
|
|
|
|
|
344
|
35
|
|
|
|
|
126
|
$_->fixup( @_ ); |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
|
348
|
32
|
|
|
|
|
80
|
return $self; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
sub XFD::Op::_add_to_graphviz { |
353
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
354
|
0
|
|
|
|
|
0
|
my ( $g ) = @_; |
355
|
|
|
|
|
|
|
|
356
|
0
|
|
|
|
|
0
|
my $port_id = 0; |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
my $port_labels = join( "|", |
359
|
|
|
|
|
|
|
map { |
360
|
0
|
|
|
|
|
0
|
my $desc = ref $_ |
361
|
|
|
|
|
|
|
? $self->can( "parm_type" ) |
362
|
|
|
|
|
|
|
? $self->parm_type( $port_id - 1 ) |
363
|
|
|
|
|
|
|
: UNIVERSAL::can( $_, "_add_to_graphviz" ) |
364
|
|
|
|
|
|
|
? "" |
365
|
|
|
|
|
|
|
: ref $_ |
366
|
|
|
|
|
|
|
: defined $_ |
367
|
0
|
0
|
|
|
|
0
|
? do { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
368
|
0
|
|
|
|
|
0
|
local $_ = $_; |
369
|
0
|
|
|
|
|
0
|
"'$_'" |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
: "undef" |
372
|
|
|
|
|
|
|
; |
373
|
0
|
|
|
|
|
0
|
for ( $desc ) { |
374
|
0
|
|
|
|
|
0
|
s/([|<>\[\]{}"])/\\$1/g; |
375
|
0
|
|
|
|
|
0
|
s/\n/\\\\n/g; |
376
|
0
|
|
|
|
|
0
|
s/(.{64}).*/$1.../; |
377
|
|
|
|
|
|
|
} |
378
|
0
|
|
|
|
|
0
|
"" . $desc; |
379
|
|
|
|
|
|
|
} @$self |
380
|
|
|
|
|
|
|
); |
381
|
|
|
|
|
|
|
|
382
|
0
|
0
|
0
|
|
|
0
|
my $label = join( "", |
|
|
0
|
|
|
|
|
|
383
|
|
|
|
|
|
|
"{", |
384
|
|
|
|
|
|
|
$self->op_type, |
385
|
|
|
|
|
|
|
$self->isa( "XFD::Action" ) && $self->[0]->{DelayToEnd} |
386
|
|
|
|
|
|
|
? " (end::)" |
387
|
|
|
|
|
|
|
: (), |
388
|
|
|
|
|
|
|
$port_labels eq "" |
389
|
|
|
|
|
|
|
? () |
390
|
|
|
|
|
|
|
: ( "|{", $port_labels, "}" ), |
391
|
|
|
|
|
|
|
"}" |
392
|
|
|
|
|
|
|
); |
393
|
|
|
|
|
|
|
|
394
|
0
|
0
|
|
|
|
0
|
$g->add_node( |
|
|
0
|
|
|
|
|
|
395
|
|
|
|
|
|
|
shape => "record", |
396
|
|
|
|
|
|
|
name => int $self, |
397
|
|
|
|
|
|
|
label => $label, |
398
|
|
|
|
|
|
|
color => $self->is_constant ? "blue" |
399
|
|
|
|
|
|
|
: $self->isa( "XFD::Action" ) ? "#A00000" |
400
|
|
|
|
|
|
|
: "black", |
401
|
|
|
|
|
|
|
height => 0.1, |
402
|
|
|
|
|
|
|
fontname => "Helvetica", |
403
|
|
|
|
|
|
|
fontsize => 10, |
404
|
|
|
|
|
|
|
); |
405
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
0
|
$port_id = 0; |
407
|
0
|
|
|
|
|
0
|
for ( @$self ) { |
408
|
0
|
0
|
|
|
|
0
|
if ( UNIVERSAL::can( $_, "_add_to_graphviz" ) ) { |
409
|
0
|
|
|
|
|
0
|
$_->_add_to_graphviz( $g ); |
410
|
0
|
0
|
|
|
|
0
|
$g->add_edge( { |
411
|
|
|
|
|
|
|
from => int $self, |
412
|
|
|
|
|
|
|
$port_labels eq "" |
413
|
|
|
|
|
|
|
? () |
414
|
|
|
|
|
|
|
: ( from_port => $port_id ), |
415
|
|
|
|
|
|
|
to => int $_, |
416
|
|
|
|
|
|
|
} ); |
417
|
|
|
|
|
|
|
} |
418
|
0
|
|
|
|
|
0
|
++$port_id; |
419
|
|
|
|
|
|
|
} |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
sub XFD::Op::as_graphviz { |
423
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
424
|
0
|
0
|
|
|
|
0
|
my $g = @_ ? shift : do { |
425
|
|
|
|
|
|
|
|
426
|
0
|
|
|
|
|
0
|
require GraphViz; |
427
|
0
|
|
|
|
|
0
|
my $g = GraphViz->new( |
428
|
|
|
|
|
|
|
nodesep => 0.1, |
429
|
|
|
|
|
|
|
ranksep => 0.1, |
430
|
|
|
|
|
|
|
); |
431
|
|
|
|
|
|
|
}; |
432
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
0
|
$self->_add_to_graphviz( $g ); |
434
|
|
|
|
|
|
|
|
435
|
0
|
|
|
|
|
0
|
return $g; |
436
|
|
|
|
|
|
|
} |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
############################################################################### |
439
|
|
|
|
|
|
|
## |
440
|
|
|
|
|
|
|
## Numeric and String literals |
441
|
|
|
|
|
|
|
## |
442
|
|
|
|
|
|
|
@XFD::NumericConstant::ISA = qw( XFD::Op ); |
443
|
0
|
|
|
0
|
|
0
|
sub XFD::NumericConstant::result_type { "number" } |
444
|
0
|
|
|
0
|
|
0
|
sub XFD::NumericConstant::is_constant { 1 } |
445
|
0
|
|
|
0
|
|
0
|
sub XFD::NumericConstant::as_immed_code { shift->[0] } |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
@XFD::StringConstant::ISA = qw( XFD::Op ); |
448
|
0
|
|
|
0
|
|
0
|
sub XFD::StringConstant::result_type { "string" } |
449
|
0
|
|
|
0
|
|
0
|
sub XFD::StringConstant::is_constant { 1 } |
450
|
|
|
|
|
|
|
sub XFD::StringConstant::as_immed_code { |
451
|
0
|
|
|
0
|
|
0
|
my $s = shift->[0]; |
452
|
0
|
|
|
|
|
0
|
$s =~ s/([\\'])/\\$1/g; |
453
|
0
|
|
|
|
|
0
|
return join $s, "'", "'"; |
454
|
|
|
|
|
|
|
} |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
################################################################################ |
457
|
|
|
|
|
|
|
## |
458
|
|
|
|
|
|
|
## Compile-time constant folding |
459
|
|
|
|
|
|
|
## |
460
|
|
|
|
|
|
|
## By tracking what values and expressions are constant, we can use |
461
|
|
|
|
|
|
|
## eval "" to evaluate things at compile time. |
462
|
|
|
|
|
|
|
## |
463
|
|
|
|
|
|
|
sub _eval_at_compile_time { |
464
|
0
|
|
|
0
|
|
0
|
my ( $type, $code, $context ) = @_; |
465
|
|
|
|
|
|
|
|
466
|
0
|
0
|
|
|
|
0
|
return $code unless $context->{FoldConstants}; |
467
|
|
|
|
|
|
|
|
468
|
0
|
|
|
|
|
0
|
my $out_code = eval $code; |
469
|
0
|
0
|
|
|
|
0
|
die "$@ in XPath compile-time execution of ($type) \"$code\"\n" |
470
|
|
|
|
|
|
|
if $@; |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
## Perl's bool ops ret. "" for F |
473
|
0
|
0
|
0
|
|
|
0
|
$out_code = "0" |
474
|
|
|
|
|
|
|
if $type eq "boolean" && !length $out_code; |
475
|
0
|
0
|
|
|
|
0
|
$out_code = $$out_code if ref $out_code; |
476
|
0
|
0
|
|
|
|
0
|
if ( $type eq "string" ) { |
477
|
0
|
|
|
|
|
0
|
$out_code =~ s/([\\'])/\\$1/g; |
478
|
0
|
|
|
|
|
0
|
$out_code = "'$out_code'"; |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
#warn "compiled `$code` to `$out_code`"; |
482
|
0
|
|
|
|
|
0
|
return $out_code; |
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
############################################################################### |
486
|
|
|
|
|
|
|
## |
487
|
|
|
|
|
|
|
## PathTest base class |
488
|
|
|
|
|
|
|
## |
489
|
|
|
|
|
|
|
## This is used for all of the pieces of location paths axis tests, name |
490
|
|
|
|
|
|
|
## and type tests, predicates. It is also used by a few functions |
491
|
|
|
|
|
|
|
## that act on the result of a location path (which is effectively a |
492
|
|
|
|
|
|
|
## node set with just the current node in it). |
493
|
|
|
|
|
|
|
## |
494
|
|
|
|
|
|
|
@XFD::PathTest::ISA = qw( XFD::Op ); |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
## TODO: factor som/all of this in to possible_event_types(). |
498
|
|
|
|
|
|
|
## That could die with an error if there are no possible event types. |
499
|
|
|
|
|
|
|
## Hmmm, may also need to undo the oddness that a [] PossibleEventTypes |
500
|
|
|
|
|
|
|
## means "any" (that's according to a comment, need to verify that |
501
|
|
|
|
|
|
|
## the comment does not lie). |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
sub XFD::PathTest::check_context { |
504
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
505
|
5
|
|
|
|
|
5
|
my ( $context ) = @_; |
506
|
|
|
|
|
|
|
|
507
|
5
|
|
|
|
|
13
|
my $hash_name = ref( $self ) . "::AllowedAfterAxis"; |
508
|
|
|
|
|
|
|
|
509
|
1
|
|
|
1
|
|
7
|
no strict "refs"; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4084
|
|
510
|
5
|
|
|
|
|
30
|
die "'", $self->op_type, "' not allowed after '$context->{Axis}'\n" |
511
|
0
|
|
|
|
|
0
|
if keys %{$hash_name} |
512
|
5
|
50
|
33
|
|
|
6
|
&& exists ${$hash_name}{$context->{Axis}}; |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
## useful_event_contexts are the events that are useful for a path |
515
|
|
|
|
|
|
|
## test to be applied to. If the context does not have one of these |
516
|
|
|
|
|
|
|
## in it's PossibleEventTypes, then it's a useless (never-match) |
517
|
|
|
|
|
|
|
## expression. For now, we die(). TODO: warn, but allow the |
518
|
|
|
|
|
|
|
## warning to be silenced. |
519
|
|
|
|
|
|
|
|
520
|
5
|
50
|
33
|
|
|
42
|
if ( $self->can( "useful_event_contexts" ) |
|
5
|
|
33
|
|
|
19
|
|
521
|
|
|
|
|
|
|
&& defined $context->{PossibleEventTypes} |
522
|
|
|
|
|
|
|
&& @{$context->{PossibleEventTypes}} ## empty list = "any". |
523
|
|
|
|
|
|
|
) { |
524
|
5
|
|
|
|
|
19
|
my %possibles = map { |
525
|
5
|
|
|
|
|
11
|
( $_ => undef ); |
526
|
5
|
|
|
|
|
8
|
} @{$context->{PossibleEventTypes}}; |
527
|
|
|
|
|
|
|
|
528
|
5
|
|
|
|
|
9
|
my @not_useful; my @useful; |
529
|
|
|
|
|
|
|
|
530
|
5
|
|
|
|
|
14
|
for ( $self->useful_event_contexts ) { |
531
|
15
|
100
|
|
|
|
41
|
exists $possibles{$_} |
532
|
|
|
|
|
|
|
? push @useful, $_ |
533
|
|
|
|
|
|
|
: push @not_useful, $_; |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
#warn $context->{PossiblesSetBy}->op_type, "/", $self->op_type, " NOT USEFUL: ", join( ",", @not_useful ), " (useful: ", join( ",", @useful ), ")\n" if @not_useful; |
537
|
|
|
|
|
|
|
die |
538
|
0
|
|
|
|
|
0
|
$context->{PossiblesSetBy}->op_type, |
539
|
|
|
|
|
|
|
" (which can result in ", |
540
|
0
|
|
|
|
|
0
|
@{$context->{PossibleEventTypes}} |
541
|
0
|
|
|
|
|
0
|
? join( ", ", @{$context->{PossibleEventTypes}} ) . ( |
542
|
5
|
0
|
|
|
|
23
|
@{$context->{PossibleEventTypes}} > 1 |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
543
|
|
|
|
|
|
|
? " event contexts" |
544
|
|
|
|
|
|
|
: " event context" |
545
|
|
|
|
|
|
|
) |
546
|
|
|
|
|
|
|
: "any event context", |
547
|
|
|
|
|
|
|
") followed by ", |
548
|
|
|
|
|
|
|
$self->op_type, |
549
|
|
|
|
|
|
|
" (which only match ", |
550
|
|
|
|
|
|
|
join( ", ", $self->useful_event_contexts ), |
551
|
|
|
|
|
|
|
" event types)", |
552
|
|
|
|
|
|
|
" can never match\n" |
553
|
|
|
|
|
|
|
unless @useful; |
554
|
|
|
|
|
|
|
} |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
|
557
|
30
|
|
|
30
|
|
116
|
sub XFD::PathTest::new { shift->XFD::Op::new( @_, undef ) } |
558
|
|
|
|
|
|
|
|
559
|
0
|
|
|
0
|
|
0
|
sub XFD::PathTest::is_constant { 0 } |
560
|
0
|
|
|
0
|
|
0
|
sub XFD::PathTest::result_type { "nodeset" } |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub _next() { -1 } |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
## This next one is used by external code like the optimizer, |
565
|
|
|
|
|
|
|
## not by this module. |
566
|
45
|
|
|
45
|
|
207
|
sub XFD::PathTest::get_next { $_[0]->[_next] } |
567
|
20
|
|
|
20
|
|
49
|
sub XFD::PathTest::force_set_next { $_[0]->[_next] = $_[1] } |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
sub XFD::PathTest::optim_signature { |
570
|
5
|
|
|
5
|
|
7
|
my $self = shift; |
571
|
5
|
50
|
|
|
|
43
|
return join "", |
572
|
|
|
|
|
|
|
ref( $self ), "(", defined $self->[0] ? "'$self->[0]'" : "undef", ")"; |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
sub XFD::PathTest::set_next { |
578
|
35
|
|
|
35
|
|
47
|
my $self = shift; |
579
|
35
|
50
|
|
|
|
246
|
Carp::confess "undef!" unless defined $_[0]; |
580
|
35
|
100
|
|
|
|
253
|
if ( $self->[_next] ) { |
581
|
|
|
|
|
|
|
# Unions cause this method to be called multiple times |
582
|
|
|
|
|
|
|
# and we never want to have a loop. |
583
|
5
|
50
|
|
|
|
66
|
return if $self == $_[0]; |
584
|
5
|
50
|
|
|
|
18
|
return if $self->[_next] == $_[0]; |
585
|
5
|
50
|
|
|
|
39
|
Carp::confess "_next ($self->[_next]) can't set_next" unless $self->[_next]->can( "set_next" ); |
586
|
5
|
|
|
|
|
18
|
$self->[_next]->set_next( @_ ); |
587
|
|
|
|
|
|
|
} |
588
|
|
|
|
|
|
|
else { |
589
|
30
|
|
|
|
|
73
|
$self->[_next] = shift; |
590
|
|
|
|
|
|
|
} |
591
|
|
|
|
|
|
|
} |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
## A utility function required by node_name and namespace_test to parse |
594
|
|
|
|
|
|
|
## prefix:localname strings. |
595
|
|
|
|
|
|
|
sub XFD::PathTest::_parse_ns_uri_and_localname { |
596
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
597
|
0
|
|
|
|
|
0
|
my ( $name ) = @_; |
598
|
|
|
|
|
|
|
|
599
|
0
|
0
|
|
|
|
0
|
my ( $prefix, $local_name ) = |
600
|
|
|
|
|
|
|
$name =~ /(.*):(.*)/ |
601
|
|
|
|
|
|
|
? ( $1, $2 ) |
602
|
|
|
|
|
|
|
: ( "", $name ); |
603
|
|
|
|
|
|
|
|
604
|
0
|
0
|
|
|
|
0
|
my $uri = exists $dispatcher->{Namespaces}->{$prefix} |
|
|
0
|
|
|
|
|
|
605
|
|
|
|
|
|
|
? $dispatcher->{Namespaces}->{$prefix} |
606
|
|
|
|
|
|
|
: length $prefix |
607
|
|
|
|
|
|
|
? die "prefix '$prefix' not declared in Namespaces option\n" |
608
|
|
|
|
|
|
|
: ""; |
609
|
|
|
|
|
|
|
|
610
|
0
|
0
|
|
|
|
0
|
die "prefix '$prefix:' not defined in Namespaces option\n" |
611
|
|
|
|
|
|
|
unless defined $uri; |
612
|
|
|
|
|
|
|
|
613
|
0
|
|
|
|
|
0
|
return ( $uri, $local_name ); |
614
|
|
|
|
|
|
|
} |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
## child:: and descendant-or-self:: axes need to curry to child nodes. |
617
|
|
|
|
|
|
|
## These tests are the appropriate tests for child nodes. |
618
|
|
|
|
|
|
|
my %child_curry_tests = qw( start_element 1 comment 1 processing_instruction 1 characters 1 ); |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
## No need for DocSubs in this array; we never curry to a doc node event |
621
|
|
|
|
|
|
|
## because doc node events never occur inside other nodes. |
622
|
|
|
|
|
|
|
my @all_curry_tests = qw( start_element comment processing_instruction characters attribute namespace ); |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
## TODO: Detect when an axis tries to queue a curried test on to a particular |
625
|
|
|
|
|
|
|
## FooSubs, and that test is incompatible with the axis. Not sure how |
626
|
|
|
|
|
|
|
## important that is, but I wanted to note it here for later thought. |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
sub XFD::PathTest::curry_tests { |
629
|
|
|
|
|
|
|
## we assume that there will *always* be a node test after an axis. |
630
|
|
|
|
|
|
|
## This is a property of the grammar. |
631
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
632
|
0
|
|
|
|
|
0
|
my $next = $self->[_next]; |
633
|
0
|
0
|
|
|
|
0
|
Carp::confess "$self does not have a next" unless defined $next; |
634
|
0
|
|
|
|
|
0
|
return $next->curry_tests; |
635
|
|
|
|
|
|
|
} |
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
|
639
|
|
|
|
|
|
|
sub XFD::PathTest::insert_next_in_to_template { |
640
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
641
|
5
|
|
|
|
|
10
|
my ( $template, $next_code ) = @_; |
642
|
|
|
|
|
|
|
|
643
|
5
|
|
|
|
|
23
|
my ( $preamble, $postamble ) = split //, $template, 2; |
644
|
5
|
50
|
|
|
|
20
|
return $preamble unless defined $postamble; |
645
|
|
|
|
|
|
|
|
646
|
5
|
50
|
|
|
|
244
|
if ( _indentomatic && $preamble =~ s/( *)(?!\n)\Z// ) { |
647
|
5
|
|
|
|
|
30
|
_indent $next_code for 1.. length( $1 ) / 2 |
648
|
|
|
|
|
|
|
} |
649
|
5
|
|
|
|
|
67
|
return join $next_code, $preamble, $postamble; |
650
|
|
|
|
|
|
|
} |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
sub XFD::PathTest::possible_event_types { |
654
|
5
|
|
|
5
|
|
7
|
my $self = shift; |
655
|
5
|
|
|
|
|
7
|
my ( $context ) = @_; |
656
|
|
|
|
|
|
|
|
657
|
5
|
|
|
|
|
15
|
my $possibles = $self->possible_event_type_map( @_ ); |
658
|
|
|
|
|
|
|
|
659
|
5
|
|
|
|
|
6
|
my %seen; |
660
|
5
|
|
|
|
|
25
|
my @possibles = grep !$seen{$_}++, |
661
|
5
|
|
|
|
|
20
|
map exists $possibles->{$_} ? @{$possibles->{$_}} : (), |
662
|
5
|
50
|
|
|
|
8
|
@{$context->{PossibleEventTypes}}; |
663
|
|
|
|
|
|
|
|
664
|
5
|
|
|
|
|
28
|
return @possibles; |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
## "Incremental code" gets evaluated SAX event by SAX event, currying it's |
668
|
|
|
|
|
|
|
## results until future events are received if need be. |
669
|
|
|
|
|
|
|
sub XFD::PathTest::as_incr_code { |
670
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
671
|
5
|
|
|
|
|
7
|
my ( $context ) = @_; |
672
|
|
|
|
|
|
|
|
673
|
5
|
|
|
|
|
16
|
$self->check_context( $context ); |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
## This is the moral equivalent to the principal node type |
676
|
|
|
|
|
|
|
## from XPath. Always set by axes. |
677
|
5
|
50
|
|
|
|
28
|
local $context->{PrincipalEventType} = $self->principal_event_type |
678
|
|
|
|
|
|
|
if $self->can( "principal_event_type" ); |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
## These are the types of events that can make it through a |
681
|
|
|
|
|
|
|
## path test to the next test. Usually (always?) set by axes. |
682
|
|
|
|
|
|
|
## right now an empty array means "any". |
683
|
|
|
|
|
|
|
## TODO: make sure this is set as accurately as possible; the |
684
|
|
|
|
|
|
|
## more accurately this is set, the more often we can give |
685
|
|
|
|
|
|
|
## helpful errors. |
686
|
|
|
|
|
|
|
## For instance, in non-currying axes, the current set of |
687
|
|
|
|
|
|
|
## possibles needs to be intersected with this axis' set |
688
|
|
|
|
|
|
|
## of possibles. |
689
|
5
|
|
|
|
|
17
|
my $set_possibles = $self->can( "possible_event_type_map" ); |
690
|
|
|
|
|
|
|
#warn $self->op_type, ",", $set_possibles; |
691
|
5
|
50
|
|
|
|
34
|
local $context->{PossibleEventTypes} = [ $self->possible_event_types( @_ ) ] |
692
|
|
|
|
|
|
|
if $set_possibles; |
693
|
5
|
50
|
|
|
|
19
|
local $context->{PossiblesSetBy} = $self |
694
|
|
|
|
|
|
|
if $set_possibles; |
695
|
5
|
50
|
33
|
|
|
15
|
confess "BUG: No _next op and no ActionCode" |
696
|
|
|
|
|
|
|
unless $self->[_next] || $context->{ActionCode}; |
697
|
|
|
|
|
|
|
|
698
|
5
|
50
|
|
|
|
15
|
$self->insert_next_in_to_template( |
699
|
|
|
|
|
|
|
$self->incr_code_template( $context ), |
700
|
|
|
|
|
|
|
$self->[_next] |
701
|
|
|
|
|
|
|
? $self->[_next]->as_incr_code( $context ) |
702
|
|
|
|
|
|
|
: $context->{ActionCode} |
703
|
|
|
|
|
|
|
); |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
## "Immediate code" gets evaluated as the expression is evaluated, so |
708
|
|
|
|
|
|
|
## it must perform DOM walking (we have only a minimal DOM: non-children |
709
|
|
|
|
|
|
|
## of elt nodes: attrs and namespace nodes). |
710
|
|
|
|
|
|
|
## |
711
|
|
|
|
|
|
|
## ARRAY actions are only possible when handed in from outside. Since |
712
|
|
|
|
|
|
|
## immediate code is only used inside function parameters and predicates, |
713
|
|
|
|
|
|
|
## it should be impossible for now to see an ARRAY action here. |
714
|
|
|
|
|
|
|
## |
715
|
|
|
|
|
|
|
sub XFD::PathTest::as_immed_code { |
716
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
717
|
|
|
|
|
|
|
|
718
|
0
|
0
|
|
|
|
0
|
return $self->insert_next_in_to_template( |
719
|
|
|
|
|
|
|
$self->immed_code_template( @_ ), |
720
|
|
|
|
|
|
|
$self->[_next] ? $self->[_next]->as_immed_code( @_ ) : "" |
721
|
|
|
|
|
|
|
); |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
sub XFD::PathTest::immed_code_template { |
726
|
|
|
|
|
|
|
## Some axes (forward and descendant) need to be precursorized |
727
|
|
|
|
|
|
|
## when in function calls and expressions. munge_parms catches |
728
|
|
|
|
|
|
|
## this and does the precursorization shuffle. |
729
|
0
|
|
|
0
|
|
0
|
die "precursorize THIS\n"; |
730
|
|
|
|
|
|
|
} |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
############################################################################### |
733
|
|
|
|
|
|
|
## An ExprEval masqeurades as a PathTest so it can be slapped on to the |
734
|
|
|
|
|
|
|
## end of a PathTest. But really, it evaluates the expression and saves |
735
|
|
|
|
|
|
|
## the result, then fires the action code. |
736
|
|
|
|
|
|
|
@XFD::ExprEval::ISA = qw( XFD::PathTest ); |
737
|
|
|
|
|
|
|
sub XFD::ExprEval::as_incr_code { |
738
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
739
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
740
|
|
|
|
|
|
|
|
741
|
0
|
|
|
|
|
0
|
my $boolerizer = ""; |
742
|
0
|
0
|
|
|
|
0
|
$boolerizer = " ? true : false" |
743
|
|
|
|
|
|
|
if $self->[0]->result_type eq "boolean"; |
744
|
|
|
|
|
|
|
|
745
|
0
|
|
|
|
|
0
|
my $action_ops = $self->[_next]; |
746
|
|
|
|
|
|
|
|
747
|
0
|
|
|
|
|
0
|
my $action_id = $action_ops->action_id; |
748
|
|
|
|
|
|
|
|
749
|
0
|
|
|
|
|
0
|
local $context->{SetXValuesEntry} = 1; |
750
|
|
|
|
|
|
|
|
751
|
0
|
|
|
|
|
0
|
my $expr_code = get_expr_code( "", $self->[0], <[_next], undef, @_ ); |
752
|
|
|
|
|
|
|
## expression evaluation |
753
|
|
|
|
|
|
|
\$ctx->{XValues}->[$action_id] = $boolerizer; |
754
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: xvalue set to '\$ctx->{XValues}->[$action_id]' for event ", _ev \$ctx if is_tracing; |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
# end expression evaluation |
757
|
|
|
|
|
|
|
CODE_END |
758
|
|
|
|
|
|
|
|
759
|
0
|
|
|
|
|
0
|
return $expr_code; |
760
|
|
|
|
|
|
|
} |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
############################################################################### |
763
|
|
|
|
|
|
|
## |
764
|
|
|
|
|
|
|
## Actions |
765
|
|
|
|
|
|
|
## |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
## If the action is in an op tree that's being precursorized, it needs |
768
|
|
|
|
|
|
|
## to return an alternate bit of Perl code (one that sets the precursor) |
769
|
|
|
|
|
|
|
## and queue up the action code to be run when enough precursors are |
770
|
|
|
|
|
|
|
## defined and the expression is true. |
771
|
|
|
|
|
|
|
@XFD::Action::ISA = qw( XFD::Op ); |
772
|
0
|
|
|
0
|
|
0
|
sub XFD::Action::result_type { Carp::confess "Actions have no result types" } |
773
|
0
|
|
|
0
|
|
0
|
sub XFD::Action::is_constant { 0 } |
774
|
0
|
|
|
0
|
|
0
|
sub XFD::Action::curry_tests { return @all_curry_tests } |
775
|
|
|
|
|
|
|
|
776
|
5
|
|
|
5
|
|
125
|
sub XFD::Action::action_code { return shift->[0]->{Code} } |
777
|
9
|
|
|
9
|
|
27
|
sub XFD::Action::action_id { return shift->[0]->{Id} } |
778
|
6
|
|
|
6
|
|
14
|
sub XFD::Action::action_score { return shift->[0]->{Score} } |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
sub XFD::Action::fixup { |
781
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
782
|
5
|
|
|
|
|
8
|
my ( $context ) = @_; |
783
|
5
|
|
|
|
|
23
|
$self->[0]->{DelayToEnd} = $context->{DelayToEnd}; |
784
|
|
|
|
|
|
|
} |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
sub XFD::Action::gate_action { |
787
|
5
|
|
|
5
|
|
6
|
my $self = shift; |
788
|
5
|
|
|
|
|
6
|
my $action_code = shift; |
789
|
5
|
|
|
|
|
7
|
my ( $context ) = @_; |
790
|
|
|
|
|
|
|
|
791
|
5
|
|
|
|
|
15
|
my $id = $self->action_id; |
792
|
5
|
|
|
|
|
15
|
my $score = $self->action_score; |
793
|
|
|
|
|
|
|
|
794
|
5
|
50
|
33
|
|
|
26
|
my ( $now_or_later, $s ) = |
795
|
|
|
|
|
|
|
$self->[0]->{DelayToEnd} && ! $context->{IgnoreDelayToEnd} |
796
|
|
|
|
|
|
|
? ( "PendingEndActions", "pending end action" ) |
797
|
|
|
|
|
|
|
: ( "PendingActions", "pending action" ); |
798
|
|
|
|
|
|
|
|
799
|
5
|
100
|
|
|
|
13
|
unless ( $context->{CallActionDirectly} ) { |
800
|
1
|
|
|
|
|
4
|
_indent $action_code if _indentomatic; |
801
|
1
|
|
|
|
|
4
|
$action_code = <
|
802
|
|
|
|
|
|
|
sub { ## action |
803
|
|
|
|
|
|
|
$action_code} |
804
|
|
|
|
|
|
|
CODE_END |
805
|
|
|
|
|
|
|
} |
806
|
|
|
|
|
|
|
|
807
|
5
|
|
|
|
|
20
|
$action_code = <
|
808
|
|
|
|
|
|
|
emit_trace_SAX_message "adding $s $score for event ", _ev \$ctx if is_tracing; |
809
|
|
|
|
|
|
|
push \@{\$ctx->{$now_or_later}->{$score}}, $action_code; |
810
|
|
|
|
|
|
|
CODE_END |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
|
813
|
5
|
50
|
|
|
|
14
|
if ( defined $context->{action_wrapper} ) { |
814
|
0
|
|
|
|
|
0
|
my $foo = $context->{action_wrapper}; |
815
|
0
|
|
|
|
|
0
|
_replace_NEXT $foo, $action_code, ""; |
816
|
0
|
|
|
|
|
0
|
$action_code = $foo; |
817
|
|
|
|
|
|
|
} |
818
|
|
|
|
|
|
|
|
819
|
5
|
50
|
|
|
|
36
|
return $action_code unless defined $context->{precursorize_action}; |
820
|
|
|
|
|
|
|
|
821
|
0
|
|
|
|
|
0
|
push @{$context->{precursorized_action_codes}}, $action_code; |
|
0
|
|
|
|
|
0
|
|
822
|
0
|
|
|
|
|
0
|
return $context->{precursorize_action}; |
823
|
|
|
|
|
|
|
} |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
########## |
827
|
|
|
|
|
|
|
@XFD::Action::PerlCode::ISA = qw( XFD::Action ); |
828
|
|
|
|
|
|
|
sub XFD::Action::PerlCode::as_incr_code { |
829
|
4
|
|
|
4
|
|
8
|
my $self = shift; |
830
|
4
|
|
|
|
|
7
|
my ( $context ) = @_; |
831
|
4
|
50
|
|
|
|
9
|
Carp::confess unless @_; |
832
|
4
|
|
|
|
|
15
|
my $action_code = $self->action_code; |
833
|
|
|
|
|
|
|
|
834
|
4
|
|
|
|
|
17
|
my $action_id = $self->action_id; |
835
|
|
|
|
|
|
|
|
836
|
4
|
|
|
|
|
7
|
my $xvalue_expr = ""; |
837
|
4
|
50
|
|
|
|
14
|
if ( $dispatcher->{SetXValue} ) { |
838
|
0
|
0
|
|
|
|
0
|
$xvalue_expr = $context->{SetXValuesEntry} |
839
|
|
|
|
|
|
|
? "local \$d->{XValue} = \$ctx->{XValues}->[$action_id];\n" |
840
|
|
|
|
|
|
|
: "local \$d->{XValue} = \$ctx->{Node};\n"; |
841
|
|
|
|
|
|
|
} |
842
|
|
|
|
|
|
|
|
843
|
4
|
50
|
|
|
|
13
|
local $context->{CallActionDirectly} = 1 |
844
|
|
|
|
|
|
|
unless length $xvalue_expr; |
845
|
4
|
50
|
|
|
|
30
|
$action_code =~ s/->\(\s*\@_\s*\)// |
846
|
|
|
|
|
|
|
unless length $xvalue_expr; |
847
|
|
|
|
|
|
|
|
848
|
4
|
|
|
|
|
20
|
return $self->gate_action( "$xvalue_expr$action_code", $context ) ; |
849
|
|
|
|
|
|
|
} |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
sub XFD::Action::PerlCode::as_immed_code { |
852
|
0
|
|
|
0
|
|
0
|
goto \&XFD::Action::PerlCode::as_incr_code; |
853
|
|
|
|
|
|
|
} |
854
|
|
|
|
|
|
|
########## |
855
|
|
|
|
|
|
|
@XFD::SubRules::ISA = qw( XFD::Op ); |
856
|
|
|
|
|
|
|
sub XFD::SubRules::curry_tests { |
857
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
858
|
|
|
|
|
|
|
|
859
|
0
|
|
|
|
|
0
|
my %tests; |
860
|
|
|
|
|
|
|
|
861
|
0
|
|
|
|
|
0
|
for ( @$self ) { |
862
|
0
|
|
|
|
|
0
|
for ( $_->curry_tests ) { |
863
|
0
|
|
|
|
|
0
|
$tests{$_} = undef; |
864
|
|
|
|
|
|
|
} |
865
|
|
|
|
|
|
|
} |
866
|
|
|
|
|
|
|
|
867
|
0
|
|
|
|
|
0
|
return keys %tests; |
868
|
|
|
|
|
|
|
} |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
sub XFD::SubRules::as_incr_code { |
871
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
872
|
|
|
|
|
|
|
|
873
|
0
|
|
|
|
|
0
|
my @code; |
874
|
0
|
|
|
|
|
0
|
my $i = 0; |
875
|
0
|
|
|
|
|
0
|
for ( @$self ) { |
876
|
0
|
|
|
|
|
0
|
my $code = $_->as_incr_code( @_ ); |
877
|
0
|
|
|
|
|
0
|
_indent $code if _indentomatic; |
878
|
0
|
|
|
|
|
0
|
push @code, "## SubRule $i\n$code## end SubRule $i\n"; |
879
|
0
|
|
|
|
|
0
|
++$i; |
880
|
|
|
|
|
|
|
} |
881
|
0
|
|
|
|
|
0
|
join "", @code; |
882
|
|
|
|
|
|
|
} |
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
sub XFD::SubRules::as_immed_code { |
885
|
0
|
|
|
0
|
|
0
|
die "The result of an EventPath expression cannot be forwarded to sub rules\n"; |
886
|
|
|
|
|
|
|
} |
887
|
|
|
|
|
|
|
########## |
888
|
|
|
|
|
|
|
@XFD::Action::EventForwarder::ISA = qw( XFD::Action ); |
889
|
|
|
|
|
|
|
sub XFD::Action::EventForwarder::as_incr_code { |
890
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
891
|
1
|
|
|
|
|
2
|
my ( $context ) = @_; |
892
|
1
|
50
|
|
|
|
4
|
Carp::confess unless @_; |
893
|
|
|
|
|
|
|
|
894
|
1
|
|
|
|
|
9
|
my $new_handler_expr = $self->action_code; |
895
|
1
|
|
|
|
|
9
|
my $action_score = $self->action_score; |
896
|
|
|
|
|
|
|
|
897
|
1
|
|
|
|
|
7
|
my $forward_end_event_too = |
898
|
1
|
|
|
|
|
2
|
grep /^start_/, @{$context->{PossibleEventTypes}}; |
899
|
|
|
|
|
|
|
|
900
|
1
|
|
|
|
|
3
|
my $end_event_forwarding_code = ""; |
901
|
1
|
50
|
|
|
|
4
|
if ( $forward_end_event_too ) { |
902
|
1
|
|
|
|
|
4
|
$end_event_forwarding_code = <
|
903
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing end_ action for \$event_type event ", _ev \$ctx if is_tracing; |
904
|
|
|
|
|
|
|
push \@{\$ctx->{PendingEndActions}->{$action_score}}, sub { |
905
|
|
|
|
|
|
|
emit_trace_SAX_message "EndSub end_ action for ", _ev \$ctx if is_tracing; |
906
|
|
|
|
|
|
|
my \$h = $new_handler_expr; |
907
|
|
|
|
|
|
|
my \$event_type = \$ctx->{EventType}; |
908
|
|
|
|
|
|
|
\$d->{LastHandlerResult} = \$h->\$event_type( \$ctx->{Node} ); |
909
|
|
|
|
|
|
|
}; |
910
|
|
|
|
|
|
|
CODE_END |
911
|
|
|
|
|
|
|
|
912
|
1
|
50
|
|
|
|
3
|
if ( grep !/^start_/, @{$context->{PossibleEventTypes}} ) { |
|
1
|
|
|
|
|
7
|
|
913
|
0
|
|
|
|
|
0
|
_indent $end_event_forwarding_code if _indentomatic; |
914
|
0
|
|
|
|
|
0
|
$end_event_forwarding_code = <
|
915
|
|
|
|
|
|
|
if ( substr( \$event_type, 0, 6 ) eq "start_" ) { |
916
|
|
|
|
|
|
|
$end_event_forwarding_code } |
917
|
|
|
|
|
|
|
CODE_END |
918
|
|
|
|
|
|
|
} |
919
|
|
|
|
|
|
|
} |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
## TODO: only forward end events if this op's not in start-element:: |
922
|
|
|
|
|
|
|
## or end-element:: context and is intercepting a start_document or |
923
|
|
|
|
|
|
|
## start_element. |
924
|
1
|
|
|
|
|
11
|
return $self->gate_action( <
|
925
|
|
|
|
|
|
|
{ |
926
|
|
|
|
|
|
|
my \$event_type = \$ctx->{EventType}; |
927
|
|
|
|
|
|
|
my \$h = $new_handler_expr; |
928
|
|
|
|
|
|
|
|
929
|
|
|
|
|
|
|
if ( ! \$d->{DocStartedFlags}->{\$h} ) { |
930
|
|
|
|
|
|
|
\$d->{DocStartedFlags}->{\$h} = 1; |
931
|
|
|
|
|
|
|
if ( \$event_type ne "start_document" |
932
|
|
|
|
|
|
|
&& ! \$d->{SuppressAutoStartDocument} |
933
|
|
|
|
|
|
|
) { |
934
|
|
|
|
|
|
|
push \@{\$d->{AutoStartedHandlers}}, \$h; |
935
|
|
|
|
|
|
|
\$h->start_document( {} ); |
936
|
|
|
|
|
|
|
} |
937
|
|
|
|
|
|
|
} |
938
|
|
|
|
|
|
|
|
939
|
|
|
|
|
|
|
\$d->{LastHandlerResult} = \$h->\$event_type( \$ctx->{Node} ); |
940
|
|
|
|
|
|
|
$end_event_forwarding_code} |
941
|
|
|
|
|
|
|
CODE_END |
942
|
|
|
|
|
|
|
} |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
sub XFD::Action::EventForwarder::as_immed_code { |
945
|
|
|
|
|
|
|
## TODO: make it so node-set returning functions can be. |
946
|
|
|
|
|
|
|
## TODO: Allow other things to be forwarded as characters() |
947
|
0
|
|
|
0
|
|
0
|
die "The result of an EventPath expression cannot be forwarded to a SAX handler\n"; |
948
|
|
|
|
|
|
|
} |
949
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
########## |
951
|
|
|
|
|
|
|
@XFD::Action::EventCutter::ISA = qw( XFD::Action ); |
952
|
|
|
|
|
|
|
sub XFD::Action::EventCutter::as_incr_code { |
953
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
954
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
955
|
|
|
|
|
|
|
|
956
|
0
|
|
|
|
|
0
|
my $cut_list_expr = $self->action_code; |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
## TODO: only forward trees if this op's not in start-element:: |
959
|
|
|
|
|
|
|
## or end-element:: context and is intercepting a start_document or |
960
|
|
|
|
|
|
|
## start_element. |
961
|
0
|
|
|
|
|
0
|
return $self->gate_action( <
|
962
|
|
|
|
|
|
|
if ( is_tracing ) { |
963
|
|
|
|
|
|
|
my \$c = $cut_list_expr; |
964
|
|
|
|
|
|
|
for my \$h ( \@\$c ) { |
965
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: cutting from handler \$h" if is_tracing; |
966
|
|
|
|
|
|
|
} |
967
|
|
|
|
|
|
|
} |
968
|
|
|
|
|
|
|
CODE_END |
969
|
|
|
|
|
|
|
} |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
sub XFD::Action::EventCutter::as_immed_code { |
972
|
|
|
|
|
|
|
## TODO: make it so node-set returning functions can be. |
973
|
|
|
|
|
|
|
## TODO: Allow other things to be forwarded as characters() |
974
|
0
|
|
|
0
|
|
0
|
die "The result of an EventPath expression cannot be forwarded to a SAX handler\n"; |
975
|
|
|
|
|
|
|
} |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
########## |
978
|
|
|
|
|
|
|
sub action { |
979
|
5
|
|
|
5
|
|
47
|
my $action = shift; |
980
|
|
|
|
|
|
|
|
981
|
5
|
|
|
|
|
11
|
my $action_type = ref $action ; |
982
|
|
|
|
|
|
|
|
983
|
5
|
50
|
|
|
|
14
|
if ( $action_type eq "ARRAY" ) { |
984
|
|
|
|
|
|
|
## It's s nested list of rules. |
985
|
0
|
|
|
|
|
0
|
my @rules = @$action; |
986
|
|
|
|
|
|
|
|
987
|
0
|
0
|
|
|
|
0
|
die "Odd number of elements in action ARRAY\n" |
988
|
|
|
|
|
|
|
if @rules % 1; |
989
|
|
|
|
|
|
|
|
990
|
0
|
|
|
|
|
0
|
my @action_ops; |
991
|
0
|
|
|
|
|
0
|
while ( @rules ) { |
992
|
0
|
|
|
|
|
0
|
my ( $expr, $action ) = ( shift @rules, shift @rules ); |
993
|
0
|
|
|
|
|
0
|
push @action_ops, XML::Filter::Dispatcher::Parser->_parse( |
994
|
|
|
|
|
|
|
$expr, |
995
|
|
|
|
|
|
|
$action, |
996
|
|
|
|
|
|
|
$dispatcher, ## TODO: pass options here. |
997
|
|
|
|
|
|
|
); |
998
|
|
|
|
|
|
|
} |
999
|
|
|
|
|
|
|
|
1000
|
0
|
|
|
|
|
0
|
return XFD::SubRules->new( @action_ops ); |
1001
|
|
|
|
|
|
|
} |
1002
|
|
|
|
|
|
|
|
1003
|
|
|
|
|
|
|
## It's a real action, not a set of subrules. |
1004
|
|
|
|
|
|
|
|
1005
|
5
|
|
|
|
|
8
|
push @{$dispatcher->{Actions}}, my $a_hash = {}; |
|
5
|
|
|
|
|
17
|
|
1006
|
5
|
|
|
|
|
8
|
my $action_num = $#{$dispatcher->{Actions}}; |
|
5
|
|
|
|
|
12
|
|
1007
|
5
|
|
|
|
|
14
|
$a_hash->{Id} = $action_num; |
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
## TODO: Allow a HASH to be passed in so the caller can set the score |
1010
|
|
|
|
|
|
|
## directly, or perhaps set a score increment. |
1011
|
5
|
|
|
|
|
10
|
$a_hash->{Score} = $action_num; |
1012
|
|
|
|
|
|
|
|
1013
|
5
|
50
|
|
|
|
13
|
if ( ! defined $action ) { |
1014
|
0
|
|
|
|
|
0
|
$a_hash->{Code} = "sub {}"; |
1015
|
0
|
|
|
|
|
0
|
return XFD::Action::PerlCode->new( $a_hash ), |
1016
|
|
|
|
|
|
|
} |
1017
|
|
|
|
|
|
|
|
1018
|
5
|
100
|
|
|
|
14
|
if ( $action_type eq "SCALAR" ) { |
1019
|
2
|
50
|
|
|
|
7
|
$a_hash->{Code} = defined $action ? $action : "undef"; |
1020
|
2
|
|
|
|
|
4
|
$a_hash->{IsInlineCode} = 1; |
1021
|
2
|
|
|
|
|
8
|
return XFD::Action::PerlCode->new( $a_hash ), |
1022
|
|
|
|
|
|
|
} |
1023
|
|
|
|
|
|
|
|
1024
|
3
|
100
|
|
|
|
8
|
if ( !$action_type ) { |
1025
|
1
|
|
|
|
|
2
|
my $handler_name = $action; |
1026
|
|
|
|
|
|
|
# die "Unknown handler name '$handler_name', ", |
1027
|
|
|
|
|
|
|
# keys %{$dispatcher->{Handlers}} |
1028
|
|
|
|
|
|
|
# ? ( |
1029
|
|
|
|
|
|
|
# "known handlers: ", |
1030
|
|
|
|
|
|
|
# join ", ", map "'$_'", |
1031
|
|
|
|
|
|
|
# keys %{$dispatcher->{Handlers}} |
1032
|
|
|
|
|
|
|
# ) |
1033
|
|
|
|
|
|
|
# : "no handlers were set in constructor call", |
1034
|
|
|
|
|
|
|
# "\n" |
1035
|
|
|
|
|
|
|
# unless exists $dispatcher->{Handlers}->{$handler_name}; |
1036
|
|
|
|
|
|
|
|
1037
|
1
|
|
|
|
|
5
|
$handler_name =~ s/([\\'])/\\$1/g; |
1038
|
|
|
|
|
|
|
|
1039
|
1
|
|
|
|
|
6
|
$a_hash->{Code} = "\$d->{Handlers}->{'$handler_name'}"; |
1040
|
|
|
|
|
|
|
|
1041
|
1
|
|
|
|
|
14
|
return XFD::Action::EventForwarder->new( $a_hash ); |
1042
|
|
|
|
|
|
|
} |
1043
|
|
|
|
|
|
|
|
1044
|
2
|
50
|
|
|
|
7
|
if ( $action_type eq "CODE" ) { |
1045
|
|
|
|
|
|
|
## It's a code ref, arrange for it to be called |
1046
|
|
|
|
|
|
|
## directly. |
1047
|
2
|
|
|
|
|
4
|
$a_hash->{CodeRef} = $action; |
1048
|
2
|
|
|
|
|
9
|
$a_hash->{Code} = |
1049
|
|
|
|
|
|
|
"\$d->{Actions}->[$action_num]->{CodeRef}->( \@_ )"; |
1050
|
2
|
|
|
|
|
17
|
return XFD::Action::PerlCode->new( $a_hash ); |
1051
|
|
|
|
|
|
|
} |
1052
|
|
|
|
|
|
|
|
1053
|
0
|
0
|
0
|
|
|
0
|
if ( |
|
|
|
0
|
|
|
|
|
1054
|
|
|
|
|
|
|
## Crude way of eliminating most common ref types and deciding |
1055
|
|
|
|
|
|
|
## that the action is a blessed object. |
1056
|
|
|
|
|
|
|
$action_type ne "HASH" |
1057
|
|
|
|
|
|
|
&& $action_type ne "REF" |
1058
|
|
|
|
|
|
|
&& $action_type ne "Regexp" |
1059
|
|
|
|
|
|
|
) { |
1060
|
|
|
|
|
|
|
## Must be a SAX handler, make up some action code to |
1061
|
|
|
|
|
|
|
## install it and arrange for it's removal. |
1062
|
0
|
|
|
|
|
0
|
$a_hash->{Handler} = $action; |
1063
|
0
|
|
|
|
|
0
|
$a_hash->{Code} = "\$d->{Actions}->[$action_num]->{Handler}"; |
1064
|
0
|
|
|
|
|
0
|
return XFD::Action::EventForwarder->new( $a_hash ); |
1065
|
|
|
|
|
|
|
} |
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
confess |
1068
|
0
|
|
|
|
|
0
|
"action is a ", ref $action, " ref, not a SCALAR or ARRAY ref."; |
1069
|
|
|
|
|
|
|
} |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
############################################################################### |
1074
|
|
|
|
|
|
|
## |
1075
|
|
|
|
|
|
|
## Misc |
1076
|
|
|
|
|
|
|
## |
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
## When an expression has been precursorized, it needs to run the |
1079
|
|
|
|
|
|
|
## relative path precursors wherever the expression was to be run, |
1080
|
|
|
|
|
|
|
## when enough precursors are satisfied, then the expression can |
1081
|
|
|
|
|
|
|
## run. This happens in predicates and when a function call or |
1082
|
|
|
|
|
|
|
## math/logical operator (not union) is the main expression. |
1083
|
|
|
|
|
|
|
$f::indent = 0; ## DEBUG ONLY |
1084
|
|
|
|
|
|
|
sub get_expr_code { ## TODO: rename this |
1085
|
0
|
|
|
0
|
|
0
|
my ( $is_predicate, $expr, $action_template, $action_ops, $path_remainder, $context ) = @_; |
1086
|
|
|
|
|
|
|
## if defined path_remainder, then it's a predicate expression |
1087
|
|
|
|
|
|
|
## otherwise, it's a top level expression. |
1088
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
## The action template is what needs to happen with the results of |
1090
|
|
|
|
|
|
|
## the expression. It has a macro where the expression result |
1091
|
|
|
|
|
|
|
## must be evaluated and a tag that gets replaced with the |
1092
|
|
|
|
|
|
|
## actual operation (which may end up being the actual action, or it |
1093
|
|
|
|
|
|
|
## may code to satisfy a postponement). |
1094
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
## Localize Precursors. If the expression requires precursors |
1096
|
|
|
|
|
|
|
## to be run, then converting it to immediate code will add them to |
1097
|
|
|
|
|
|
|
## Precursors. |
1098
|
|
|
|
|
|
|
#warn "## it's a predicate\n" if $is_predicate; |
1099
|
0
|
|
|
|
|
0
|
local $context->{Precursors}; |
1100
|
|
|
|
|
|
|
|
1101
|
0
|
|
|
|
|
0
|
my $expr_code = $expr->as_immed_code( $context ); |
1102
|
|
|
|
|
|
|
|
1103
|
0
|
0
|
|
|
|
0
|
my $action_code = $is_predicate ? <
|
1104
|
|
|
|
|
|
|
if ( ) { |
1105
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: predicate postponement ", _po \$postponement, " MATCHED!" if is_tracing; |
1106
|
|
|
|
|
|
|
} |
1107
|
|
|
|
|
|
|
END_PREDICATE_TEMPLATE |
1108
|
|
|
|
|
|
|
|
1109
|
0
|
|
|
|
|
0
|
_replace_NEXT $action_code, $expr_code, ""; |
1110
|
0
|
0
|
|
|
|
0
|
_replace_NEXT $action_code, $action_ops->as_incr_code( $context ) |
1111
|
|
|
|
|
|
|
if $action_ops; |
1112
|
|
|
|
|
|
|
|
1113
|
0
|
0
|
|
|
|
0
|
unless ( $context->{Precursors} ) { |
1114
|
0
|
0
|
|
|
|
0
|
_replace_NEXT $action_code, $path_remainder->as_incr_code( $context ) |
1115
|
|
|
|
|
|
|
if $is_predicate; |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
## Return an immediate expression if no precursors were added. |
1118
|
0
|
|
|
|
|
0
|
return $action_code |
1119
|
|
|
|
|
|
|
} |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
## Some part of the expression was precursorized. inline all |
1122
|
|
|
|
|
|
|
## relative precursors. |
1123
|
|
|
|
|
|
|
#{ |
1124
|
|
|
|
|
|
|
# warn "## precursorized\n"; |
1125
|
|
|
|
|
|
|
# my $c = $expr_code; |
1126
|
|
|
|
|
|
|
# _indent $c for 0..$f::indent+1; |
1127
|
|
|
|
|
|
|
# chomp $c; |
1128
|
|
|
|
|
|
|
# warn " expr_code:\n$c\n"; |
1129
|
|
|
|
|
|
|
# my $a = $action_code; |
1130
|
|
|
|
|
|
|
# chomp $a; |
1131
|
|
|
|
|
|
|
# _indent $a for 0..$f::indent+1; |
1132
|
|
|
|
|
|
|
# warn " action_code:\n$a\n"; |
1133
|
|
|
|
|
|
|
#} |
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
## Take any precursors and set them up to run right after the |
1136
|
|
|
|
|
|
|
## postponement is initialized. |
1137
|
0
|
|
|
|
|
0
|
my @inline_precursor_codes; |
1138
|
|
|
|
|
|
|
|
1139
|
0
|
|
|
|
|
0
|
my %precursor_context = %$context; |
1140
|
0
|
|
|
|
|
0
|
for my $precursor_number ( 0..$#{$context->{Precursors}} ) { |
|
0
|
|
|
|
|
0
|
|
1141
|
0
|
0
|
|
|
|
0
|
if ( _is_rel_path $context->{Precursors}->[$precursor_number] ) { |
1142
|
0
|
|
|
|
|
0
|
my $code = $context->{Precursors}->[$precursor_number]->as_incr_code( |
1143
|
|
|
|
|
|
|
\%precursor_context |
1144
|
|
|
|
|
|
|
); |
1145
|
0
|
|
|
|
|
0
|
_indent $code if _indentomatic; |
1146
|
0
|
|
|
|
|
0
|
push @inline_precursor_codes, |
1147
|
|
|
|
|
|
|
"\n## relative precursor $precursor_number\n$code"; |
1148
|
0
|
|
|
|
|
0
|
undef $context->{Precursors}->[$precursor_number]; |
1149
|
|
|
|
|
|
|
} |
1150
|
|
|
|
|
|
|
} |
1151
|
|
|
|
|
|
|
|
1152
|
0
|
|
|
|
|
0
|
my $postponement_init_code; |
1153
|
|
|
|
|
|
|
|
1154
|
0
|
0
|
|
|
|
0
|
if ( $is_predicate ) { |
1155
|
|
|
|
|
|
|
## It's a predicate |
1156
|
0
|
0
|
|
|
|
0
|
my $leftmost = ! defined $context->{precursorize_action} |
1157
|
|
|
|
|
|
|
? " leftmost" |
1158
|
|
|
|
|
|
|
: ""; |
1159
|
|
|
|
|
|
|
|
1160
|
0
|
|
|
|
|
0
|
_indent $action_code if _indentomatic; |
1161
|
0
|
|
|
|
|
0
|
_indent $action_code if _indentomatic; |
1162
|
0
|
0
|
|
|
|
0
|
$postponement_init_code = $leftmost ? <
|
1163
|
|
|
|
|
|
|
\$postponement = [ undef ]; ## Leftmost predicate, no parent to report to |
1164
|
|
|
|
|
|
|
LEFTMOST_END |
1165
|
|
|
|
|
|
|
\$postponement = [ \$postponement ]; ## Refer to parent postponement |
1166
|
|
|
|
|
|
|
CODE_END |
1167
|
|
|
|
|
|
|
## TODO: Only add the push EndSubs code if there |
1168
|
|
|
|
|
|
|
## are s to perform |
1169
|
|
|
|
|
|
|
## TODO: Figure out what to perform if this is a |
1170
|
|
|
|
|
|
|
## predicate expression with no $path_remaining. This can |
1171
|
|
|
|
|
|
|
## happen in a pattern like "a[b[c]]"; the "b[c]" predicate |
1172
|
|
|
|
|
|
|
## has no $path_remaining. It *should* refer the results of |
1173
|
|
|
|
|
|
|
## its postponement (whether or not a was found) back up |
1174
|
|
|
|
|
|
|
## to the parent postponement; probably by being in the |
1175
|
|
|
|
|
|
|
## context of the implicit boolean() wrapped around it by |
1176
|
|
|
|
|
|
|
## the a[] predicate. See a commented out test in |
1177
|
|
|
|
|
|
|
## t/postponements.t for an example. |
1178
|
0
|
|
|
|
|
0
|
$postponement_init_code .= <
|
1179
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: creating postponement ", _po \$postponement, " for${leftmost} predicate in event ", _ev \$ctx if is_tracing; |
1180
|
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing check sub for postponement ", _po \$postponement if is_tracing; |
1182
|
|
|
|
|
|
|
push \@{\$ctx->{EndSubs}}, [ |
1183
|
|
|
|
|
|
|
sub { |
1184
|
|
|
|
|
|
|
## Called to see if the leftmost predicate matched |
1185
|
|
|
|
|
|
|
my ( \$ctx, \$postponement ) = \@_; |
1186
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: checking${leftmost} predicate postponement ", _po \$postponement, " in event ", _ev \$ctx if is_tracing; |
1187
|
|
|
|
|
|
|
}, |
1188
|
|
|
|
|
|
|
\$ctx, |
1189
|
|
|
|
|
|
|
\$postponement |
1190
|
|
|
|
|
|
|
]; |
1191
|
|
|
|
|
|
|
CODE_END |
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
# for my \$ctx ( \@{\$postponement->[_p_contexts]} ) { |
1194
|
|
|
|
|
|
|
# \@{\$ctx->{Postponements}} = grep \$_ != \$postponement, \@{\$ctx->{Postponements}}; |
1195
|
|
|
|
|
|
|
# emit_trace_SAX_message "EventPath: ", \@{\$ctx->{Postponements}} . " postponements left in event ", _ev \$ctx, ": (", join( ", ", map _ev \$_, \@{\$ctx->{Postponements}} ), ")" if is_tracing; |
1196
|
|
|
|
|
|
|
# } |
1197
|
|
|
|
|
|
|
|
1198
|
0
|
0
|
|
|
|
0
|
if ( $leftmost ) { |
1199
|
|
|
|
|
|
|
## this is the leftmost predicate expression |
1200
|
0
|
0
|
|
|
|
0
|
die "ARGH!" if $context->{precursorized_action_codes}; |
1201
|
0
|
|
|
|
|
0
|
local $context->{precursorized_action_codes} = []; |
1202
|
0
|
|
|
|
|
0
|
local $context->{precursorize_action} = <
|
1203
|
|
|
|
|
|
|
{ |
1204
|
|
|
|
|
|
|
my \$p = \$postponement->[_p_parent_postponement] || \$postponement; |
1205
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: adding context node ", _ev \$ctx, " to postponement ", _po \$p if is_tracing; |
1206
|
|
|
|
|
|
|
\$ctx->{PostponementCount}++; |
1207
|
|
|
|
|
|
|
push \@{\$p->[_p_contexts]}, \$ctx; |
1208
|
|
|
|
|
|
|
} |
1209
|
|
|
|
|
|
|
CODE_END |
1210
|
|
|
|
|
|
|
|
1211
|
0
|
|
|
|
|
0
|
local $context->{action_wrapper} = <
|
1212
|
|
|
|
|
|
|
if ( ) { |
1213
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: predicate postponement ", _po \$postponement, " MATCHED!" if is_tracing; |
1214
|
|
|
|
|
|
|
while ( my \$ctx = shift \@{\$postponement->[_p_contexts]} ) { |
1215
|
|
|
|
|
|
|
\$ctx->{PostponementCount}--; |
1216
|
|
|
|
|
|
|
} |
1217
|
|
|
|
|
|
|
} |
1218
|
|
|
|
|
|
|
else { |
1219
|
|
|
|
|
|
|
while ( my \$ctx = shift \@{\$postponement->[_p_contexts]} ) { |
1220
|
|
|
|
|
|
|
\$ctx->{PostponementCount}--; |
1221
|
|
|
|
|
|
|
} |
1222
|
|
|
|
|
|
|
} |
1223
|
|
|
|
|
|
|
CODE_END |
1224
|
|
|
|
|
|
|
|
1225
|
0
|
|
|
|
|
0
|
_indent $context->{action_wrapper} if _indentomatic; |
1226
|
0
|
|
|
|
|
0
|
_indent $context->{action_wrapper} if _indentomatic; |
1227
|
0
|
|
|
|
|
0
|
_replace_NEXT $context->{action_wrapper}, $expr_code, ""; |
1228
|
|
|
|
|
|
|
|
1229
|
0
|
|
|
|
|
0
|
$action_code = "## NO ACTION LEFT\n"; |
1230
|
|
|
|
|
|
|
|
1231
|
0
|
|
|
|
|
0
|
local $f::indent = $f::indent + 1; |
1232
|
0
|
0
|
|
|
|
0
|
if ( $path_remainder ) { |
1233
|
0
|
|
|
|
|
0
|
my $code = $path_remainder->as_incr_code( $context ); |
1234
|
0
|
|
|
|
|
0
|
push @inline_precursor_codes, |
1235
|
|
|
|
|
|
|
"\n## remainder of location path\n$code"; |
1236
|
|
|
|
|
|
|
} |
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
_replace_NEXT |
1239
|
0
|
|
|
|
|
0
|
$postponement_init_code, |
1240
|
0
|
|
|
|
|
0
|
join( "", @{$context->{precursorized_action_codes}} ), |
1241
|
|
|
|
|
|
|
""; |
1242
|
|
|
|
|
|
|
} |
1243
|
|
|
|
|
|
|
else { |
1244
|
|
|
|
|
|
|
#warn " ## non-leftmost predicate\n"; |
1245
|
|
|
|
|
|
|
## It's a non-leftmost predicate. |
1246
|
|
|
|
|
|
|
|
1247
|
0
|
|
|
|
|
0
|
local $f::indent = $f::indent + 1; |
1248
|
0
|
0
|
|
|
|
0
|
if ( $path_remainder ) { |
1249
|
0
|
|
|
|
|
0
|
my $code = $path_remainder->as_incr_code( $context ); |
1250
|
0
|
|
|
|
|
0
|
_indent $code if _indentomatic; |
1251
|
0
|
|
|
|
|
0
|
push @inline_precursor_codes, |
1252
|
|
|
|
|
|
|
"\n## remainder of location path\n$code"; |
1253
|
|
|
|
|
|
|
} |
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
## $postponement_init_code = <
|
1256
|
|
|
|
|
|
|
##my \$parent_postponement = \$postponement; |
1257
|
|
|
|
|
|
|
##\$postponement = [ \$parent_postponement ]; |
1258
|
|
|
|
|
|
|
##emit_trace_SAX_message "EventPath: creating postponement ", _po \$postponement, " for predicate (non-leftmost) in event ", _ev \$ctx if is_tracing; |
1259
|
|
|
|
|
|
|
##CODE_END |
1260
|
|
|
|
|
|
|
## |
1261
|
0
|
|
|
|
|
0
|
_replace_NEXT $action_code, <
|
1262
|
|
|
|
|
|
|
if ( \$postponement->[_p_contexts] ) { |
1263
|
|
|
|
|
|
|
my \$parent_postponement = \$postponement->[_p_parent_postponement]; |
1264
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: moving context nodes from postponement ", _po \$postponement, " to parent postponement ", _po \$parent_postponement if is_tracing; |
1265
|
|
|
|
|
|
|
push |
1266
|
|
|
|
|
|
|
\@{\$parent_postponement->[_p_contexts]}, |
1267
|
|
|
|
|
|
|
splice \@{\$postponement->[_p_contexts]}; |
1268
|
|
|
|
|
|
|
} |
1269
|
|
|
|
|
|
|
else { |
1270
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: but no context nodes in postponement ", _po \$postponement if is_tracing; |
1271
|
|
|
|
|
|
|
} |
1272
|
|
|
|
|
|
|
CODE_END |
1273
|
|
|
|
|
|
|
|
1274
|
|
|
|
|
|
|
## _indent $action_code if _indentomatic; |
1275
|
|
|
|
|
|
|
## _indent $action_code if _indentomatic; |
1276
|
|
|
|
|
|
|
## $action_code = <
|
1277
|
|
|
|
|
|
|
##push \@{\$ctx->{EndSubs}}, [ |
1278
|
|
|
|
|
|
|
## sub { |
1279
|
|
|
|
|
|
|
## ## Called to see if a non-leftmost predicate matched |
1280
|
|
|
|
|
|
|
## my ( \$ctx, \$parent_postponement, \$postponement ) = \@_; |
1281
|
|
|
|
|
|
|
## emit_trace_SAX_message "EventPath: checking postponement ", _po \$postponement, " for predicate (non-leftmost)" if is_tracing; |
1282
|
|
|
|
|
|
|
##warn \$postponement->[_p_first_precursor+0]; |
1283
|
|
|
|
|
|
|
## for my \$ctx ( \@{\$postponement->[_p_contexts]} ) { |
1284
|
|
|
|
|
|
|
## \@{\$ctx->{Postponements}} = grep \$_ != \$postponement, \@{\$ctx->{Postponements}}; |
1285
|
|
|
|
|
|
|
## emit_trace_SAX_message \@{\$ctx->{Postponements}} . " postponements left in event ", _ev \$ctx, ": (", join( ", ", map _ev \$_, \@{\$ctx->{Postponements}} ), ")" if is_tracing; |
1286
|
|
|
|
|
|
|
## } |
1287
|
|
|
|
|
|
|
##$action_code }, |
1288
|
|
|
|
|
|
|
## \$ctx, |
1289
|
|
|
|
|
|
|
## \$parent_postponement, |
1290
|
|
|
|
|
|
|
## \$postponement |
1291
|
|
|
|
|
|
|
##]; |
1292
|
|
|
|
|
|
|
##CODE_END |
1293
|
0
|
|
|
|
|
0
|
_replace_NEXT |
1294
|
|
|
|
|
|
|
$postponement_init_code, |
1295
|
0
|
|
|
|
|
0
|
join( "", @{$context->{precursorized_action_codes}} ), |
1296
|
|
|
|
|
|
|
""; |
1297
|
|
|
|
|
|
|
} |
1298
|
|
|
|
|
|
|
} |
1299
|
|
|
|
|
|
|
else { |
1300
|
|
|
|
|
|
|
#warn " ## it's an expression\n"; |
1301
|
|
|
|
|
|
|
## It's an expression, not a predicate |
1302
|
0
|
|
|
|
|
0
|
_indent $action_code if _indentomatic; |
1303
|
0
|
|
|
|
|
0
|
_indent $action_code if _indentomatic; |
1304
|
0
|
|
|
|
|
0
|
$postponement_init_code = <
|
1305
|
|
|
|
|
|
|
\$postponement = [ \$postponement ]; ## Refer to parent postponement, if present |
1306
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: creating expression postponement ", _po \$postponement, " in event ", _ev \$ctx if is_tracing; |
1307
|
|
|
|
|
|
|
\$ctx->{PostponementCount}++; |
1308
|
|
|
|
|
|
|
push \@{\$ctx->{EndSubs}}, [ |
1309
|
|
|
|
|
|
|
sub { |
1310
|
|
|
|
|
|
|
## Called to calculate the postponed expression. |
1311
|
|
|
|
|
|
|
my ( \$ctx, \$postponement ) = \@_; |
1312
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: checking expression postponement ", _po \$postponement, " in event ", _ev \$ctx if is_tracing; |
1313
|
|
|
|
|
|
|
\$ctx->{PostponementCount}--; |
1314
|
|
|
|
|
|
|
emit_trace_SAX_message \$ctx->{PostponementCount} . " postponements left in event ", _ev \$ctx if is_tracing; |
1315
|
|
|
|
|
|
|
$action_code }, |
1316
|
|
|
|
|
|
|
\$ctx, |
1317
|
|
|
|
|
|
|
\$postponement |
1318
|
|
|
|
|
|
|
]; |
1319
|
|
|
|
|
|
|
CODE_END |
1320
|
0
|
|
|
|
|
0
|
$action_code = ""; |
1321
|
|
|
|
|
|
|
} |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
# my $code = $self->insert_next_in_to_template( <
|
1324
|
|
|
|
|
|
|
## TODO: figure a way for the absolute precursors to fire this expression. |
1325
|
|
|
|
|
|
|
#{ |
1326
|
|
|
|
|
|
|
# my $p = $postponement_init_code; |
1327
|
|
|
|
|
|
|
# _indent $p for 0..$f::indent+1; |
1328
|
|
|
|
|
|
|
# chomp $p; |
1329
|
|
|
|
|
|
|
# warn " postponement_init_code:\n$p\n"; |
1330
|
|
|
|
|
|
|
# |
1331
|
|
|
|
|
|
|
# for ( @inline_precursor_codes ) { |
1332
|
|
|
|
|
|
|
# my $a = $_; |
1333
|
|
|
|
|
|
|
# chomp $a; |
1334
|
|
|
|
|
|
|
# _indent $a for 0..$f::indent+1; |
1335
|
|
|
|
|
|
|
# warn " precursor_code:\n$a\n"; |
1336
|
|
|
|
|
|
|
# } |
1337
|
|
|
|
|
|
|
# |
1338
|
|
|
|
|
|
|
# my $a = $action_code; |
1339
|
|
|
|
|
|
|
# chomp $a; |
1340
|
|
|
|
|
|
|
# _indent $a for 0..$f::indent+1; |
1341
|
|
|
|
|
|
|
# warn " action_code:\n$a\n"; |
1342
|
|
|
|
|
|
|
#} |
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
|
1345
|
0
|
|
|
|
|
0
|
local $" = ""; |
1346
|
0
|
|
|
|
|
0
|
my $code = <
|
1347
|
|
|
|
|
|
|
$postponement_init_code@inline_precursor_codes |
1348
|
|
|
|
|
|
|
$action_code |
1349
|
|
|
|
|
|
|
CODE_END |
1350
|
|
|
|
|
|
|
|
1351
|
0
|
|
|
|
|
0
|
return $code; |
1352
|
|
|
|
|
|
|
} |
1353
|
|
|
|
|
|
|
|
1354
|
|
|
|
|
|
|
############################################################################### |
1355
|
|
|
|
|
|
|
## |
1356
|
|
|
|
|
|
|
## Functions |
1357
|
|
|
|
|
|
|
## |
1358
|
|
|
|
|
|
|
|
1359
|
|
|
|
|
|
|
## Boolean functions return 0 or 1, it's up to expr_eval (or any |
1360
|
|
|
|
|
|
|
## other code which passes these in or out to perl code) to convert |
1361
|
|
|
|
|
|
|
## these to true() or false(). Passing these in/out of this subsystem |
1362
|
|
|
|
|
|
|
## is far rarer than using them within it. Using 1 or 0 lets |
1363
|
|
|
|
|
|
|
## the optimization code and the generated use numeric or boolean |
1364
|
|
|
|
|
|
|
## Perl ops. |
1365
|
|
|
|
|
|
|
|
1366
|
|
|
|
|
|
|
## When compiled, expressions and function calls are turned in to |
1367
|
|
|
|
|
|
|
## Perl code right in the grammar, with a vew exceptions like |
1368
|
|
|
|
|
|
|
## string( node-set ). |
1369
|
|
|
|
|
|
|
|
1370
|
|
|
|
|
|
|
## The parser calls this |
1371
|
|
|
|
|
|
|
sub function { |
1372
|
0
|
|
|
0
|
|
0
|
my ( $name, $parms ) = @_; |
1373
|
|
|
|
|
|
|
|
1374
|
1
|
|
|
1
|
|
8
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5371
|
|
1375
|
|
|
|
|
|
|
|
1376
|
|
|
|
|
|
|
## prevent ppl from spelling then "foo_bar" |
1377
|
0
|
|
|
|
|
0
|
my $real_name = $name; |
1378
|
0
|
|
|
|
|
0
|
my $had_underscores = $real_name =~ s/_/*NO-UNDERSCORES-PLEASE*/g; |
1379
|
0
|
|
|
|
|
0
|
$real_name =~ s/-/_/g; |
1380
|
|
|
|
|
|
|
|
1381
|
0
|
0
|
|
|
|
0
|
unless ( "XFD::Function::$real_name"->can( "new" ) ) { |
1382
|
0
|
0
|
|
|
|
0
|
if ( $had_underscores ) { |
1383
|
0
|
0
|
|
|
|
0
|
if ( $had_underscores ) { |
1384
|
0
|
|
|
|
|
0
|
$real_name = $name; |
1385
|
0
|
|
|
|
|
0
|
$real_name =~ s/-/_/g; |
1386
|
0
|
0
|
|
|
|
0
|
if ( defined &{"XFD::Function::$real_name"} ) { |
|
0
|
|
|
|
|
0
|
|
1387
|
0
|
|
|
|
|
0
|
die |
1388
|
|
|
|
|
|
|
"XPath function mispelled, use '-' instead of '_' in '$name'\n"; |
1389
|
|
|
|
|
|
|
} |
1390
|
|
|
|
|
|
|
} |
1391
|
|
|
|
|
|
|
} |
1392
|
0
|
|
|
|
|
0
|
die "unknown XPath function '$name'\n"; |
1393
|
|
|
|
|
|
|
} |
1394
|
|
|
|
|
|
|
|
1395
|
0
|
|
|
|
|
0
|
return "XFD::Function::$real_name"->new( @$parms ); |
1396
|
|
|
|
|
|
|
} |
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
|
1399
|
|
|
|
|
|
|
## Many XPath functions use a node set of the context node when |
1400
|
|
|
|
|
|
|
## no args are provided. |
1401
|
|
|
|
|
|
|
sub _default_to_context { |
1402
|
0
|
|
|
0
|
|
0
|
my $args = shift; |
1403
|
0
|
0
|
|
|
|
0
|
return $args if @$args; |
1404
|
|
|
|
|
|
|
|
1405
|
0
|
|
|
|
|
0
|
my $s = XFD::Axis::self->new; |
1406
|
0
|
|
|
|
|
0
|
my $n = XFD::EventType::node->new; |
1407
|
0
|
|
|
|
|
0
|
$s->set_next( $n ); |
1408
|
0
|
|
|
|
|
0
|
return [ $s ]; |
1409
|
|
|
|
|
|
|
} |
1410
|
|
|
|
|
|
|
|
1411
|
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
|
#################### |
1413
|
|
|
|
|
|
|
@XFD::Function::ISA = qw( XFD::Op ); |
1414
|
|
|
|
|
|
|
|
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
@XFD::BooleanFunction::ISA = qw( XFD::Function ); |
1417
|
0
|
|
|
0
|
|
0
|
sub XFD::BooleanFunction::result_type { "boolean" } |
1418
|
0
|
|
|
0
|
|
0
|
sub XFD::BooleanFunction::parm_type { "boolean" } |
1419
|
|
|
|
|
|
|
@XFD::NodesetFunction::ISA = qw( XFD::Function ); |
1420
|
0
|
|
|
0
|
|
0
|
sub XFD::NodesetFunction::result_type { "string" } |
1421
|
0
|
|
|
0
|
|
0
|
sub XFD::NodesetFunction::parm_type { "nodeset" } |
1422
|
|
|
|
|
|
|
@XFD::NumericFunction::ISA = qw( XFD::Function ); |
1423
|
0
|
|
|
0
|
|
0
|
sub XFD::NumericFunction::result_type { "number" } |
1424
|
0
|
|
|
0
|
|
0
|
sub XFD::NumericFunction::parm_type { "number" } |
1425
|
|
|
|
|
|
|
@XFD::StringFunction::ISA = qw( XFD::Function ); |
1426
|
0
|
|
|
0
|
|
0
|
sub XFD::StringFunction::result_type { "string" } |
1427
|
0
|
|
|
0
|
|
0
|
sub XFD::StringFunction::parm_type { "string" } |
1428
|
|
|
|
|
|
|
|
1429
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::op_type { shift->XFD::Op::op_type . "()" } |
1430
|
|
|
|
|
|
|
|
1431
|
|
|
|
|
|
|
## |
1432
|
|
|
|
|
|
|
## NOTE: munge_parms is where all the precursor detection magic occurs. |
1433
|
|
|
|
|
|
|
## A precursor is detected when a parameter to a function (or operator) |
1434
|
|
|
|
|
|
|
## queues up one or more precursors when converted to immediate code. |
1435
|
|
|
|
|
|
|
## By definition, a precursor can't be executed immediately. |
1436
|
|
|
|
|
|
|
## |
1437
|
|
|
|
|
|
|
sub XFD::Function::munge_parms { |
1438
|
|
|
|
|
|
|
## police parms and convert to appropriate type as needed. |
1439
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1440
|
0
|
|
|
|
|
0
|
my ( $min, $max, $context ) = @_; |
1441
|
|
|
|
|
|
|
|
1442
|
0
|
|
|
|
|
0
|
( my $sub_name = ref $self ) =~ s/.*://; |
1443
|
|
|
|
|
|
|
|
1444
|
0
|
0
|
0
|
|
|
0
|
die "$min > $max!!\n" if defined $max && $min > $max; |
1445
|
|
|
|
|
|
|
|
1446
|
0
|
|
|
|
|
0
|
my $msg; |
1447
|
0
|
|
|
|
|
0
|
my $cnt = @$self; |
1448
|
0
|
0
|
0
|
|
|
0
|
if ( defined $max && $max == $min ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1449
|
0
|
0
|
|
|
|
0
|
$msg = "takes $min parameters" unless $cnt == $min; |
1450
|
|
|
|
|
|
|
} |
1451
|
|
|
|
|
|
|
elsif ( $cnt < $min ) { |
1452
|
0
|
|
|
|
|
0
|
$msg = "takes at least $min parameters"; |
1453
|
|
|
|
|
|
|
} |
1454
|
|
|
|
|
|
|
elsif ( defined $max && $cnt > $max ) { |
1455
|
0
|
|
|
|
|
0
|
$msg = "takes at most $max parameters"; |
1456
|
|
|
|
|
|
|
} |
1457
|
|
|
|
|
|
|
|
1458
|
0
|
|
|
|
|
0
|
my @errors; |
1459
|
0
|
0
|
|
|
|
0
|
push @errors, "$sub_name() $msg, got $cnt\n" |
1460
|
|
|
|
|
|
|
if defined $msg; |
1461
|
0
|
|
|
|
|
0
|
my $num = 0; |
1462
|
|
|
|
|
|
|
|
1463
|
0
|
|
|
|
|
0
|
my @parm_codes; |
1464
|
|
|
|
|
|
|
|
1465
|
0
|
|
|
|
|
0
|
for my $parm ( @$self ) { |
1466
|
0
|
|
|
|
|
0
|
my $required_type = $self->parm_type( $num ); |
1467
|
0
|
|
|
|
|
0
|
++$num; |
1468
|
|
|
|
|
|
|
|
1469
|
0
|
|
|
|
|
0
|
my $type = $parm->result_type; |
1470
|
|
|
|
|
|
|
|
1471
|
0
|
0
|
0
|
|
|
0
|
if ( $type ne $required_type |
|
|
|
0
|
|
|
|
|
1472
|
|
|
|
|
|
|
|| ( $type eq "nodeset" && $required_type eq "nodeset" ) |
1473
|
|
|
|
|
|
|
) { |
1474
|
0
|
|
|
|
|
0
|
my $cvt = "XFD::${type}2$required_type"; |
1475
|
0
|
0
|
|
|
|
0
|
if ( $cvt->can( "new" ) ) { |
1476
|
0
|
|
|
|
|
0
|
$parm = $cvt->new( $parm ); |
1477
|
|
|
|
|
|
|
} |
1478
|
|
|
|
|
|
|
else { |
1479
|
0
|
|
|
|
|
0
|
push @errors, |
1480
|
|
|
|
|
|
|
"Can't convert ", |
1481
|
|
|
|
|
|
|
$type, |
1482
|
|
|
|
|
|
|
" to ", |
1483
|
|
|
|
|
|
|
$required_type, |
1484
|
|
|
|
|
|
|
" in ", |
1485
|
|
|
|
|
|
|
$sub_name, |
1486
|
|
|
|
|
|
|
"() parameter ", |
1487
|
|
|
|
|
|
|
$num, |
1488
|
|
|
|
|
|
|
"\n" |
1489
|
|
|
|
|
|
|
} |
1490
|
|
|
|
|
|
|
} |
1491
|
|
|
|
|
|
|
|
1492
|
0
|
|
|
|
|
0
|
push @parm_codes, $parm->as_immed_code( $context ); |
1493
|
|
|
|
|
|
|
} |
1494
|
|
|
|
|
|
|
|
1495
|
0
|
0
|
|
|
|
0
|
die @errors if @errors; |
1496
|
|
|
|
|
|
|
|
1497
|
0
|
|
|
|
|
0
|
return @parm_codes; |
1498
|
|
|
|
|
|
|
} |
1499
|
|
|
|
|
|
|
|
1500
|
|
|
|
|
|
|
|
1501
|
|
|
|
|
|
|
sub XFD::Function::build_expr { |
1502
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1503
|
0
|
|
|
|
|
0
|
my ( undef, undef, $context ) = @_; |
1504
|
|
|
|
|
|
|
|
1505
|
0
|
|
|
|
|
0
|
my $code_sub = pop; |
1506
|
0
|
|
|
|
|
0
|
my $code = $code_sub->( $self->munge_parms( @_ ) ); |
1507
|
|
|
|
|
|
|
|
1508
|
0
|
0
|
|
|
|
0
|
$code = _eval_at_compile_time $self->result_type, $code, $context |
1509
|
|
|
|
|
|
|
if $self->is_constant; |
1510
|
|
|
|
|
|
|
|
1511
|
0
|
|
|
|
|
0
|
return $code; |
1512
|
|
|
|
|
|
|
} |
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
############################################################################### |
1515
|
|
|
|
|
|
|
## |
1516
|
|
|
|
|
|
|
## Type Converters |
1517
|
|
|
|
|
|
|
## |
1518
|
|
|
|
|
|
|
@XFD::Converter::ISA = qw( XFD::Function ); |
1519
|
|
|
|
|
|
|
|
1520
|
0
|
|
|
0
|
|
0
|
sub XFD::Converter::result_type { ( my $foo = ref shift ) =~ s/.*2//; $foo } |
|
0
|
|
|
|
|
0
|
|
1521
|
|
|
|
|
|
|
|
1522
|
|
|
|
|
|
|
sub XFD::Converter::as_immed_code { |
1523
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1524
|
|
|
|
|
|
|
|
1525
|
0
|
|
|
|
|
0
|
my $code = $self->immed_code_template( @_ ); |
1526
|
|
|
|
|
|
|
|
1527
|
0
|
|
|
|
|
0
|
my $parm = $self->[0]; |
1528
|
0
|
0
|
|
|
|
0
|
_replace_NEXT $code, $parm->as_immed_code( @_ ) if defined $parm; |
1529
|
|
|
|
|
|
|
|
1530
|
0
|
|
|
|
|
0
|
return $code; |
1531
|
|
|
|
|
|
|
} |
1532
|
|
|
|
|
|
|
|
1533
|
|
|
|
|
|
|
|
1534
|
|
|
|
|
|
|
## NaN is not handled properly. |
1535
|
|
|
|
|
|
|
|
1536
|
|
|
|
|
|
|
@XFD::boolean2number::ISA = qw( XFD::Converter ); |
1537
|
|
|
|
|
|
|
sub XFD::boolean2number::immed_code_template { |
1538
|
|
|
|
|
|
|
## Internally, booleans are numeric, force them to 0 or 1. |
1539
|
0
|
|
|
0
|
|
0
|
return " ? 1 : 0"; |
1540
|
|
|
|
|
|
|
} |
1541
|
|
|
|
|
|
|
|
1542
|
|
|
|
|
|
|
@XFD::boolean2string::ISA = qw( XFD::Converter ); |
1543
|
|
|
|
|
|
|
sub XFD::boolean2string::immed_code_template { |
1544
|
|
|
|
|
|
|
## Internally, booleans are numeric |
1545
|
0
|
|
|
0
|
|
0
|
return "( ? 'true' : 'false' )"; |
1546
|
|
|
|
|
|
|
} |
1547
|
|
|
|
|
|
|
|
1548
|
|
|
|
|
|
|
## "int" is used internally to get things rounded right. |
1549
|
|
|
|
|
|
|
@XFD::number2int::ISA = qw( XFD::Converter ); |
1550
|
0
|
|
|
0
|
|
0
|
sub XFD::number2int::result_type { "number" } |
1551
|
|
|
|
|
|
|
sub XFD::number2int::immed_code_template { |
1552
|
0
|
|
|
0
|
|
0
|
require POSIX; |
1553
|
0
|
|
|
|
|
0
|
return "POSIX::floor( + 0.5 )"; |
1554
|
|
|
|
|
|
|
} |
1555
|
|
|
|
|
|
|
|
1556
|
|
|
|
|
|
|
@XFD::number2string::ISA = qw( XFD::Converter ); |
1557
|
|
|
|
|
|
|
sub XFD::number2string::immed_code_template { |
1558
|
|
|
|
|
|
|
## The 0+ is to force the scalar in to a numeric format, so to |
1559
|
|
|
|
|
|
|
## trim leading zeros. This will have the side effect that any |
1560
|
|
|
|
|
|
|
## numbers that don't "fit" in to the local machine's notion of |
1561
|
|
|
|
|
|
|
## a floating point Perl scaler will be munged to the closest |
1562
|
|
|
|
|
|
|
## approximation, but hey... |
1563
|
|
|
|
|
|
|
return |
1564
|
0
|
|
|
0
|
|
0
|
"do { my \$n = ; ( \$n ne 'NaN' ? 0+\$n : \$n ) }"; |
1565
|
|
|
|
|
|
|
} |
1566
|
|
|
|
|
|
|
|
1567
|
|
|
|
|
|
|
@XFD::number2boolean::ISA = qw( XFD::Converter ); |
1568
|
|
|
|
|
|
|
sub XFD::number2boolean::immed_code_template { |
1569
|
|
|
|
|
|
|
return |
1570
|
0
|
|
|
0
|
|
0
|
"do { my \$n = ; ( \$n ne 'NaN' && \$n ) ? 1 : 0 }"; |
1571
|
|
|
|
|
|
|
} |
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
@XFD::string2boolean::ISA = qw( XFD::Converter ); |
1574
|
|
|
|
|
|
|
sub XFD::string2boolean::immed_code_template { |
1575
|
0
|
|
|
0
|
|
0
|
return "( length ? 1 : 0 )"; |
1576
|
|
|
|
|
|
|
} |
1577
|
|
|
|
|
|
|
|
1578
|
|
|
|
|
|
|
@XFD::string2number::ISA = qw( XFD::Converter ); |
1579
|
|
|
|
|
|
|
sub XFD::string2number::immed_code_template { |
1580
|
|
|
|
|
|
|
## The "0+" forces it to a number, hopefully it was a number |
1581
|
|
|
|
|
|
|
## the local machine's perl can represent accurately. |
1582
|
0
|
|
|
0
|
|
0
|
return qq{do { my \$s = ; _looks_numeric \$s ? 0+\$s : die "can't convert '\$s' to a number in XPath expression"}}; |
1583
|
|
|
|
|
|
|
} |
1584
|
|
|
|
|
|
|
|
1585
|
|
|
|
|
|
|
## the any2..._rt are used at runtime when we have no idea at compile time |
1586
|
|
|
|
|
|
|
## about type. So far, this only happens with variable refs. Unlike the |
1587
|
|
|
|
|
|
|
## other converters, these are called at runtime. |
1588
|
|
|
|
|
|
|
sub _any2boolean_rt { |
1589
|
0
|
|
|
0
|
|
0
|
my $any_value = shift; |
1590
|
|
|
|
|
|
|
|
1591
|
0
|
|
|
|
|
0
|
my $type = ref $any_value; |
1592
|
0
|
|
|
|
|
0
|
$type =~ s/.*://; |
1593
|
0
|
|
|
|
|
0
|
$type =~ s/ .*//; |
1594
|
|
|
|
|
|
|
|
1595
|
0
|
|
|
|
|
0
|
my $value = $$any_value; |
1596
|
|
|
|
|
|
|
|
1597
|
0
|
0
|
|
|
|
0
|
return $value if $type eq "boolean"; |
1598
|
0
|
0
|
|
|
|
0
|
return $value ? 1 : 0 if $type eq "number"; |
|
|
0
|
|
|
|
|
|
1599
|
0
|
0
|
|
|
|
0
|
return length( $value ) ? 1 : 0 if $type eq "string"; |
|
|
0
|
|
|
|
|
|
1600
|
|
|
|
|
|
|
|
1601
|
0
|
|
|
|
|
0
|
die "Can't convert '$type' to boolean\n"; |
1602
|
|
|
|
|
|
|
} |
1603
|
|
|
|
|
|
|
|
1604
|
|
|
|
|
|
|
@XFD::any2boolean::ISA = qw( XFD::Converter ); |
1605
|
0
|
|
|
0
|
|
0
|
sub XFD::any2boolean::immed_code_template { "_any2boolean_rt( )" } |
1606
|
|
|
|
|
|
|
########## |
1607
|
|
|
|
|
|
|
sub _any2string_rt { |
1608
|
0
|
|
|
0
|
|
0
|
my $any_value = shift; |
1609
|
|
|
|
|
|
|
|
1610
|
0
|
|
|
|
|
0
|
my $type = ref $any_value; |
1611
|
0
|
|
|
|
|
0
|
$type =~ s/.*://; |
1612
|
0
|
|
|
|
|
0
|
$type =~ s/ .*//; |
1613
|
|
|
|
|
|
|
|
1614
|
0
|
|
|
|
|
0
|
my $value = $$any_value; |
1615
|
|
|
|
|
|
|
|
1616
|
0
|
0
|
|
|
|
0
|
return $any_value if $type eq "string"; |
1617
|
0
|
0
|
|
|
|
0
|
return 0+$any_value if $type eq "number"; |
1618
|
0
|
0
|
|
|
|
0
|
if ( $type eq "boolean" ) { |
1619
|
0
|
0
|
|
|
|
0
|
return ref $value |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1620
|
|
|
|
|
|
|
? UNIVERSAL::isa( "XFD::true" ) |
1621
|
|
|
|
|
|
|
? "true" |
1622
|
|
|
|
|
|
|
: "false" |
1623
|
|
|
|
|
|
|
: $value ? "true" : "false"; |
1624
|
|
|
|
|
|
|
} |
1625
|
|
|
|
|
|
|
|
1626
|
0
|
|
|
|
|
0
|
die "Can't convert '$type' to string\n"; |
1627
|
|
|
|
|
|
|
} |
1628
|
|
|
|
|
|
|
|
1629
|
|
|
|
|
|
|
@XFD::any2string::ISA = qw( XFD::Converter ); |
1630
|
0
|
|
|
0
|
|
0
|
sub XFD::any2string::immed_code_template { "_any2string_rt( )" } |
1631
|
|
|
|
|
|
|
########## |
1632
|
|
|
|
|
|
|
sub _any2number_rt { |
1633
|
0
|
|
|
0
|
|
0
|
my $any_value = shift; |
1634
|
|
|
|
|
|
|
|
1635
|
0
|
|
|
|
|
0
|
my $type = ref $any_value; |
1636
|
0
|
|
|
|
|
0
|
$type =~ s/.*://; |
1637
|
0
|
|
|
|
|
0
|
$type =~ s/ .*//; |
1638
|
|
|
|
|
|
|
|
1639
|
0
|
|
|
|
|
0
|
my $value = $$any_value; |
1640
|
|
|
|
|
|
|
|
1641
|
0
|
0
|
|
|
|
0
|
return 0+$any_value if $type eq "number"; |
1642
|
|
|
|
|
|
|
|
1643
|
0
|
0
|
|
|
|
0
|
if ( $type eq "boolean" ) { |
1644
|
0
|
0
|
|
|
|
0
|
return ref $value |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
1645
|
|
|
|
|
|
|
? UNIVERSAL::isa( "XFD::true" ) ? 1 : 0 |
1646
|
|
|
|
|
|
|
: $value ? 1 : 0; |
1647
|
|
|
|
|
|
|
} |
1648
|
|
|
|
|
|
|
|
1649
|
0
|
0
|
|
|
|
0
|
if ( $type eq "string" ) { |
1650
|
0
|
0
|
|
|
|
0
|
return 0+$value if _looks_numeric $value; |
1651
|
0
|
|
|
|
|
0
|
return "NaN"; |
1652
|
|
|
|
|
|
|
} |
1653
|
|
|
|
|
|
|
|
1654
|
0
|
|
|
|
|
0
|
die "Can't convert '$type' to number\n"; |
1655
|
|
|
|
|
|
|
} |
1656
|
|
|
|
|
|
|
|
1657
|
|
|
|
|
|
|
@XFD::any2number::ISA = qw( XFD::Converter ); |
1658
|
0
|
|
|
0
|
|
0
|
sub XFD::any2number::immed_code_template { "_any2number_rt( )" } |
1659
|
|
|
|
|
|
|
######################################## |
1660
|
|
|
|
|
|
|
## |
1661
|
|
|
|
|
|
|
## nodeset2foo converters |
1662
|
|
|
|
|
|
|
## |
1663
|
|
|
|
|
|
|
|
1664
|
|
|
|
|
|
|
@XFD::NodesetConverter::ISA = qw( XFD::Converter ); |
1665
|
0
|
|
|
0
|
|
0
|
sub XFD::NodesetConverter::result_type { ( ( ref shift ) =~ m/2(.*)/ )[0] } |
1666
|
|
|
|
|
|
|
sub XFD::NodesetConverter::incr_code_template { |
1667
|
0
|
|
|
0
|
|
0
|
Carp::confess( ref shift ) . " cannot generate incremental code"; |
1668
|
|
|
|
|
|
|
} |
1669
|
|
|
|
|
|
|
|
1670
|
|
|
|
|
|
|
sub XFD::NodesetConverter::as_immed_code { |
1671
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1672
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
1673
|
|
|
|
|
|
|
|
1674
|
0
|
|
|
|
|
0
|
my $expr_code = eval { |
1675
|
0
|
|
|
|
|
0
|
$self->[0]->XFD::Converter::as_immed_code( $context ); |
1676
|
|
|
|
|
|
|
}; |
1677
|
|
|
|
|
|
|
|
1678
|
0
|
0
|
|
|
|
0
|
if ( defined $expr_code ) { |
1679
|
0
|
|
|
|
|
0
|
my $code = $self->immed_code_template( @_ ); |
1680
|
0
|
|
|
|
|
0
|
_replace_NEXT $code, $expr_code; |
1681
|
0
|
|
|
|
|
0
|
return $code; |
1682
|
|
|
|
|
|
|
} |
1683
|
0
|
0
|
|
|
|
0
|
die $@ unless $@ eq "precursorize THIS\n"; |
1684
|
|
|
|
|
|
|
|
1685
|
0
|
|
|
|
|
0
|
my ( $postponer_class ) |
1686
|
|
|
|
|
|
|
= "XFD::" . ucfirst( $self->result_type ) . "Postponer"; |
1687
|
|
|
|
|
|
|
|
1688
|
0
|
|
|
|
|
0
|
my $precursor_number = $#{$context->{Precursors}} + 1; |
|
0
|
|
|
|
|
0
|
|
1689
|
|
|
|
|
|
|
|
1690
|
0
|
|
|
|
|
0
|
my $postponer = $postponer_class->new( $precursor_number ); |
1691
|
|
|
|
|
|
|
|
1692
|
0
|
|
|
|
|
0
|
$postponer->set_next( $self->[0] ); |
1693
|
|
|
|
|
|
|
|
1694
|
0
|
|
|
|
|
0
|
push @{$context->{Precursors}}, $postponer; |
|
0
|
|
|
|
|
0
|
|
1695
|
|
|
|
|
|
|
|
1696
|
0
|
|
|
|
|
0
|
return $self->precursor_fetching_code( $precursor_number ); |
1697
|
|
|
|
|
|
|
} |
1698
|
|
|
|
|
|
|
|
1699
|
|
|
|
|
|
|
|
1700
|
|
|
|
|
|
|
## |
1701
|
|
|
|
|
|
|
## When a NodesetConverter notices that it's nodeset expression |
1702
|
|
|
|
|
|
|
## needs to be precursorized, it places one of these at the |
1703
|
|
|
|
|
|
|
## head of the location path to manage precursorization. |
1704
|
|
|
|
|
|
|
## This allows a boolean conversion to operate differently than |
1705
|
|
|
|
|
|
|
## a string/numeric one, for instance. |
1706
|
|
|
|
|
|
|
## |
1707
|
|
|
|
|
|
|
## TODO: Allow these to signal the enclosing path test to not |
1708
|
|
|
|
|
|
|
## re-curry itself if the precursor has been satisfied. |
1709
|
|
|
|
|
|
|
sub _np_precursor_number() { 0 } |
1710
|
|
|
|
|
|
|
@XFD::NodesetPostponer::ISA = qw( XFD::PathTest ); |
1711
|
|
|
|
|
|
|
sub XFD::NodesetPostponer::as_incr_code { |
1712
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1713
|
0
|
|
|
|
|
0
|
my $context = shift; |
1714
|
0
|
|
|
|
|
0
|
local $context->{ActionCode} = $self->postponement_setting_code; |
1715
|
0
|
|
|
|
|
0
|
my $code = $self->[_next]->as_incr_code( $context ); |
1716
|
0
|
|
|
|
|
0
|
return $code; |
1717
|
|
|
|
|
|
|
} |
1718
|
|
|
|
|
|
|
sub XFD::NodesetPostponer::postponement_setting_code { |
1719
|
|
|
|
|
|
|
## This is overridden by number, string, boolean postponers |
1720
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1721
|
0
|
|
|
|
|
0
|
my $precursor_number = $self->[_np_precursor_number]; |
1722
|
0
|
|
|
|
|
0
|
return <
|
1723
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: Setting postponement for precursor $precursor_number" if is_tracing; |
1724
|
|
|
|
|
|
|
\$postponement->[_p_first_precursor+$precursor_number] = \$ctx; ## Nodeset postponer |
1725
|
|
|
|
|
|
|
CODE_END |
1726
|
|
|
|
|
|
|
} |
1727
|
|
|
|
|
|
|
|
1728
|
|
|
|
|
|
|
|
1729
|
|
|
|
|
|
|
########## |
1730
|
|
|
|
|
|
|
@XFD::nodeset2string::ISA = qw( XFD::NodesetConverter ); |
1731
|
|
|
|
|
|
|
sub XFD::nodeset2string::immed_code_template { |
1732
|
|
|
|
|
|
|
## This is used in cases where the location path can be |
1733
|
|
|
|
|
|
|
## evaluated immediately. |
1734
|
0
|
|
|
0
|
|
0
|
return <
|
1735
|
|
|
|
|
|
|
do { ## nodeset2string |
1736
|
|
|
|
|
|
|
my \$ctx = ( |
1737
|
|
|
|
|
|
|
|
1738
|
|
|
|
|
|
|
)[0]; |
1739
|
|
|
|
|
|
|
exists \$ctx->{Node}->{Value} |
1740
|
|
|
|
|
|
|
? \$ctx->{Node}->{Value} |
1741
|
|
|
|
|
|
|
: ""; |
1742
|
|
|
|
|
|
|
} # nodeset2string |
1743
|
|
|
|
|
|
|
CODE_END |
1744
|
|
|
|
|
|
|
} |
1745
|
|
|
|
|
|
|
|
1746
|
|
|
|
|
|
|
|
1747
|
|
|
|
|
|
|
sub XFD::nodeset2string::precursor_fetching_code { |
1748
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1749
|
0
|
|
|
|
|
0
|
my ( $precursor_number ) = @_; |
1750
|
|
|
|
|
|
|
|
1751
|
0
|
|
|
|
|
0
|
return qq{( |
1752
|
|
|
|
|
|
|
defined \$postponement->[_p_first_precursor+$precursor_number] |
1753
|
|
|
|
|
|
|
? \$postponement->[_p_first_precursor+$precursor_number] |
1754
|
|
|
|
|
|
|
: "" |
1755
|
|
|
|
|
|
|
)}; |
1756
|
|
|
|
|
|
|
} |
1757
|
|
|
|
|
|
|
|
1758
|
|
|
|
|
|
|
|
1759
|
|
|
|
|
|
|
@XFD::StringPostponer::ISA = qw( XFD::NodesetPostponer ); |
1760
|
|
|
|
|
|
|
sub XFD::StringPostponer::postponement_setting_code { |
1761
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1762
|
0
|
|
|
|
|
0
|
my $precursor_number = $self->[_np_precursor_number]; |
1763
|
0
|
|
|
|
|
0
|
return <
|
1764
|
|
|
|
|
|
|
unless ( defined \$postponement->[_p_first_precursor+$precursor_number] ) { ## nodeset2string |
1765
|
|
|
|
|
|
|
if ( \$ctx->{EventType} eq "start_document" |
1766
|
|
|
|
|
|
|
|| \$ctx->{EventType} eq "start_element" |
1767
|
|
|
|
|
|
|
) { |
1768
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: enabling text collection for precursor $precursor_number (postponement ", _po \$postponement, ")" if is_tracing; |
1769
|
|
|
|
|
|
|
nodeset2string_start( \$postponement, $precursor_number ); |
1770
|
|
|
|
|
|
|
## If this is one branch of a union, we need to define this |
1771
|
|
|
|
|
|
|
## precursor so the other branch of the union won't also |
1772
|
|
|
|
|
|
|
## start collecting text. |
1773
|
|
|
|
|
|
|
\$postponement->[_p_first_precursor+$precursor_number] = ""; |
1774
|
|
|
|
|
|
|
} |
1775
|
|
|
|
|
|
|
else { |
1776
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: setting precursor $precursor_number to string" if is_tracing; |
1777
|
|
|
|
|
|
|
my \$type = \$ctx->{EventType}; |
1778
|
|
|
|
|
|
|
\$postponement->[_p_first_precursor+$precursor_number] = ( |
1779
|
|
|
|
|
|
|
\$type eq "attribute" ? \$ctx->{Node}->{Value} |
1780
|
|
|
|
|
|
|
: \$ctx->{Node}->{Data} |
1781
|
|
|
|
|
|
|
); |
1782
|
|
|
|
|
|
|
\$postponement->[_p_first_precursor+$precursor_number] = "" |
1783
|
|
|
|
|
|
|
unless defined \$postponement->[_p_first_precursor+$precursor_number]; |
1784
|
|
|
|
|
|
|
} |
1785
|
|
|
|
|
|
|
} # nodeset2string |
1786
|
|
|
|
|
|
|
CODE_END |
1787
|
|
|
|
|
|
|
} |
1788
|
|
|
|
|
|
|
|
1789
|
|
|
|
|
|
|
########## |
1790
|
|
|
|
|
|
|
@XFD::nodeset2hash::ISA = qw( XFD::NodesetConverter ); |
1791
|
|
|
|
|
|
|
sub XFD::nodeset2hash::immed_code_template { |
1792
|
|
|
|
|
|
|
## This is used in cases where the location path can be |
1793
|
|
|
|
|
|
|
## evaluated immediately. |
1794
|
0
|
|
|
0
|
|
0
|
die "nodeset2hash::immed_code_template not implemented yet\n"; |
1795
|
0
|
|
|
|
|
0
|
return <
|
1796
|
|
|
|
|
|
|
do { ## nodeset2hash |
1797
|
|
|
|
|
|
|
my \$ctx = ( |
1798
|
|
|
|
|
|
|
|
1799
|
|
|
|
|
|
|
)[0]; |
1800
|
|
|
|
|
|
|
exists \$ctx->{Node}->{Value} |
1801
|
|
|
|
|
|
|
? \$ctx->{Node}->{Value} |
1802
|
|
|
|
|
|
|
: ""; |
1803
|
|
|
|
|
|
|
} # nodeset2hash |
1804
|
|
|
|
|
|
|
CODE_END |
1805
|
|
|
|
|
|
|
} |
1806
|
|
|
|
|
|
|
|
1807
|
|
|
|
|
|
|
|
1808
|
|
|
|
|
|
|
sub XFD::nodeset2hash::precursor_fetching_code { |
1809
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1810
|
0
|
|
|
|
|
0
|
my ( $precursor_number ) = @_; |
1811
|
|
|
|
|
|
|
|
1812
|
0
|
|
|
|
|
0
|
return qq{\$postponement->[_p_first_precursor+$precursor_number]->end_document}; |
1813
|
|
|
|
|
|
|
} |
1814
|
|
|
|
|
|
|
|
1815
|
|
|
|
|
|
|
@XFD::HashPostponer::ISA = qw( XFD::NodesetPostponer ); |
1816
|
|
|
|
|
|
|
sub XFD::HashPostponer::postponement_setting_code { |
1817
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1818
|
0
|
|
|
|
|
0
|
my $precursor_number = $self->[_np_precursor_number]; |
1819
|
|
|
|
|
|
|
## TODO: check to see if we really need this if EventType eq ... stuff |
1820
|
|
|
|
|
|
|
## it should be known at compile time, perhaps even just by dint of us |
1821
|
|
|
|
|
|
|
## setting the acceptable events for this opcode to be queued for. |
1822
|
0
|
|
|
|
|
0
|
return <
|
1823
|
|
|
|
|
|
|
unless ( defined \$postponement->[_p_first_precursor+$precursor_number] ) { ## nodeset2hash |
1824
|
|
|
|
|
|
|
if ( \$ctx->{EventType} eq "start_document" |
1825
|
|
|
|
|
|
|
|| \$ctx->{EventType} eq "start_element" |
1826
|
|
|
|
|
|
|
) { |
1827
|
|
|
|
|
|
|
## Note that, if this is one branch of a union, defining this |
1828
|
|
|
|
|
|
|
## precursor prevents the other branch of the union from also |
1829
|
|
|
|
|
|
|
## building a hash over top of this one. |
1830
|
|
|
|
|
|
|
## TODO: allow the caller to specify this class name |
1831
|
|
|
|
|
|
|
require XML::Filter::Dispatcher::AsHashHandler; |
1832
|
|
|
|
|
|
|
\$XFD::AsHashHandlers[0] ||= XML::Filter::Dispatcher::AsHashHandler->new; |
1833
|
|
|
|
|
|
|
my \$h = \$postponement->[_p_first_precursor+$precursor_number] = |
1834
|
|
|
|
|
|
|
shift \@XFD::AsHashHandlers; |
1835
|
|
|
|
|
|
|
|
1836
|
|
|
|
|
|
|
\$h->set_namespaces( \$d->{Namespaces} ? %{ \$d->{Namespaces} } : () ); |
1837
|
|
|
|
|
|
|
|
1838
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: precursor $precursor_number is handled by \$h" if is_tracing; |
1839
|
|
|
|
|
|
|
|
1840
|
|
|
|
|
|
|
\$h->start_document( {} ); ## superfluous in the current version, but just in case... |
1841
|
|
|
|
|
|
|
|
1842
|
|
|
|
|
|
|
my \$end_element = \$h->can( "end_element" ); |
1843
|
|
|
|
|
|
|
## nodeset2hash_start() will queue up the matching end_element |
1844
|
|
|
|
|
|
|
\$h->start_element( \$ctx->{Node} ) |
1845
|
|
|
|
|
|
|
if \$ctx->{EventType} eq "start_element"; |
1846
|
|
|
|
|
|
|
|
1847
|
|
|
|
|
|
|
nodeset2hash_start( |
1848
|
|
|
|
|
|
|
\$h, |
1849
|
|
|
|
|
|
|
\$h->can( "start_element" ), |
1850
|
|
|
|
|
|
|
\$h->can( "characters" ), |
1851
|
|
|
|
|
|
|
\$end_element, |
1852
|
|
|
|
|
|
|
); |
1853
|
|
|
|
|
|
|
|
1854
|
|
|
|
|
|
|
push \@{\$ctx->{EndSubs}}, [ |
1855
|
|
|
|
|
|
|
sub { |
1856
|
|
|
|
|
|
|
unshift \@XFD::AsHashHandlers, shift; |
1857
|
|
|
|
|
|
|
}, |
1858
|
|
|
|
|
|
|
\$h, |
1859
|
|
|
|
|
|
|
]; |
1860
|
|
|
|
|
|
|
} |
1861
|
|
|
|
|
|
|
else { |
1862
|
|
|
|
|
|
|
## TODO: do this at compile time. |
1863
|
|
|
|
|
|
|
die "EventPath function hash() requires a start_element or start_document\n"; |
1864
|
|
|
|
|
|
|
} |
1865
|
|
|
|
|
|
|
} # nodeset2hash |
1866
|
|
|
|
|
|
|
CODE_END |
1867
|
|
|
|
|
|
|
} |
1868
|
|
|
|
|
|
|
|
1869
|
|
|
|
|
|
|
########## |
1870
|
|
|
|
|
|
|
@XFD::nodeset2struct::ISA = qw( XFD::NodesetConverter ); |
1871
|
|
|
|
|
|
|
sub XFD::nodeset2struct::immed_code_template { |
1872
|
|
|
|
|
|
|
## This is used in cases where the location path can be |
1873
|
|
|
|
|
|
|
## evaluated immediately. |
1874
|
0
|
|
|
0
|
|
0
|
die "nodeset2struct::immed_code_template not implemented yet\n"; |
1875
|
0
|
|
|
|
|
0
|
return <
|
1876
|
|
|
|
|
|
|
do { ## nodeset2struct |
1877
|
|
|
|
|
|
|
my \$ctx = ( |
1878
|
|
|
|
|
|
|
|
1879
|
|
|
|
|
|
|
)[0]; |
1880
|
|
|
|
|
|
|
exists \$ctx->{Node}->{Value} |
1881
|
|
|
|
|
|
|
? \$ctx->{Node}->{Value} |
1882
|
|
|
|
|
|
|
: ""; |
1883
|
|
|
|
|
|
|
} # nodeset2struct |
1884
|
|
|
|
|
|
|
CODE_END |
1885
|
|
|
|
|
|
|
} |
1886
|
|
|
|
|
|
|
|
1887
|
|
|
|
|
|
|
|
1888
|
|
|
|
|
|
|
sub XFD::nodeset2struct::precursor_fetching_code { |
1889
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1890
|
0
|
|
|
|
|
0
|
my ( $precursor_number ) = @_; |
1891
|
|
|
|
|
|
|
|
1892
|
0
|
|
|
|
|
0
|
return qq{\$postponement->[_p_first_precursor+$precursor_number]->end_document}; |
1893
|
|
|
|
|
|
|
} |
1894
|
|
|
|
|
|
|
|
1895
|
|
|
|
|
|
|
@XFD::StructPostponer::ISA = qw( XFD::NodesetPostponer ); |
1896
|
|
|
|
|
|
|
sub XFD::StructPostponer::postponement_setting_code { |
1897
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1898
|
0
|
|
|
|
|
0
|
my $precursor_number = $self->[_np_precursor_number]; |
1899
|
|
|
|
|
|
|
## TODO: check to see if we really need this if EventType eq ... stuff |
1900
|
|
|
|
|
|
|
## it should be known at compile time, perhaps even just by dint of us |
1901
|
|
|
|
|
|
|
## setting the acceptable events for this opcode to be queued for. |
1902
|
0
|
|
|
|
|
0
|
return <
|
1903
|
|
|
|
|
|
|
unless ( defined \$postponement->[_p_first_precursor+$precursor_number] ) { ## nodeset2struct |
1904
|
|
|
|
|
|
|
if ( \$ctx->{EventType} eq "start_document" |
1905
|
|
|
|
|
|
|
|| \$ctx->{EventType} eq "start_element" |
1906
|
|
|
|
|
|
|
) { |
1907
|
|
|
|
|
|
|
## Note that, if this is one branch of a union, defining this |
1908
|
|
|
|
|
|
|
## precursor prevents the other branch of the union from also |
1909
|
|
|
|
|
|
|
## building a struct over top of this one. |
1910
|
|
|
|
|
|
|
## TODO: allow the caller to specify this class name |
1911
|
|
|
|
|
|
|
require XML::Filter::Dispatcher::AsStructHandler; |
1912
|
|
|
|
|
|
|
\$XFD::AsStructHandlers[0] ||= XML::Filter::Dispatcher::AsStructHandler->new; |
1913
|
|
|
|
|
|
|
my \$h = \$postponement->[_p_first_precursor+$precursor_number] = |
1914
|
|
|
|
|
|
|
shift \@XFD::AsStructHandlers; |
1915
|
|
|
|
|
|
|
|
1916
|
|
|
|
|
|
|
\$h->set_namespaces( \$d->{Namespaces} ? %{ \$d->{Namespaces} } : () ); |
1917
|
|
|
|
|
|
|
|
1918
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: precursor $precursor_number is handled by \$h" if is_tracing; |
1919
|
|
|
|
|
|
|
|
1920
|
|
|
|
|
|
|
\$h->start_document( {} ); ## superfluous in the current version, but just in case... |
1921
|
|
|
|
|
|
|
|
1922
|
|
|
|
|
|
|
my \$end_element = \$h->can( "end_element" ); |
1923
|
|
|
|
|
|
|
## nodeset2struct_start() will queue up the matching end_element |
1924
|
|
|
|
|
|
|
\$h->start_element( \$ctx->{Node} ) |
1925
|
|
|
|
|
|
|
if \$ctx->{EventType} eq "start_element"; |
1926
|
|
|
|
|
|
|
|
1927
|
|
|
|
|
|
|
nodeset2struct_start( |
1928
|
|
|
|
|
|
|
\$h, |
1929
|
|
|
|
|
|
|
\$h->can( "start_element" ), |
1930
|
|
|
|
|
|
|
\$h->can( "characters" ), |
1931
|
|
|
|
|
|
|
\$end_element, |
1932
|
|
|
|
|
|
|
); |
1933
|
|
|
|
|
|
|
|
1934
|
|
|
|
|
|
|
push \@{\$ctx->{EndSubs}}, [ |
1935
|
|
|
|
|
|
|
sub { |
1936
|
|
|
|
|
|
|
unshift \@XFD::AsStructHandlers, shift; |
1937
|
|
|
|
|
|
|
}, |
1938
|
|
|
|
|
|
|
\$h, |
1939
|
|
|
|
|
|
|
]; |
1940
|
|
|
|
|
|
|
} |
1941
|
|
|
|
|
|
|
else { |
1942
|
|
|
|
|
|
|
## TODO: do this at compile time. |
1943
|
|
|
|
|
|
|
die "EventPath function struct() requires a start_element or start_document\n"; |
1944
|
|
|
|
|
|
|
} |
1945
|
|
|
|
|
|
|
} # nodeset2struct |
1946
|
|
|
|
|
|
|
CODE_END |
1947
|
|
|
|
|
|
|
} |
1948
|
|
|
|
|
|
|
|
1949
|
|
|
|
|
|
|
########## |
1950
|
|
|
|
|
|
|
########## |
1951
|
|
|
|
|
|
|
@XFD::nodeset2number::ISA = qw( XFD::NodesetConverter ); |
1952
|
|
|
|
|
|
|
|
1953
|
|
|
|
|
|
|
sub XFD::nodeset2number::immed_code_template { |
1954
|
|
|
|
|
|
|
## This is used in cases where the location path can be |
1955
|
|
|
|
|
|
|
## evaluated immediately. |
1956
|
0
|
|
|
0
|
|
0
|
return <
|
1957
|
|
|
|
|
|
|
do { ## nodeset2number |
1958
|
|
|
|
|
|
|
my \$ctx = ( |
1959
|
|
|
|
|
|
|
|
1960
|
|
|
|
|
|
|
)[0]; |
1961
|
|
|
|
|
|
|
( exists \$ctx->{Node}->{Value} && _looks_numeric \$ctx->{Node}->{Value} ) |
1962
|
|
|
|
|
|
|
? 0 + \$ctx->{Node}->{Value} |
1963
|
|
|
|
|
|
|
: "NaN"; |
1964
|
|
|
|
|
|
|
} # nodeset2number |
1965
|
|
|
|
|
|
|
CODE_END |
1966
|
|
|
|
|
|
|
} |
1967
|
|
|
|
|
|
|
|
1968
|
|
|
|
|
|
|
|
1969
|
|
|
|
|
|
|
sub XFD::nodeset2number::precursor_fetching_code { |
1970
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1971
|
0
|
|
|
|
|
0
|
my ( $precursor_number ) = @_; |
1972
|
|
|
|
|
|
|
|
1973
|
0
|
|
|
|
|
0
|
return qq[do { |
1974
|
|
|
|
|
|
|
my \$string = \$postponement->[_p_first_precursor+$precursor_number]; |
1975
|
|
|
|
|
|
|
( defined \$string && _looks_numeric( \$string ) ) ? 0 + \$string |
1976
|
|
|
|
|
|
|
: "NaN" |
1977
|
|
|
|
|
|
|
}]; |
1978
|
|
|
|
|
|
|
} |
1979
|
|
|
|
|
|
|
|
1980
|
|
|
|
|
|
|
|
1981
|
|
|
|
|
|
|
## Collect text *just* like a string. |
1982
|
|
|
|
|
|
|
@XFD::NumberPostponer::ISA = qw( XFD::StringPostponer ); |
1983
|
|
|
|
|
|
|
|
1984
|
|
|
|
|
|
|
########## |
1985
|
|
|
|
|
|
|
@XFD::nodeset2boolean::ISA = qw( XFD::NodesetConverter ); |
1986
|
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
|
sub XFD::nodeset2boolean::immed_code_template { |
1988
|
0
|
|
|
0
|
|
0
|
return <
|
1989
|
|
|
|
|
|
|
( |
1990
|
|
|
|
|
|
|
scalar( ## nodeset2boolean |
1991
|
|
|
|
|
|
|
|
1992
|
|
|
|
|
|
|
) ? 1 : 0 |
1993
|
|
|
|
|
|
|
) # nodeset2boolean |
1994
|
|
|
|
|
|
|
CODE_END |
1995
|
|
|
|
|
|
|
} |
1996
|
|
|
|
|
|
|
|
1997
|
|
|
|
|
|
|
sub XFD::nodeset2boolean::precursor_fetching_code { |
1998
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
1999
|
0
|
|
|
|
|
0
|
my ( $precursor_number ) = @_; |
2000
|
|
|
|
|
|
|
|
2001
|
|
|
|
|
|
|
return |
2002
|
0
|
|
|
|
|
0
|
"( \$postponement->[_p_first_precursor+$precursor_number] || 0 )"; |
2003
|
|
|
|
|
|
|
} |
2004
|
|
|
|
|
|
|
|
2005
|
|
|
|
|
|
|
|
2006
|
0
|
|
|
0
|
|
0
|
sub XFD::nodeset2boolean::default_value_code { '""' }; |
2007
|
|
|
|
|
|
|
|
2008
|
|
|
|
|
|
|
@XFD::BooleanPostponer::ISA = qw( XFD::NodesetPostponer ); |
2009
|
|
|
|
|
|
|
sub XFD::BooleanPostponer::postponement_setting_code { |
2010
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2011
|
0
|
|
|
|
|
0
|
my $precursor_number = $self->[_np_precursor_number]; |
2012
|
0
|
|
|
|
|
0
|
return <
|
2013
|
|
|
|
|
|
|
\$postponement->[_p_first_precursor+$precursor_number] = 1; ## nodeset2boolean: if we got here, the nodeset is non-empty. |
2014
|
|
|
|
|
|
|
CODE_END |
2015
|
|
|
|
|
|
|
} |
2016
|
|
|
|
|
|
|
|
2017
|
|
|
|
|
|
|
########## |
2018
|
|
|
|
|
|
|
@XFD::nodeset2nodeset::ISA = qw( XFD::NodesetConverter ); |
2019
|
|
|
|
|
|
|
sub XFD::nodeset2nodeset::immed_code_template { |
2020
|
0
|
|
|
0
|
|
0
|
return ""; |
2021
|
|
|
|
|
|
|
} |
2022
|
|
|
|
|
|
|
|
2023
|
|
|
|
|
|
|
|
2024
|
|
|
|
|
|
|
sub XFD::nodeset2nodeset::precursor_fetching_code { |
2025
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2026
|
0
|
|
|
|
|
0
|
my ( $precursor_number ) = @_; |
2027
|
|
|
|
|
|
|
|
2028
|
|
|
|
|
|
|
return |
2029
|
0
|
|
|
|
|
0
|
"( \$postponement->[_p_first_precursor+$precursor_number] || \$ctx )"; |
2030
|
|
|
|
|
|
|
} |
2031
|
|
|
|
|
|
|
|
2032
|
|
|
|
|
|
|
############################################################################### |
2033
|
|
|
|
|
|
|
## |
2034
|
|
|
|
|
|
|
## User Visible Functions |
2035
|
|
|
|
|
|
|
## |
2036
|
|
|
|
|
|
|
## These (and only these) must all be in the XFD::Function::* namespaces, |
2037
|
|
|
|
|
|
|
## so function() can find them. They derive from a subclass that indicates |
2038
|
|
|
|
|
|
|
## their return types so munge_parms() can figure out what it's parameters |
2039
|
|
|
|
|
|
|
## return. |
2040
|
|
|
|
|
|
|
## |
2041
|
|
|
|
|
|
|
|
2042
|
|
|
|
|
|
|
## The first "$_[0]" in this: |
2043
|
|
|
|
|
|
|
## shift->build_expr( 1, 1, $_[0], sub { $_[0] } ); |
2044
|
|
|
|
|
|
|
## is $context. |
2045
|
|
|
|
|
|
|
|
2046
|
|
|
|
|
|
|
########## |
2047
|
|
|
|
|
|
|
|
2048
|
|
|
|
|
|
|
@XFD::Function::boolean::ISA = qw( XFD::BooleanFunction ); |
2049
|
|
|
|
|
|
|
sub XFD::Function::boolean::as_immed_code { |
2050
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { $_[0] } ); |
|
0
|
|
|
0
|
|
0
|
|
2051
|
|
|
|
|
|
|
} |
2052
|
|
|
|
|
|
|
########## |
2053
|
|
|
|
|
|
|
@XFD::Function::ceiling::ISA = qw( XFD::NumericFunction ); |
2054
|
|
|
|
|
|
|
sub XFD::Function::ceiling::as_immed_code { |
2055
|
0
|
|
|
0
|
|
0
|
require POSIX; |
2056
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub {"POSIX::ceil( $_[0] )" } ); |
|
0
|
|
|
|
|
0
|
|
2057
|
|
|
|
|
|
|
} |
2058
|
|
|
|
|
|
|
########## |
2059
|
|
|
|
|
|
|
@XFD::Function::concat::ISA = qw( XFD::StringFunction ); |
2060
|
|
|
|
|
|
|
sub XFD::Function::concat::as_immed_code { |
2061
|
|
|
|
|
|
|
shift->build_expr( 2, undef, $_[0], sub { |
2062
|
0
|
|
|
0
|
|
0
|
"join( '', " . join( ", ", @_ ) . " )"; |
2063
|
0
|
|
|
0
|
|
0
|
} ); |
2064
|
|
|
|
|
|
|
} |
2065
|
|
|
|
|
|
|
########## |
2066
|
|
|
|
|
|
|
@XFD::Function::contains::ISA = qw( XFD::BooleanFunction ); |
2067
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::contains::parm_type { "string" } |
2068
|
|
|
|
|
|
|
sub XFD::Function::contains::as_immed_code { |
2069
|
|
|
|
|
|
|
shift->build_expr( 2, 2, $_[0], sub { |
2070
|
0
|
|
|
0
|
|
0
|
"0 <= index( " . join( ", ", @_ ) . " )"; |
2071
|
0
|
|
|
0
|
|
0
|
} ); |
2072
|
|
|
|
|
|
|
} |
2073
|
|
|
|
|
|
|
########## |
2074
|
|
|
|
|
|
|
@XFD::Function::false::ISA = qw( XFD::BooleanFunction ); |
2075
|
|
|
|
|
|
|
sub XFD::Function::false::as_immed_code { |
2076
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 0, 0, $_[0], sub { "0" } ); |
|
0
|
|
|
0
|
|
0
|
|
2077
|
|
|
|
|
|
|
} |
2078
|
|
|
|
|
|
|
########## |
2079
|
|
|
|
|
|
|
@XFD::Function::floor::ISA = qw( XFD::NumericFunction ); |
2080
|
|
|
|
|
|
|
sub XFD::Function::floor::as_immed_code { |
2081
|
0
|
|
|
0
|
|
0
|
require POSIX; |
2082
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub {"POSIX::floor( $_[0] )"} ); |
|
0
|
|
|
|
|
0
|
|
2083
|
|
|
|
|
|
|
} |
2084
|
|
|
|
|
|
|
########## |
2085
|
|
|
|
|
|
|
@XFD::Function::hash::ISA = qw( XFD::NodesetFunction ); |
2086
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::hash::result_type { "hash" } |
2087
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::hash::parm_type { "hash" } |
2088
|
|
|
|
|
|
|
sub XFD::Function::hash::new { |
2089
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NodesetFunction::new( @_ ); |
2090
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2091
|
0
|
|
|
|
|
0
|
return $self; |
2092
|
|
|
|
|
|
|
} |
2093
|
|
|
|
|
|
|
|
2094
|
|
|
|
|
|
|
sub XFD::Function::hash::as_immed_code { |
2095
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { $_[0] } ); |
|
0
|
|
|
0
|
|
0
|
|
2096
|
|
|
|
|
|
|
} |
2097
|
|
|
|
|
|
|
########## |
2098
|
|
|
|
|
|
|
@XFD::Function::normalize_space::ISA = qw( XFD::StringFunction ); |
2099
|
|
|
|
|
|
|
sub XFD::Function::normalize_space::new { |
2100
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::StringFunction::new( @_ ); |
2101
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2102
|
0
|
|
|
|
|
0
|
return $self; |
2103
|
|
|
|
|
|
|
} |
2104
|
|
|
|
|
|
|
|
2105
|
|
|
|
|
|
|
sub XFD::Function::normalize_space::as_immed_code { |
2106
|
|
|
|
|
|
|
## We don't do the argless version because we can't for all nodes, since |
2107
|
|
|
|
|
|
|
## that would require keeping entire subtrees around. We might be |
2108
|
|
|
|
|
|
|
## able to do it for attributes and leaf elements, throwing an error |
2109
|
|
|
|
|
|
|
## at runtime if the node is not a leaf node. |
2110
|
|
|
|
|
|
|
shift->build_expr( 1, 1, $_[0], sub { |
2111
|
0
|
|
|
0
|
|
0
|
"do { my \$s = $_[0]; \$s =~ s/^[ \\t\\r\\n]+//; \$s =~ s/[ \\t\\r\\n]+(?!\\n)\\Z//; \$s =~ s/[ \\t\\r\\n]+/ /g; \$s }"; |
2112
|
0
|
|
|
0
|
|
0
|
} ); |
2113
|
|
|
|
|
|
|
|
2114
|
|
|
|
|
|
|
} |
2115
|
|
|
|
|
|
|
########## |
2116
|
|
|
|
|
|
|
@XFD::Function::not::ISA = qw( XFD::BooleanFunction ); |
2117
|
|
|
|
|
|
|
sub XFD::Function::not::as_immed_code { |
2118
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { "! $_[0]" } ); |
|
0
|
|
|
0
|
|
0
|
|
2119
|
|
|
|
|
|
|
} |
2120
|
|
|
|
|
|
|
########## |
2121
|
|
|
|
|
|
|
@XFD::Function::number::ISA = qw( XFD::NumericFunction ); |
2122
|
|
|
|
|
|
|
sub XFD::Function::number::new { |
2123
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NumericFunction::new( @_ ); |
2124
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2125
|
0
|
|
|
|
|
0
|
return $self; |
2126
|
|
|
|
|
|
|
} |
2127
|
|
|
|
|
|
|
sub XFD::Function::number::as_immed_code { |
2128
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { $_[0] } ); |
|
0
|
|
|
0
|
|
0
|
|
2129
|
|
|
|
|
|
|
} |
2130
|
|
|
|
|
|
|
########## |
2131
|
|
|
|
|
|
|
@XFD::Function::local_name::ISA = qw( XFD::NodesetFunction ); |
2132
|
|
|
|
|
|
|
sub XFD::Function::local_name::new { |
2133
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NodesetFunction::new( @_ ); |
2134
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2135
|
0
|
|
|
|
|
0
|
return $self; |
2136
|
|
|
|
|
|
|
} |
2137
|
|
|
|
|
|
|
sub XFD::Function::local_name::as_immed_code { |
2138
|
|
|
|
|
|
|
shift->build_expr( 1, 1, $_[0], sub { |
2139
|
0
|
|
|
0
|
|
0
|
"( exists( $_[0]\->{Node}->{LocalName} ) && $_[0]\->{Node}->{LocalName} ) || \"\""; |
2140
|
0
|
|
|
0
|
|
0
|
} ); |
2141
|
|
|
|
|
|
|
} |
2142
|
|
|
|
|
|
|
########## |
2143
|
|
|
|
|
|
|
@XFD::Function::name::ISA = qw( XFD::NodesetFunction ); |
2144
|
|
|
|
|
|
|
sub XFD::Function::name::new { |
2145
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NodesetFunction::new( @_ ); |
2146
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2147
|
0
|
|
|
|
|
0
|
return $self; |
2148
|
|
|
|
|
|
|
} |
2149
|
|
|
|
|
|
|
sub XFD::Function::name::as_immed_code { |
2150
|
|
|
|
|
|
|
shift->build_expr( 1, 1, $_[0], sub { |
2151
|
0
|
|
|
0
|
|
0
|
"( exists( $_[0]\->{Node}->{Name} ) && $_[0]\->{Node}->{Name} ) || \"\""; |
2152
|
0
|
|
|
0
|
|
0
|
} ); |
2153
|
|
|
|
|
|
|
} |
2154
|
|
|
|
|
|
|
########## |
2155
|
|
|
|
|
|
|
@XFD::Function::namespace_uri::ISA = qw( XFD::NodesetFunction ); |
2156
|
|
|
|
|
|
|
sub XFD::Function::namespace_uri::new { |
2157
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NodesetFunction::new( @_ ); |
2158
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2159
|
0
|
|
|
|
|
0
|
return $self; |
2160
|
|
|
|
|
|
|
} |
2161
|
|
|
|
|
|
|
sub XFD::Function::namespace_uri::as_immed_code { |
2162
|
|
|
|
|
|
|
shift->build_expr( 1, 1, $_[0], sub { |
2163
|
0
|
|
|
0
|
|
0
|
"( defined( $_[0]\->{Node}->{NamespaceURI} ) ? $_[0]\->{Node}->{NamespaceURI} : \"\" )"; |
2164
|
0
|
|
|
0
|
|
0
|
} ); |
2165
|
|
|
|
|
|
|
} |
2166
|
|
|
|
|
|
|
########## |
2167
|
|
|
|
|
|
|
@XFD::Function::round::ISA = qw( XFD::NumericFunction ); |
2168
|
|
|
|
|
|
|
sub XFD::Function::round::as_immed_code { |
2169
|
0
|
|
|
0
|
|
0
|
require POSIX; |
2170
|
|
|
|
|
|
|
## Expressly ignoring the -0 conditions in the spec. |
2171
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub {"POSIX::floor( $_[0] + 0.5 )"} ); |
|
0
|
|
|
|
|
0
|
|
2172
|
|
|
|
|
|
|
} |
2173
|
|
|
|
|
|
|
########## |
2174
|
|
|
|
|
|
|
@XFD::Function::starts_with::ISA = qw( XFD::BooleanFunction ); |
2175
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::starts_with::parm_type { "string" } |
2176
|
|
|
|
|
|
|
sub XFD::Function::starts_with::as_immed_code { |
2177
|
|
|
|
|
|
|
shift->build_expr( 2, 2, $_[0], sub { |
2178
|
0
|
|
|
0
|
|
0
|
"0 == index( " . join( ", ", @_ ) . " )"; |
2179
|
0
|
|
|
0
|
|
0
|
} ); |
2180
|
|
|
|
|
|
|
} |
2181
|
|
|
|
|
|
|
########## |
2182
|
|
|
|
|
|
|
@XFD::Function::string::ISA = qw( XFD::StringFunction ); |
2183
|
|
|
|
|
|
|
sub XFD::Function::string::new { |
2184
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::StringFunction::new( @_ ); |
2185
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2186
|
0
|
|
|
|
|
0
|
return $self; |
2187
|
|
|
|
|
|
|
} |
2188
|
|
|
|
|
|
|
|
2189
|
|
|
|
|
|
|
sub XFD::Function::string::as_immed_code { |
2190
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { $_[0] } ); |
|
0
|
|
|
0
|
|
0
|
|
2191
|
|
|
|
|
|
|
} |
2192
|
|
|
|
|
|
|
########## |
2193
|
|
|
|
|
|
|
@XFD::Function::string_length::ISA = qw( XFD::NumericFunction ); |
2194
|
|
|
|
|
|
|
sub XFD::Function::string_length::new { |
2195
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NumericFunction::new( @_ ); |
2196
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2197
|
0
|
|
|
|
|
0
|
return $self; |
2198
|
|
|
|
|
|
|
} |
2199
|
|
|
|
|
|
|
|
2200
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::string_length::parm_type { "string" } |
2201
|
|
|
|
|
|
|
sub XFD::Function::string_length::as_immed_code { |
2202
|
|
|
|
|
|
|
## We don't do string-length() because we can't for all nodes, since |
2203
|
|
|
|
|
|
|
## that would require keeping entire subtrees around. We might be |
2204
|
|
|
|
|
|
|
## able to do it for attributes and leaf elements, throwing an error |
2205
|
|
|
|
|
|
|
## at runtime if the node is not a leaf node. |
2206
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { "length( $_[0] )" } ); |
|
0
|
|
|
0
|
|
0
|
|
2207
|
|
|
|
|
|
|
} |
2208
|
|
|
|
|
|
|
########## |
2209
|
|
|
|
|
|
|
@XFD::Function::struct::ISA = qw( XFD::NodesetFunction ); |
2210
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::struct::result_type { "struct" } |
2211
|
0
|
|
|
0
|
|
0
|
sub XFD::Function::struct::parm_type { "struct" } |
2212
|
|
|
|
|
|
|
sub XFD::Function::struct::new { |
2213
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::NodesetFunction::new( @_ ); |
2214
|
0
|
0
|
|
|
|
0
|
push @$self, XFD::self_node->new unless @$self; |
2215
|
0
|
|
|
|
|
0
|
return $self; |
2216
|
|
|
|
|
|
|
} |
2217
|
|
|
|
|
|
|
|
2218
|
|
|
|
|
|
|
sub XFD::Function::struct::as_immed_code { |
2219
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 1, 1, $_[0], sub { $_[0] } ); |
|
0
|
|
|
0
|
|
0
|
|
2220
|
|
|
|
|
|
|
} |
2221
|
|
|
|
|
|
|
########## |
2222
|
|
|
|
|
|
|
@XFD::Function::substring::ISA = qw( XFD::StringFunction ); |
2223
|
|
|
|
|
|
|
sub XFD::Function::substring::parm_type { |
2224
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2225
|
0
|
0
|
|
|
|
0
|
return shift == 0 ? "string" : "int"; |
2226
|
|
|
|
|
|
|
} |
2227
|
|
|
|
|
|
|
|
2228
|
|
|
|
|
|
|
sub XFD::Function::substring::as_immed_code { |
2229
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2230
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
2231
|
|
|
|
|
|
|
|
2232
|
0
|
|
|
|
|
0
|
my @args = $self->munge_parms( 2, 3, $context ); |
2233
|
|
|
|
|
|
|
|
2234
|
0
|
|
|
|
|
0
|
my @is_constant = map $_->is_constant, @$self; |
2235
|
|
|
|
|
|
|
|
2236
|
0
|
|
|
|
|
0
|
my $code; |
2237
|
0
|
0
|
|
|
|
0
|
if ( @args == 2 ) { |
2238
|
0
|
|
|
|
|
0
|
my $pos_code = |
2239
|
|
|
|
|
|
|
"do { my \$pos = $args[1] - 1; \$pos = 0 if \$pos < 0; \$pos}"; |
2240
|
|
|
|
|
|
|
|
2241
|
0
|
0
|
|
|
|
0
|
$pos_code = _eval_at_compile_time "number", $pos_code, $context |
2242
|
|
|
|
|
|
|
if $is_constant[1]; |
2243
|
0
|
|
|
|
|
0
|
$code = "substr( $args[0], $pos_code )"; |
2244
|
|
|
|
|
|
|
} |
2245
|
|
|
|
|
|
|
else { |
2246
|
|
|
|
|
|
|
## must be 3 arg form. |
2247
|
0
|
|
|
|
|
0
|
my $pos_len_code = |
2248
|
|
|
|
|
|
|
"do { my ( \$pos, \$len ) = ( $args[1] - 1, $args[2] ); my \$end = \$pos + \$len; \$pos = 0 if \$pos < 0; \$len = \$end - \$pos ; \$len = 0 if \$len < 0; ( \$pos, \$len ) }"; |
2249
|
|
|
|
|
|
|
|
2250
|
|
|
|
|
|
|
## Not bothering to optimize the substring( , , ) |
2251
|
|
|
|
|
|
|
## situation, only substring( , , ) |
2252
|
|
|
|
|
|
|
|
2253
|
0
|
0
|
0
|
|
|
0
|
if ( $is_constant[1] && $is_constant[2] ) { |
2254
|
0
|
0
|
|
|
|
0
|
my ( $pos, $len ) = eval $pos_len_code |
2255
|
|
|
|
|
|
|
or die "$! executing XPath (number, number) $pos_len_code at compile time\n"; |
2256
|
0
|
|
|
|
|
0
|
$code = "substr( $args[0], $pos, $len )" ; |
2257
|
|
|
|
|
|
|
} |
2258
|
|
|
|
|
|
|
else { |
2259
|
0
|
|
|
|
|
0
|
$code = "substr( $args[0], $pos_len_code )" ; |
2260
|
|
|
|
|
|
|
} |
2261
|
|
|
|
|
|
|
} |
2262
|
|
|
|
|
|
|
|
2263
|
0
|
0
|
|
|
|
0
|
$code = _eval_at_compile_time "string", $code, $context |
2264
|
|
|
|
|
|
|
if $self->is_constant; |
2265
|
|
|
|
|
|
|
|
2266
|
0
|
|
|
|
|
0
|
return $code; |
2267
|
|
|
|
|
|
|
} |
2268
|
|
|
|
|
|
|
########## |
2269
|
|
|
|
|
|
|
@XFD::Function::substring_after::ISA = qw( XFD::StringFunction ); |
2270
|
|
|
|
|
|
|
sub XFD::Function::substring_after::as_immed_code { |
2271
|
|
|
|
|
|
|
shift->build_expr( 2, 2, $_[0], sub { |
2272
|
0
|
|
|
0
|
|
0
|
"do { my ( \$s, \$ss ) = ( $_[0], $_[1] ); my \$pos = index \$s, \$ss; \$pos >= 0 ? substr \$s, \$pos + length \$ss : '' }"; |
2273
|
0
|
|
|
0
|
|
0
|
} ); |
2274
|
|
|
|
|
|
|
} |
2275
|
|
|
|
|
|
|
########## |
2276
|
|
|
|
|
|
|
@XFD::Function::substring_before::ISA = qw( XFD::StringFunction ); |
2277
|
|
|
|
|
|
|
sub XFD::Function::substring_before::as_immed_code { |
2278
|
|
|
|
|
|
|
shift->build_expr( 2, 2, $_[0], sub { |
2279
|
0
|
|
|
0
|
|
0
|
"do { my \$s = $_[0]; my \$pos = index \$s, $_[1]; \$pos >= 0 ? substr \$s, 0, \$pos : '' }"; |
2280
|
0
|
|
|
0
|
|
0
|
} ); |
2281
|
|
|
|
|
|
|
} |
2282
|
|
|
|
|
|
|
########## |
2283
|
|
|
|
|
|
|
@XFD::Function::translate::ISA = qw( XFD::StringFunction ); |
2284
|
|
|
|
|
|
|
sub XFD::Function::translate::as_immed_code { |
2285
|
|
|
|
|
|
|
## We don't implement the argless version because we can't for all nodes, |
2286
|
|
|
|
|
|
|
## since that would require keeping entire subtrees around. We might be |
2287
|
|
|
|
|
|
|
## able to do it for attributes and leaf elements, throwing an error |
2288
|
|
|
|
|
|
|
## at runtime if the node is not a leaf node. |
2289
|
|
|
|
|
|
|
|
2290
|
|
|
|
|
|
|
## TODO: verify that quotemeta is really enough and is correct, here. |
2291
|
|
|
|
|
|
|
|
2292
|
|
|
|
|
|
|
## We don't handle the case where only one of $from and $to is constant, |
2293
|
|
|
|
|
|
|
## should be rare (hell, just seeing translate() anywhere should be rare). |
2294
|
|
|
|
|
|
|
## This was not true for substring() above, which I suspect will be |
2295
|
|
|
|
|
|
|
## called a bit more than translate(). |
2296
|
|
|
|
|
|
|
shift->build_expr( 3, 3, $_[0], sub { |
2297
|
0
|
|
|
0
|
|
0
|
"do { my ( \$s, \$f, \$t ) = ( $_[0], quotemeta $_[1], quotemeta $_[2] ); eval qq{\\\$s =~ tr/\$f/\$t/d}; \$s }"; |
2298
|
0
|
|
|
0
|
|
0
|
} ); |
2299
|
|
|
|
|
|
|
} |
2300
|
|
|
|
|
|
|
########## |
2301
|
|
|
|
|
|
|
@XFD::Function::true::ISA = qw( XFD::BooleanFunction ); |
2302
|
|
|
|
|
|
|
sub XFD::Function::true::as_immed_code { |
2303
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 0, 0, $_[0], sub { "1" } ); |
|
0
|
|
|
0
|
|
0
|
|
2304
|
|
|
|
|
|
|
} |
2305
|
|
|
|
|
|
|
|
2306
|
|
|
|
|
|
|
############################################################################### |
2307
|
|
|
|
|
|
|
## |
2308
|
|
|
|
|
|
|
## Variable references |
2309
|
|
|
|
|
|
|
## |
2310
|
|
|
|
|
|
|
@XFD::VariableReference::ISA = qw( XFD::Op ); |
2311
|
0
|
|
|
0
|
|
0
|
sub XFD::VariableReference::is_constant { 0 } |
2312
|
0
|
|
|
0
|
|
0
|
sub XFD::VariableReference::result_type { "any" } |
2313
|
|
|
|
|
|
|
sub XFD::VariableReference::as_immed_code { |
2314
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2315
|
0
|
|
|
|
|
0
|
my $var_name = $self->[0]; |
2316
|
0
|
|
|
|
|
0
|
return "\$d->_look_up_var( '$var_name' )"; |
2317
|
|
|
|
|
|
|
} |
2318
|
|
|
|
|
|
|
|
2319
|
|
|
|
|
|
|
############################################################################### |
2320
|
|
|
|
|
|
|
## |
2321
|
|
|
|
|
|
|
## Operators (other than Union) |
2322
|
|
|
|
|
|
|
## |
2323
|
|
|
|
|
|
|
sub _compile_relational_ops { |
2324
|
6
|
|
|
6
|
|
11
|
my ( $name, $numeric_op, $string_op ) = @_; |
2325
|
6
|
|
|
|
|
12
|
for ( qw( boolean number string ) ) { |
2326
|
18
|
|
|
|
|
34
|
my $class = "XFD::Operator::${_}_${name}"; |
2327
|
18
|
100
|
|
|
|
41
|
my $op = $_ ne "string" ? $numeric_op : $string_op; |
2328
|
|
|
|
|
|
|
|
2329
|
1
|
|
|
1
|
|
8
|
no strict "refs"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
226
|
|
2330
|
18
|
|
|
|
|
18
|
@{"${class}::ISA"} = qw( XFD::BooleanFunction ); |
|
18
|
|
|
|
|
291
|
|
2331
|
18
|
|
|
0
|
|
1505
|
eval <
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
2332
|
|
|
|
|
|
|
sub ${class}::parm_type { "$_" } |
2333
|
|
|
|
|
|
|
sub ${class}::as_immed_code { |
2334
|
|
|
|
|
|
|
shift->build_expr( 2, 2, \$_[0], sub { "( \$_[0] $op \$_[1] )" } ); |
2335
|
|
|
|
|
|
|
} |
2336
|
|
|
|
|
|
|
CODE_END |
2337
|
|
|
|
|
|
|
} |
2338
|
|
|
|
|
|
|
} |
2339
|
|
|
|
|
|
|
|
2340
|
|
|
|
|
|
|
|
2341
|
|
|
|
|
|
|
sub relational_op { |
2342
|
0
|
|
|
0
|
|
0
|
my ( $op_name, $parm1, $parm2 ) = @_; |
2343
|
0
|
|
|
|
|
0
|
my $foo = $parm1->result_type . "|" . $parm2->result_type; |
2344
|
0
|
|
|
|
|
0
|
for (qw( boolean number string )) { |
2345
|
0
|
0
|
|
|
|
0
|
if ( 0 <= index $foo, $_ ) { |
2346
|
0
|
|
|
|
|
0
|
my $class = "XFD::Operator::${_}_${op_name}"; |
2347
|
0
|
|
|
|
|
0
|
return $class->new( $parm1, $parm2 ); |
2348
|
|
|
|
|
|
|
} |
2349
|
|
|
|
|
|
|
} |
2350
|
0
|
|
|
|
|
0
|
die "Couldn't discern a parameter type in $foo"; |
2351
|
|
|
|
|
|
|
} |
2352
|
|
|
|
|
|
|
|
2353
|
|
|
|
|
|
|
|
2354
|
|
|
|
|
|
|
sub _compile_math_op { |
2355
|
5
|
|
|
5
|
|
7
|
my ( $name, $op ) = @_; |
2356
|
|
|
|
|
|
|
|
2357
|
5
|
|
|
|
|
9
|
my $class = "XFD::Operator::${name}"; |
2358
|
|
|
|
|
|
|
|
2359
|
1
|
|
|
1
|
|
5
|
no strict "refs"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11536
|
|
2360
|
5
|
|
|
|
|
6
|
@{"${class}::ISA"} = qw( XFD::NumericFunction ); |
|
5
|
|
|
|
|
84
|
|
2361
|
5
|
|
|
0
|
|
417
|
eval <
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
0
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
2362
|
|
|
|
|
|
|
sub ${class}::as_immed_code { |
2363
|
|
|
|
|
|
|
shift->build_expr( 2, 2, \$_[0], sub { "( \$_[0] $op \$_[1] )" } ); |
2364
|
|
|
|
|
|
|
} |
2365
|
|
|
|
|
|
|
CODE_END |
2366
|
|
|
|
|
|
|
} |
2367
|
|
|
|
|
|
|
|
2368
|
|
|
|
|
|
|
|
2369
|
|
|
|
|
|
|
sub math_op { |
2370
|
0
|
|
|
0
|
|
0
|
my ( $name, $parm1, $parm2 ) = @_; |
2371
|
0
|
|
|
|
|
0
|
my $class = "XFD::Operator::$name"; |
2372
|
0
|
|
|
|
|
0
|
return $class->new( $parm1, $parm2 ); |
2373
|
|
|
|
|
|
|
} |
2374
|
|
|
|
|
|
|
|
2375
|
|
|
|
|
|
|
########## |
2376
|
|
|
|
|
|
|
@XFD::Parens::ISA = qw( XFD::Function ); |
2377
|
0
|
|
|
0
|
|
0
|
sub XFD::Parens::result_type { shift->[0]->result_type } |
2378
|
0
|
|
|
0
|
|
0
|
sub XFD::Parens::as_immed_code { join shift->[0]->as_immed_code( @_ ), "( ", " )" } |
2379
|
|
|
|
|
|
|
########## |
2380
|
|
|
|
|
|
|
@XFD::Negation::ISA = qw( XFD::NumericFunction ); |
2381
|
|
|
|
|
|
|
sub XFD::Negation::as_immed_code { |
2382
|
|
|
|
|
|
|
shift->build_expr( 1, 1, $_[0], |
2383
|
0
|
|
|
0
|
|
0
|
sub { "do { my \$n = $_[0]; \$n eq 'NaN' ? \$n : 0-\$n }" } |
2384
|
0
|
|
|
0
|
|
0
|
); |
2385
|
|
|
|
|
|
|
} |
2386
|
|
|
|
|
|
|
########## |
2387
|
|
|
|
|
|
|
@XFD::Operator::and::ISA = qw( XFD::BooleanFunction ); |
2388
|
|
|
|
|
|
|
sub XFD::Operator::and::as_immed_code { |
2389
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 2, 2, $_[0], sub { "( $_[0] and $_[1] )" } ); |
|
0
|
|
|
0
|
|
0
|
|
2390
|
|
|
|
|
|
|
} |
2391
|
|
|
|
|
|
|
########## |
2392
|
|
|
|
|
|
|
@XFD::Operator::or::ISA = qw( XFD::BooleanFunction ); |
2393
|
|
|
|
|
|
|
sub XFD::Operator::or::as_immed_code { |
2394
|
0
|
|
|
0
|
|
0
|
shift->build_expr( 2, 2, $_[0], sub { "( $_[0] or $_[1] )" } ); |
|
0
|
|
|
0
|
|
0
|
|
2395
|
|
|
|
|
|
|
} |
2396
|
|
|
|
|
|
|
########## |
2397
|
|
|
|
|
|
|
## |
2398
|
|
|
|
|
|
|
## Relational ops |
2399
|
|
|
|
|
|
|
## |
2400
|
|
|
|
|
|
|
_compile_relational_ops equals => "==", "eq"; |
2401
|
|
|
|
|
|
|
_compile_relational_ops not_equals => "!=", "ne"; |
2402
|
|
|
|
|
|
|
_compile_relational_ops lt => "<" , "lt"; |
2403
|
|
|
|
|
|
|
_compile_relational_ops lte => "<=", "le"; |
2404
|
|
|
|
|
|
|
_compile_relational_ops gt => ">" , "gt"; |
2405
|
|
|
|
|
|
|
_compile_relational_ops gte => ">=", "ge"; |
2406
|
|
|
|
|
|
|
########## |
2407
|
|
|
|
|
|
|
_compile_math_op addition => "+"; |
2408
|
|
|
|
|
|
|
_compile_math_op subtraction => "-"; |
2409
|
|
|
|
|
|
|
_compile_math_op multiplication => "*"; |
2410
|
|
|
|
|
|
|
_compile_math_op division => "/"; |
2411
|
|
|
|
|
|
|
_compile_math_op modulus => "%"; |
2412
|
|
|
|
|
|
|
|
2413
|
|
|
|
|
|
|
############################################################################### |
2414
|
|
|
|
|
|
|
## |
2415
|
|
|
|
|
|
|
## Location Path Tests |
2416
|
|
|
|
|
|
|
## |
2417
|
|
|
|
|
|
|
## As the |
2418
|
|
|
|
|
|
|
## grammar parses a location path, it stringse these objects together. |
2419
|
|
|
|
|
|
|
## When a location path has been completely assembed, the objects |
2420
|
|
|
|
|
|
|
## are converted in to code. This is necessary because paths are recognized |
2421
|
|
|
|
|
|
|
## from left to right by the grammar, but need to be assembled right |
2422
|
|
|
|
|
|
|
## to left. We could use closure to accomplish this, but closures leak |
2423
|
|
|
|
|
|
|
## in different ways in different perls. |
2424
|
|
|
|
|
|
|
## |
2425
|
|
|
|
|
|
|
@XFD::doc_node::ISA = qw( XFD::PathTest ); |
2426
|
|
|
|
|
|
|
|
2427
|
0
|
|
|
0
|
|
0
|
sub XFD::doc_node::optim_signature { ref shift } |
2428
|
|
|
|
|
|
|
|
2429
|
|
|
|
|
|
|
sub XFD::doc_node::possible_event_type_map { |
2430
|
|
|
|
|
|
|
## This is because there's no surrounding context for this, ever, |
2431
|
|
|
|
|
|
|
## so we need to bootstrap $context->{PossibleEventTypes} by |
2432
|
|
|
|
|
|
|
## circumventing XSF::PathTest::possible_event_types() with our |
2433
|
|
|
|
|
|
|
## own. Defining *this* sub cause our possible_event_types() to |
2434
|
|
|
|
|
|
|
## be called. |
2435
|
0
|
|
|
0
|
|
0
|
confess "this is a DUMMY to force possibe_event_types to be called"; |
2436
|
|
|
|
|
|
|
} |
2437
|
|
|
|
|
|
|
|
2438
|
|
|
|
|
|
|
|
2439
|
|
|
|
|
|
|
## TODO: see if we really need end_document here (and end_element in other places) |
2440
|
|
|
|
|
|
|
#sub XFD::doc_node::possible_event_types { qw( start_document end_document ) } |
2441
|
0
|
|
|
0
|
|
0
|
sub XFD::doc_node::possible_event_types { qw( start_document end_document ) } |
2442
|
|
|
|
|
|
|
|
2443
|
|
|
|
|
|
|
sub XFD::doc_node::incr_code_template { |
2444
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2445
|
0
|
|
|
|
|
0
|
return <
|
2446
|
|
|
|
|
|
|
## doc_node |
2447
|
|
|
|
|
|
|
|
2448
|
|
|
|
|
|
|
# end doc_node |
2449
|
|
|
|
|
|
|
CODE_END |
2450
|
|
|
|
|
|
|
} |
2451
|
|
|
|
|
|
|
|
2452
|
|
|
|
|
|
|
|
2453
|
|
|
|
|
|
|
########## |
2454
|
|
|
|
|
|
|
@XFD::self_node::ISA = qw( XFD::PathTest ); |
2455
|
|
|
|
|
|
|
|
2456
|
|
|
|
|
|
|
sub XFD::self_node::curry_tests { |
2457
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2458
|
|
|
|
|
|
|
|
2459
|
|
|
|
|
|
|
## If this is *not* a standalone, then it's basically a noop, so |
2460
|
|
|
|
|
|
|
## delegate to the next test. |
2461
|
0
|
0
|
|
|
|
0
|
return $self->[_next]->curry_tests |
2462
|
|
|
|
|
|
|
if defined $self->[_next]; |
2463
|
|
|
|
|
|
|
|
2464
|
|
|
|
|
|
|
## Otherwise, return every node test type. This happens when '.' |
2465
|
|
|
|
|
|
|
## is the entire location path |
2466
|
0
|
|
|
|
|
0
|
@all_curry_tests; |
2467
|
|
|
|
|
|
|
} |
2468
|
|
|
|
|
|
|
|
2469
|
|
|
|
|
|
|
# This little method lets rules like '@*' => [ 'string()' => sub { ... } ] |
2470
|
|
|
|
|
|
|
# work: it checks to see if it will only be called in an attribute context and |
2471
|
|
|
|
|
|
|
# returns the current node. This works because 'string()' is really |
2472
|
|
|
|
|
|
|
# 'string(.)', which is really a function call to string() with self_node |
2473
|
|
|
|
|
|
|
# as its first parameter. So, if self_node can only be interpreted in |
2474
|
|
|
|
|
|
|
# attribute context, then it returns $ctx as immediate code. Otherwise |
2475
|
|
|
|
|
|
|
# it lets XFD::PathTest precursorize thie and tell get_expr_code to |
2476
|
|
|
|
|
|
|
# wait and then look in the postponement for its answer. |
2477
|
|
|
|
|
|
|
|
2478
|
|
|
|
|
|
|
# This is an awkward little kludge, |
2479
|
|
|
|
|
|
|
# but I haven't taken the time to figure out how the compiler should handle |
2480
|
|
|
|
|
|
|
# the general case of this situation. TODO: Probably do more than just |
2481
|
|
|
|
|
|
|
# attributes here; probably comment and PI. Perhaps also characters, but |
2482
|
|
|
|
|
|
|
# then the user gets no catenation. hmmm. |
2483
|
|
|
|
|
|
|
sub XFD::self_node::immed_code_template { |
2484
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2485
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
2486
|
|
|
|
|
|
|
|
2487
|
|
|
|
|
|
|
#warn $context->{PossiblesSetBy}->op_type, ": ", join ",", @{$context->{PossibleEventTypes}}; |
2488
|
|
|
|
|
|
|
|
2489
|
0
|
|
|
|
|
0
|
return "\$ctx" |
2490
|
|
|
|
|
|
|
if $context->{PossibleEventTypes} |
2491
|
0
|
0
|
0
|
|
|
0
|
&& @{$context->{PossibleEventTypes}} == 1 |
|
|
|
0
|
|
|
|
|
2492
|
|
|
|
|
|
|
&& $context->{PossibleEventTypes}->[0] eq "attribute"; |
2493
|
|
|
|
|
|
|
|
2494
|
0
|
|
|
|
|
0
|
return $self->XFD::PathTest::immed_code_template( @_ ); |
2495
|
|
|
|
|
|
|
} |
2496
|
|
|
|
|
|
|
|
2497
|
|
|
|
|
|
|
|
2498
|
0
|
|
|
0
|
|
0
|
sub XFD::self_node::incr_code_template { "" } |
2499
|
|
|
|
|
|
|
|
2500
|
|
|
|
|
|
|
########## |
2501
|
|
|
|
|
|
|
@XFD::node_name::ISA = qw( XFD::PathTest ); |
2502
|
|
|
|
|
|
|
|
2503
|
0
|
|
|
0
|
|
0
|
sub XFD::node_name::curry_tests { qw( start_element attribute ) } |
2504
|
|
|
|
|
|
|
|
2505
|
|
|
|
|
|
|
sub XFD::node_name::possible_event_type_map { { |
2506
|
5
|
|
|
5
|
|
22
|
'start_element' => [qw( start_element )], |
2507
|
|
|
|
|
|
|
'attribute' => [qw( attribute )], |
2508
|
|
|
|
|
|
|
} } |
2509
|
|
|
|
|
|
|
|
2510
|
5
|
|
|
5
|
|
16
|
sub XFD::node_name::useful_event_contexts { qw( start_element end_element attribute ) } |
2511
|
|
|
|
|
|
|
|
2512
|
|
|
|
|
|
|
sub XFD::node_name::condition { |
2513
|
5
|
|
|
5
|
|
6
|
my $self = shift; |
2514
|
5
|
|
|
|
|
8
|
my ( $ctx_expr ) = @_; |
2515
|
|
|
|
|
|
|
|
2516
|
5
|
|
|
|
|
17
|
return "$ctx_expr\->{Node}->{Name} eq '$self->[0]'"; |
2517
|
|
|
|
|
|
|
} |
2518
|
|
|
|
|
|
|
|
2519
|
|
|
|
|
|
|
sub XFD::node_name::incr_code_template { |
2520
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
2521
|
5
|
|
|
|
|
11
|
my $cond = $self->condition( "\$ctx" ); |
2522
|
|
|
|
|
|
|
|
2523
|
5
|
|
|
|
|
35
|
return <
|
2524
|
|
|
|
|
|
|
if ( $cond ) { |
2525
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: node name '$self->[0]' found" if is_tracing; |
2526
|
|
|
|
|
|
|
} |
2527
|
|
|
|
|
|
|
CODE_END |
2528
|
|
|
|
|
|
|
} |
2529
|
|
|
|
|
|
|
|
2530
|
|
|
|
|
|
|
sub XFD::node_name::immed_code_template { |
2531
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2532
|
0
|
|
|
|
|
0
|
my $cond = $self->condition( "\$_" ); |
2533
|
|
|
|
|
|
|
|
2534
|
0
|
|
|
|
|
0
|
return <
|
2535
|
|
|
|
|
|
|
grep ## node name '$self->[0]' |
2536
|
|
|
|
|
|
|
$cond, |
2537
|
|
|
|
|
|
|
|
2538
|
|
|
|
|
|
|
CODE_END |
2539
|
|
|
|
|
|
|
} |
2540
|
|
|
|
|
|
|
|
2541
|
|
|
|
|
|
|
########## |
2542
|
|
|
|
|
|
|
@XFD::node_local_name::ISA = qw( XFD::node_name ); |
2543
|
|
|
|
|
|
|
|
2544
|
|
|
|
|
|
|
sub XFD::node_local_name::condition { |
2545
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2546
|
0
|
|
|
|
|
0
|
my ( $ctx_expr ) = @_; |
2547
|
|
|
|
|
|
|
|
2548
|
0
|
|
|
|
|
0
|
return "$ctx_expr\->{Node}->{LocalName} eq '$self->[0]'"; |
2549
|
|
|
|
|
|
|
} |
2550
|
|
|
|
|
|
|
|
2551
|
|
|
|
|
|
|
sub XFD::node_local_name::incr_code_template { |
2552
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2553
|
0
|
|
|
|
|
0
|
my $cond = $self->condition( "\$ctx" ); |
2554
|
|
|
|
|
|
|
|
2555
|
0
|
|
|
|
|
0
|
return <
|
2556
|
|
|
|
|
|
|
if ( $cond ) { |
2557
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: node local_name '$self->[0]' found" if is_tracing; |
2558
|
|
|
|
|
|
|
} |
2559
|
|
|
|
|
|
|
CODE_END |
2560
|
|
|
|
|
|
|
} |
2561
|
|
|
|
|
|
|
|
2562
|
|
|
|
|
|
|
########## |
2563
|
|
|
|
|
|
|
@XFD::namespace_test::ISA = qw( XFD::PathTest ); |
2564
|
|
|
|
|
|
|
|
2565
|
|
|
|
|
|
|
sub XFD::namespace_test::new { |
2566
|
0
|
|
|
0
|
|
0
|
my $self = shift->XFD::PathTest::new( @_ ); |
2567
|
|
|
|
|
|
|
|
2568
|
0
|
0
|
|
|
|
0
|
die "Namespaces option required to support '$self->[0]' match\n" |
2569
|
|
|
|
|
|
|
unless defined $dispatcher->{Namespaces}; |
2570
|
|
|
|
|
|
|
|
2571
|
|
|
|
|
|
|
# ( $self->[0] ) = $self->_parse_ns_uri_and_localname( $self->[0] ); |
2572
|
|
|
|
|
|
|
|
2573
|
0
|
|
|
|
|
0
|
return $self; |
2574
|
|
|
|
|
|
|
} |
2575
|
|
|
|
|
|
|
|
2576
|
0
|
|
|
0
|
|
0
|
sub XFD::namespace_test::curry_tests { qw( start_element attribute ) } |
2577
|
|
|
|
|
|
|
|
2578
|
|
|
|
|
|
|
sub XFD::namespace_test::possible_event_type_map { { |
2579
|
0
|
|
|
0
|
|
0
|
'start_element' => [qw( start_element )], |
2580
|
|
|
|
|
|
|
'attribute' => [qw( attribute )], |
2581
|
|
|
|
|
|
|
} } |
2582
|
|
|
|
|
|
|
|
2583
|
0
|
|
|
0
|
|
0
|
sub XFD::namespace_test::useful_event_contexts { qw( start_element end_element attribute ) } |
2584
|
|
|
|
|
|
|
|
2585
|
|
|
|
|
|
|
sub XFD::namespace_test::condition { |
2586
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2587
|
0
|
|
|
|
|
0
|
my ( $ctx_expr ) = @_; |
2588
|
|
|
|
|
|
|
|
2589
|
|
|
|
|
|
|
return |
2590
|
0
|
|
|
|
|
0
|
"$ctx_expr\->{Node}->{NamespaceURI} eq '$self->[0]'"; |
2591
|
|
|
|
|
|
|
} |
2592
|
|
|
|
|
|
|
|
2593
|
|
|
|
|
|
|
sub XFD::namespace_test::incr_code_template { |
2594
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2595
|
0
|
|
|
|
|
0
|
my $cond = $self->condition( "\$ctx" ); |
2596
|
|
|
|
|
|
|
|
2597
|
0
|
|
|
|
|
0
|
return <
|
2598
|
|
|
|
|
|
|
if ( $cond ) { |
2599
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: node namespace '$self->[0]' found" if is_tracing; |
2600
|
|
|
|
|
|
|
} |
2601
|
|
|
|
|
|
|
CODE_END |
2602
|
|
|
|
|
|
|
} |
2603
|
|
|
|
|
|
|
|
2604
|
|
|
|
|
|
|
sub XFD::namespace_test::immed_code_template { |
2605
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2606
|
0
|
|
|
|
|
0
|
my $cond = $self->condition( "\$_" ); |
2607
|
|
|
|
|
|
|
|
2608
|
0
|
|
|
|
|
0
|
return <
|
2609
|
|
|
|
|
|
|
grep ## node namespace '$self->[0]' |
2610
|
|
|
|
|
|
|
$cond, |
2611
|
|
|
|
|
|
|
|
2612
|
|
|
|
|
|
|
CODE_END |
2613
|
|
|
|
|
|
|
} |
2614
|
|
|
|
|
|
|
|
2615
|
|
|
|
|
|
|
########## |
2616
|
|
|
|
|
|
|
## TODO: implement this as primary nodetype for this axis and not |
2617
|
|
|
|
|
|
|
## a name test. |
2618
|
|
|
|
|
|
|
@XFD::any_node_name::ISA = qw( XFD::PathTest ); |
2619
|
|
|
|
|
|
|
|
2620
|
0
|
|
|
0
|
|
0
|
sub XFD::any_node_name::curry_tests { qw( start_element attribute ) } |
2621
|
|
|
|
|
|
|
|
2622
|
0
|
|
|
0
|
|
0
|
sub XFD::any_node_name::incr_code_template { <
|
2623
|
|
|
|
|
|
|
## any node name |
2624
|
|
|
|
|
|
|
if ( \$ctx->{EventType} eq "start_element" || \$ctx->{EventType} eq "attribute" ) { |
2625
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: node name '*' found" if is_tracing; |
2626
|
|
|
|
|
|
|
|
2627
|
|
|
|
|
|
|
} # any node name |
2628
|
|
|
|
|
|
|
CODE_END |
2629
|
|
|
|
|
|
|
|
2630
|
|
|
|
|
|
|
########## |
2631
|
|
|
|
|
|
|
@XFD::union::ISA = qw( XFD::PathTest ); |
2632
|
|
|
|
|
|
|
|
2633
|
|
|
|
|
|
|
sub XFD::union::new { |
2634
|
7
|
|
|
7
|
|
14
|
my $class = shift; |
2635
|
|
|
|
|
|
|
## No _next, so don't use base class' new(). |
2636
|
7
|
|
|
|
|
64
|
return bless [@_], $class; |
2637
|
|
|
|
|
|
|
} |
2638
|
|
|
|
|
|
|
|
2639
|
0
|
|
|
0
|
|
0
|
sub XFD::union::optim_signature { ref shift } |
2640
|
|
|
|
|
|
|
|
2641
|
5
|
|
|
5
|
|
8
|
sub XFD::union::add { push @{shift()}, @_ } |
|
5
|
|
|
|
|
26
|
|
2642
|
|
|
|
|
|
|
|
2643
|
0
|
|
|
0
|
|
0
|
sub XFD::union::set_next { $_->set_next( @_ ) for @{shift()} } |
|
0
|
|
|
|
|
0
|
|
2644
|
|
|
|
|
|
|
|
2645
|
|
|
|
|
|
|
## get_kids/set_kids is used by external code only, like the optimizer |
2646
|
8
|
50
|
|
8
|
|
12
|
sub XFD::union::get_kids { map $_->isa( "XFD::union" ) ? $_->get_kids : $_, @{shift()} } |
|
8
|
|
|
|
|
72
|
|
2647
|
4
|
|
|
4
|
|
5
|
sub XFD::union::set_kids { my $self = shift; @$self = @_ } |
|
4
|
|
|
|
|
14
|
|
2648
|
|
|
|
|
|
|
|
2649
|
|
|
|
|
|
|
sub XFD::union::curry_tests { |
2650
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2651
|
|
|
|
|
|
|
|
2652
|
0
|
|
|
|
|
0
|
my %tests; |
2653
|
|
|
|
|
|
|
|
2654
|
0
|
|
|
|
|
0
|
for ( @$self ) { |
2655
|
0
|
|
|
|
|
0
|
for ( $_->curry_tests ) { |
2656
|
0
|
|
|
|
|
0
|
$tests{$_} = undef; |
2657
|
|
|
|
|
|
|
} |
2658
|
|
|
|
|
|
|
} |
2659
|
|
|
|
|
|
|
|
2660
|
0
|
|
|
|
|
0
|
return keys %tests; |
2661
|
|
|
|
|
|
|
} |
2662
|
|
|
|
|
|
|
|
2663
|
|
|
|
|
|
|
|
2664
|
|
|
|
|
|
|
sub XFD::union::fixup { |
2665
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
2666
|
|
|
|
|
|
|
|
2667
|
|
|
|
|
|
|
## Test this here because the optimizer *does* put unions in front |
2668
|
|
|
|
|
|
|
## of things the user should not be able to do. |
2669
|
|
|
|
|
|
|
|
2670
|
2
|
|
|
|
|
7
|
for ( @$self ) { |
2671
|
5
|
50
|
|
|
|
66
|
die |
2672
|
|
|
|
|
|
|
"XPath's union operator ('|') doesn't work on a ", ref $_, ", perhaps 'or' is needed.\n" |
2673
|
|
|
|
|
|
|
unless $_->isa( "XFD::PathTest" ); |
2674
|
|
|
|
|
|
|
} |
2675
|
|
|
|
|
|
|
|
2676
|
2
|
|
|
|
|
18
|
$self->XFD::PathTest::fixup( @_ ); |
2677
|
|
|
|
|
|
|
} |
2678
|
|
|
|
|
|
|
|
2679
|
|
|
|
|
|
|
|
2680
|
|
|
|
|
|
|
sub XFD::union::as_incr_code { |
2681
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
2682
|
|
|
|
|
|
|
|
2683
|
4
|
100
|
|
|
|
17
|
return "" if @$self == 0; |
2684
|
2
|
50
|
|
|
|
7
|
return $self->[0]->as_incr_code( @_ ) if @$self == 1; |
2685
|
|
|
|
|
|
|
|
2686
|
2
|
|
|
|
|
16
|
return join "", |
2687
|
|
|
|
|
|
|
map( ( "# union\n", $_->as_incr_code( @_ ) ), @$self ), |
2688
|
|
|
|
|
|
|
"# end union\n" ; |
2689
|
|
|
|
|
|
|
} |
2690
|
|
|
|
|
|
|
|
2691
|
|
|
|
|
|
|
########## |
2692
|
|
|
|
|
|
|
## |
2693
|
|
|
|
|
|
|
## An XFD::Rule is a special "noop" op that allows compilation |
2694
|
|
|
|
|
|
|
## exceptions to be labelled with a rule's pattern. |
2695
|
|
|
|
|
|
|
## |
2696
|
|
|
|
|
|
|
@XFD::Rule::ISA = qw( XFD::PathTest ); |
2697
|
|
|
|
|
|
|
|
2698
|
|
|
|
|
|
|
sub XFD::Rule::fixup { |
2699
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
2700
|
|
|
|
|
|
|
|
2701
|
|
|
|
|
|
|
eval { |
2702
|
5
|
|
|
|
|
21
|
$self->XFD::PathTest::fixup( @_ ); |
2703
|
5
|
|
|
|
|
21
|
1; |
2704
|
5
|
50
|
|
|
|
9
|
} or do { |
2705
|
0
|
|
|
|
|
0
|
$@ =~ s/\n/ in expression $self->[0]\n/; |
2706
|
0
|
|
|
|
|
0
|
die $@; |
2707
|
|
|
|
|
|
|
} |
2708
|
|
|
|
|
|
|
} |
2709
|
|
|
|
|
|
|
|
2710
|
|
|
|
|
|
|
|
2711
|
|
|
|
|
|
|
sub XFD::Rule::as_incr_code { |
2712
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2713
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
2714
|
|
|
|
|
|
|
|
2715
|
0
|
|
|
|
|
0
|
$context = { %$context }; |
2716
|
|
|
|
|
|
|
|
2717
|
0
|
|
|
|
|
0
|
my $r = eval { |
2718
|
0
|
|
|
|
|
0
|
$self->[_next]->as_incr_code( $context ); |
2719
|
|
|
|
|
|
|
}; |
2720
|
0
|
0
|
|
|
|
0
|
unless ( defined $r ) { |
2721
|
0
|
|
|
|
|
0
|
$@ =~ s/\n/ in expression $self->[0]\n/; |
2722
|
0
|
|
|
|
|
0
|
die $@; |
2723
|
|
|
|
|
|
|
} |
2724
|
0
|
|
|
|
|
0
|
return $r; |
2725
|
|
|
|
|
|
|
} |
2726
|
|
|
|
|
|
|
|
2727
|
|
|
|
|
|
|
########## |
2728
|
|
|
|
|
|
|
@XFD::predicate::ISA = qw( XFD::PathTest ); |
2729
|
|
|
|
|
|
|
|
2730
|
|
|
|
|
|
|
## new() might get a location path passed as a param, or find them in the |
2731
|
|
|
|
|
|
|
## predicates. The former happens when st. like [@foo] occurs, the latter |
2732
|
|
|
|
|
|
|
## when [@foo=2] occurs (since the "=" converted @foo to a predicate). |
2733
|
|
|
|
|
|
|
|
2734
|
|
|
|
|
|
|
sub XFD::predicate::new { |
2735
|
0
|
|
|
0
|
|
0
|
return shift->XFD::PathTest::new( XFD::Function::boolean->new( @_ ) ); |
2736
|
|
|
|
|
|
|
} |
2737
|
|
|
|
|
|
|
|
2738
|
|
|
|
|
|
|
## Disable folding of predicates for now. What we really need to do |
2739
|
|
|
|
|
|
|
## is cat up all the signatures of the code in the predicate in to the |
2740
|
|
|
|
|
|
|
## signature so only identical ones will be optimized. |
2741
|
|
|
|
|
|
|
## |
2742
|
|
|
|
|
|
|
## A better approace longer term might be to hoist the predicate |
2743
|
|
|
|
|
|
|
## precursors in fixup phase so they are normal ops and would get |
2744
|
|
|
|
|
|
|
## optimized normally. |
2745
|
0
|
|
|
0
|
|
0
|
sub XFD::predicate::optim_signature { int shift } |
2746
|
|
|
|
|
|
|
|
2747
|
|
|
|
|
|
|
sub _expr() { 0 } |
2748
|
|
|
|
|
|
|
|
2749
|
|
|
|
|
|
|
sub XFD::predicate::curry_tests { |
2750
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2751
|
|
|
|
|
|
|
|
2752
|
|
|
|
|
|
|
## If there's something after us, delegate. |
2753
|
0
|
0
|
|
|
|
0
|
return $self->[_next]->curry_tests |
2754
|
|
|
|
|
|
|
if defined $self->[_next]; |
2755
|
|
|
|
|
|
|
|
2756
|
|
|
|
|
|
|
## Otherwise, return every node test type. |
2757
|
0
|
|
|
|
|
0
|
@all_curry_tests; |
2758
|
|
|
|
|
|
|
} |
2759
|
|
|
|
|
|
|
|
2760
|
|
|
|
|
|
|
|
2761
|
|
|
|
|
|
|
sub XFD::predicate::as_incr_code { |
2762
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2763
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
2764
|
|
|
|
|
|
|
|
2765
|
0
|
|
|
|
|
0
|
return get_expr_code "predicate", $self->[_expr], undef, undef, $self->[_next], @_; |
2766
|
|
|
|
|
|
|
} |
2767
|
|
|
|
|
|
|
|
2768
|
|
|
|
|
|
|
############################################################################### |
2769
|
|
|
|
|
|
|
## |
2770
|
|
|
|
|
|
|
## Axes |
2771
|
|
|
|
|
|
|
## |
2772
|
|
|
|
|
|
|
|
2773
|
|
|
|
|
|
|
## |
2774
|
|
|
|
|
|
|
## The grammar calls axis(), which returns an object. |
2775
|
|
|
|
|
|
|
## |
2776
|
|
|
|
|
|
|
sub axis { |
2777
|
0
|
|
|
0
|
|
0
|
my $class = "XFD::Axis::$_[0]"; |
2778
|
0
|
|
|
|
|
0
|
$class =~ s/_//g; |
2779
|
0
|
|
|
|
|
0
|
$class =~ s/-/_/g; |
2780
|
0
|
0
|
|
|
|
0
|
die "'$_[0]' is not a valid EventPath axis\n" |
2781
|
|
|
|
|
|
|
unless $class->can( "new" ); |
2782
|
0
|
|
|
|
|
0
|
return $class->new; |
2783
|
|
|
|
|
|
|
} |
2784
|
|
|
|
|
|
|
|
2785
|
|
|
|
|
|
|
@XFD::Axis::ISA = qw( XFD::PathTest ); |
2786
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::op_type { shift->XFD::Op::op_type . "::" } |
2787
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::principal_event_type { "start_element" } |
2788
|
|
|
|
|
|
|
|
2789
|
|
|
|
|
|
|
## Axes have no parameters and are inherently foldable, so return the |
2790
|
|
|
|
|
|
|
## type of the axis. Axis ops that need to be curried for different |
2791
|
|
|
|
|
|
|
## event types can't be folded. |
2792
|
|
|
|
|
|
|
sub XFD::Axis::optim_signature { |
2793
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2794
|
0
|
|
|
|
|
0
|
join "", ref $self, "(", $self->[_next]->curry_tests, ":", $self->principal_event_type, ")"; |
2795
|
|
|
|
|
|
|
} |
2796
|
|
|
|
|
|
|
|
2797
|
|
|
|
|
|
|
|
2798
|
|
|
|
|
|
|
########## |
2799
|
|
|
|
|
|
|
@XFD::Axis::attribute::ISA = qw( XFD::Axis ); |
2800
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::attribute::curry_tests { ( "start_element" ) } |
2801
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::attribute::principal_event_type { "attribute" } |
2802
|
|
|
|
|
|
|
sub XFD::Axis::attribute::possible_event_type_map { |
2803
|
|
|
|
|
|
|
#warn "HI!"; |
2804
|
|
|
|
|
|
|
{ |
2805
|
0
|
|
|
0
|
|
0
|
start_element => [qw( attribute )], |
2806
|
|
|
|
|
|
|
} } |
2807
|
|
|
|
|
|
|
|
2808
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::attribute::useful_event_contexts { qw( start_element end_element ) } |
2809
|
|
|
|
|
|
|
|
2810
|
|
|
|
|
|
|
#X This is an aborted attempt to make things following an attribute:: |
2811
|
|
|
|
|
|
|
#X run immediately. |
2812
|
|
|
|
|
|
|
#Xsub XFD::Axis::attribute::as_incr_code { ## not ..._template()! |
2813
|
|
|
|
|
|
|
sub XFD::Axis::attribute::incr_code_template { |
2814
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2815
|
|
|
|
|
|
|
#X my ( $context ) = @_; |
2816
|
|
|
|
|
|
|
#X |
2817
|
|
|
|
|
|
|
#X $self->check_context( $context ); |
2818
|
|
|
|
|
|
|
|
2819
|
|
|
|
|
|
|
## node type tests only apply to certain event types, so |
2820
|
|
|
|
|
|
|
## we only curry to those events. This makes EventType |
2821
|
|
|
|
|
|
|
## tests run-time noops, and simplifies others (node_name) |
2822
|
|
|
|
|
|
|
## because they do not need to test $ctx->{EventType}. |
2823
|
0
|
|
|
|
|
0
|
my @curry_tests = grep $_ eq "attribute", $self->[_next]->curry_tests; |
2824
|
|
|
|
|
|
|
|
2825
|
0
|
0
|
|
|
|
0
|
die $self->op_type, " followed by ", $self->[_next]->op_type, |
2826
|
|
|
|
|
|
|
" can never match\n" unless @curry_tests; |
2827
|
|
|
|
|
|
|
|
2828
|
|
|
|
|
|
|
#X local $context->{Axis} = $self->op_type; |
2829
|
|
|
|
|
|
|
#X local $context->{PrincipalEventType} = $self->principal_event_type; |
2830
|
|
|
|
|
|
|
#X local $context->{PossibleEventTypes} = [ $self->possible_event_types( @_ ) ]; |
2831
|
|
|
|
|
|
|
#X |
2832
|
|
|
|
|
|
|
#X my $next_code = $self->[_next]->as_immed_code( $context ); |
2833
|
|
|
|
|
|
|
#X |
2834
|
|
|
|
|
|
|
#X return $self->insert_next_in_to_template( <
|
2835
|
|
|
|
|
|
|
|
2836
|
0
|
0
|
|
|
|
0
|
return <
|
2837
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for attribute::" if is_tracing; |
2838
|
|
|
|
|
|
|
push \@{\$ctx->{ChildCtx}->{$curry_tests[0]}}, [ ## attribute:: |
2839
|
|
|
|
|
|
|
sub { |
2840
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
2841
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: in attribute \$ctx->{Node}->{Name}" if is_tracing; |
2842
|
|
|
|
|
|
|
|
2843
|
|
|
|
|
|
|
}, |
2844
|
|
|
|
|
|
|
\$postponement, |
2845
|
|
|
|
|
|
|
]; # attribute:: |
2846
|
|
|
|
|
|
|
CODE_END |
2847
|
|
|
|
|
|
|
|
2848
|
0
|
|
|
|
|
0
|
my $curry_code = join "\n", |
2849
|
|
|
|
|
|
|
map " push \@{\$ctx->{ChildCtx}->{$_}}, \$queue_record;", |
2850
|
|
|
|
|
|
|
@curry_tests; |
2851
|
|
|
|
|
|
|
|
2852
|
0
|
|
|
|
|
0
|
return <
|
2853
|
|
|
|
|
|
|
## attribute:: |
2854
|
|
|
|
|
|
|
{ |
2855
|
|
|
|
|
|
|
## Curry the rest of the location path tests |
2856
|
|
|
|
|
|
|
## to be handled in the appropriate attribute events. |
2857
|
|
|
|
|
|
|
my \$queue_record = [ |
2858
|
|
|
|
|
|
|
sub { |
2859
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
2860
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: in attribute" if is_tracing; |
2861
|
|
|
|
|
|
|
|
2862
|
|
|
|
|
|
|
}, |
2863
|
|
|
|
|
|
|
\$postponement, |
2864
|
|
|
|
|
|
|
]; |
2865
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for attribute::" if is_tracing; |
2866
|
|
|
|
|
|
|
$curry_code |
2867
|
|
|
|
|
|
|
} # attribute:: |
2868
|
|
|
|
|
|
|
CODE_END |
2869
|
|
|
|
|
|
|
} |
2870
|
|
|
|
|
|
|
|
2871
|
|
|
|
|
|
|
|
2872
|
|
|
|
|
|
|
sub XFD::Axis::attribute::immed_code_template { |
2873
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2874
|
|
|
|
|
|
|
## Do a little belated optimization here |
2875
|
|
|
|
|
|
|
## TODO: Generalize this to handle intervening XFD::unions and |
2876
|
|
|
|
|
|
|
## to work for node_name tests. |
2877
|
0
|
|
|
|
|
0
|
my $kid = $self->[_next]; |
2878
|
0
|
0
|
0
|
|
|
0
|
if ( $kid && $kid->isa( "XFD::namespace_test" ) ) { |
2879
|
0
|
|
|
|
|
0
|
my $gkid = $kid->[_next]; |
2880
|
0
|
0
|
0
|
|
|
0
|
if ( $gkid && $gkid->isa( "XFD::node_local_name" ) ) { |
2881
|
|
|
|
|
|
|
## Its an attribute::foo:bar expression, which can |
2882
|
|
|
|
|
|
|
## be optimized very nicely, thank you |
2883
|
0
|
|
|
|
|
0
|
my $ns_uri = $kid->[0]; |
2884
|
0
|
|
|
|
|
0
|
my $local_name = $gkid->[0]; |
2885
|
0
|
|
|
|
|
0
|
return <
|
2886
|
|
|
|
|
|
|
( ## attribute::prefix:name |
2887
|
|
|
|
|
|
|
exists \$ctx->{Node}->{Attributes}->{'{$ns_uri}$local_name'} |
2888
|
|
|
|
|
|
|
? { ## A context for the found attribute |
2889
|
|
|
|
|
|
|
EventType => 'attribute', |
2890
|
|
|
|
|
|
|
Node => \$ctx->{Node}->{Attributes}->{'{$ns_uri}$local_name'}, |
2891
|
|
|
|
|
|
|
Parent => \$ctx, |
2892
|
|
|
|
|
|
|
} |
2893
|
|
|
|
|
|
|
: () |
2894
|
|
|
|
|
|
|
) |
2895
|
|
|
|
|
|
|
CODE_END |
2896
|
|
|
|
|
|
|
} |
2897
|
|
|
|
|
|
|
} |
2898
|
|
|
|
|
|
|
|
2899
|
0
|
0
|
|
|
|
0
|
my $sort_code = $dispatcher->{SortAttributes} ? <<'CODE_END' : ""; |
2900
|
|
|
|
|
|
|
} sort { |
2901
|
|
|
|
|
|
|
## Put attributes in a reproducable order, mostly for testing |
2902
|
|
|
|
|
|
|
## purposes. |
2903
|
|
|
|
|
|
|
## TODO: Look for Node->{AttributeOrder} here |
2904
|
|
|
|
|
|
|
( \$a->{Name} || "" ) cmp ( \$b->{Name} || "" ) |
2905
|
|
|
|
|
|
|
CODE_END |
2906
|
|
|
|
|
|
|
|
2907
|
0
|
|
|
|
|
0
|
return <
|
2908
|
|
|
|
|
|
|
( ## attribute:: |
2909
|
|
|
|
|
|
|
|
2910
|
|
|
|
|
|
|
map { |
2911
|
|
|
|
|
|
|
my \$ctx = { |
2912
|
|
|
|
|
|
|
EventType => 'attribute', |
2913
|
|
|
|
|
|
|
Node => \$_, |
2914
|
|
|
|
|
|
|
Parent => \$ctx, |
2915
|
|
|
|
|
|
|
}; |
2916
|
|
|
|
|
|
|
emit_trace_SAX_message "built attribute event ", _ev \$ctx if is_tracing; |
2917
|
|
|
|
|
|
|
\$ctx; |
2918
|
|
|
|
|
|
|
$sort_code |
2919
|
|
|
|
|
|
|
} values %{\$ctx->{Node}->{Attributes}} |
2920
|
|
|
|
|
|
|
) # attribute:: |
2921
|
|
|
|
|
|
|
CODE_END |
2922
|
|
|
|
|
|
|
} |
2923
|
|
|
|
|
|
|
|
2924
|
|
|
|
|
|
|
|
2925
|
|
|
|
|
|
|
########## |
2926
|
|
|
|
|
|
|
@XFD::Axis::child::ISA = qw( XFD::Axis ); |
2927
|
|
|
|
|
|
|
sub XFD::Axis::child::possible_event_type_map { { |
2928
|
0
|
|
|
0
|
|
0
|
start_document => [qw( start_prefix_mapping start_element comment processing_instruction )], |
2929
|
|
|
|
|
|
|
start_element => [qw( start_prefix_mapping start_element comment processing_instruction characters )], |
2930
|
|
|
|
|
|
|
} } |
2931
|
|
|
|
|
|
|
|
2932
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::child::useful_event_contexts { qw( start_document start_element ) } |
2933
|
|
|
|
|
|
|
|
2934
|
|
|
|
|
|
|
sub XFD::Axis::child::incr_code_template { |
2935
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
2936
|
|
|
|
|
|
|
|
2937
|
|
|
|
|
|
|
## node type tests only apply to certain event types, so |
2938
|
|
|
|
|
|
|
## we only curry to those events. This makes EventType |
2939
|
|
|
|
|
|
|
## tests run-time noops, and simplifies others (node_name) |
2940
|
|
|
|
|
|
|
## because they do not need to test $ctx->{EventType}. |
2941
|
0
|
|
|
|
|
0
|
my @curry_tests = |
2942
|
|
|
|
|
|
|
grep exists $child_curry_tests{$_}, $self->[_next]->curry_tests; |
2943
|
|
|
|
|
|
|
|
2944
|
0
|
0
|
|
|
|
0
|
die $self->op_type, " followed by ", $self->[_next]->op_type, |
2945
|
|
|
|
|
|
|
" can never match\n" unless @curry_tests; |
2946
|
|
|
|
|
|
|
|
2947
|
0
|
0
|
|
|
|
0
|
return <
|
2948
|
|
|
|
|
|
|
## child:: |
2949
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for child::" if is_tracing; |
2950
|
|
|
|
|
|
|
push \@{\$ctx->{ChildCtx}->{$curry_tests[0]}}, [ ## child:: |
2951
|
|
|
|
|
|
|
sub { |
2952
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
2953
|
|
|
|
|
|
|
|
2954
|
|
|
|
|
|
|
}, |
2955
|
|
|
|
|
|
|
\$postponement, |
2956
|
|
|
|
|
|
|
]; # end child:: |
2957
|
|
|
|
|
|
|
CODE_END |
2958
|
|
|
|
|
|
|
|
2959
|
0
|
|
|
|
|
0
|
my $curry_code = join "\n", |
2960
|
|
|
|
|
|
|
map " push \@{\$ctx->{ChildCtx}->{$_}}, \$queue_record;", |
2961
|
|
|
|
|
|
|
@curry_tests; |
2962
|
|
|
|
|
|
|
|
2963
|
0
|
|
|
|
|
0
|
return <
|
2964
|
|
|
|
|
|
|
{ ## child:: |
2965
|
|
|
|
|
|
|
my \$queue_record = [ |
2966
|
|
|
|
|
|
|
sub { |
2967
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
2968
|
|
|
|
|
|
|
|
2969
|
|
|
|
|
|
|
}, |
2970
|
|
|
|
|
|
|
\$postponement, |
2971
|
|
|
|
|
|
|
]; |
2972
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for child::" if is_tracing; |
2973
|
|
|
|
|
|
|
$curry_code |
2974
|
|
|
|
|
|
|
} # child:: |
2975
|
|
|
|
|
|
|
CODE_END |
2976
|
|
|
|
|
|
|
} |
2977
|
|
|
|
|
|
|
|
2978
|
|
|
|
|
|
|
|
2979
|
|
|
|
|
|
|
########## |
2980
|
|
|
|
|
|
|
@XFD::Axis::descendant_or_self::ISA = qw( XFD::Axis ); |
2981
|
|
|
|
|
|
|
|
2982
|
|
|
|
|
|
|
sub XFD::Axis::descendant_or_self::possible_event_type_map { { |
2983
|
|
|
|
|
|
|
## This is odd: we tell the caller that we could call our kids for |
2984
|
|
|
|
|
|
|
## any of these when called on a start_document. And, literally, |
2985
|
|
|
|
|
|
|
## thats' true. But I'd like to have it set up so that |
2986
|
|
|
|
|
|
|
## this is unwound after a start_document so it only queues for |
2987
|
|
|
|
|
|
|
## start_element *there*, but then queues for all of them other |
2988
|
|
|
|
|
|
|
## places. That's just for neatness' sake; there would be minimal |
2989
|
|
|
|
|
|
|
## performance improvement. And it would take extra generated code, |
2990
|
|
|
|
|
|
|
## I think. |
2991
|
|
|
|
|
|
|
## these in start_document. |
2992
|
0
|
|
|
0
|
|
0
|
'start_document' => [qw( start_prefix_mapping start_element comment processing_instruction characters )], |
2993
|
|
|
|
|
|
|
'start_element' => [qw( start_prefix_mapping start_element comment processing_instruction characters )], |
2994
|
|
|
|
|
|
|
}; } |
2995
|
|
|
|
|
|
|
|
2996
|
|
|
|
|
|
|
## useful in any event context, even though self:: alone would be |
2997
|
|
|
|
|
|
|
## more appropriate in most. |
2998
|
|
|
|
|
|
|
|
2999
|
|
|
|
|
|
|
sub XFD::Axis::descendant_or_self::as_incr_code { |
3000
|
0
|
|
|
0
|
|
0
|
return shift->XFD::Axis::as_incr_code( @_ ); |
3001
|
|
|
|
|
|
|
} |
3002
|
|
|
|
|
|
|
|
3003
|
|
|
|
|
|
|
sub XFD::Axis::descendant_or_self::incr_code_template { |
3004
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3005
|
|
|
|
|
|
|
|
3006
|
|
|
|
|
|
|
## node type tests only apply to certain event types, so |
3007
|
|
|
|
|
|
|
## we only curry to those events. This makes EventType |
3008
|
|
|
|
|
|
|
## tests run-time noops, and simplifies others (node_name) |
3009
|
|
|
|
|
|
|
## because they do not need to test $ctx->{EventType}. |
3010
|
|
|
|
|
|
|
## We always curry to start_element to propogate the tests down |
3011
|
|
|
|
|
|
|
## the chain. Unfortunately, this |
3012
|
|
|
|
|
|
|
|
3013
|
0
|
|
|
|
|
0
|
my %seen; |
3014
|
0
|
|
0
|
|
|
0
|
my @curry_tests = |
3015
|
|
|
|
|
|
|
grep ! $seen{$_}++ && exists $child_curry_tests{$_}, |
3016
|
|
|
|
|
|
|
$self->[_next]->curry_tests, "start_element"; |
3017
|
|
|
|
|
|
|
|
3018
|
0
|
0
|
|
|
|
0
|
die $self->op_type, " followed by ", $self->[_next]->op_type, |
3019
|
|
|
|
|
|
|
" can never match\n" unless @curry_tests; |
3020
|
|
|
|
|
|
|
|
3021
|
0
|
0
|
|
|
|
0
|
return <
|
3022
|
|
|
|
|
|
|
{ ## descendant-or-self:: |
3023
|
|
|
|
|
|
|
my \$sub = sub { |
3024
|
|
|
|
|
|
|
my ( \$sub, \$postponement ) = \@_; |
3025
|
|
|
|
|
|
|
|
3026
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for descendant-or-self::" if is_tracing; |
3027
|
|
|
|
|
|
|
push \@{\$ctx->{ChildCtx}->{$curry_tests[0]}}, [ \$sub, \$sub, \$postponement ]; |
3028
|
|
|
|
|
|
|
## ...run it on this node (aka "self") |
3029
|
|
|
|
|
|
|
|
3030
|
|
|
|
|
|
|
}; |
3031
|
|
|
|
|
|
|
\$sub->( \$sub, \$postponement ); |
3032
|
|
|
|
|
|
|
} # descendant-or-self:: |
3033
|
|
|
|
|
|
|
CODE_END |
3034
|
|
|
|
|
|
|
|
3035
|
0
|
|
|
|
|
0
|
my $curry_code = join "\n", |
3036
|
|
|
|
|
|
|
map " push \@{\$ctx->{ChildCtx}->{$_}}, \$queue_record;", |
3037
|
|
|
|
|
|
|
@curry_tests; |
3038
|
|
|
|
|
|
|
|
3039
|
0
|
|
|
|
|
0
|
return <
|
3040
|
|
|
|
|
|
|
{ ## descendant-or-self:: |
3041
|
|
|
|
|
|
|
my \$sub = sub { |
3042
|
|
|
|
|
|
|
my ( \$sub, \$postponement ) = \@_; |
3043
|
|
|
|
|
|
|
|
3044
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for descendant-or-self::" if is_tracing; |
3045
|
|
|
|
|
|
|
my \$queue_record = [ \$sub, \$sub, \$postponement ]; |
3046
|
|
|
|
|
|
|
$curry_code |
3047
|
|
|
|
|
|
|
## ...run it on this node (aka "self") |
3048
|
|
|
|
|
|
|
|
3049
|
|
|
|
|
|
|
}; |
3050
|
|
|
|
|
|
|
\$sub->( \$sub, \$postponement ); |
3051
|
|
|
|
|
|
|
} # descendant-or-self:: |
3052
|
|
|
|
|
|
|
CODE_END |
3053
|
|
|
|
|
|
|
} |
3054
|
|
|
|
|
|
|
|
3055
|
|
|
|
|
|
|
|
3056
|
|
|
|
|
|
|
########## |
3057
|
|
|
|
|
|
|
@XFD::Axis::end::ISA = qw( XFD::Axis::end_element ); |
3058
|
|
|
|
|
|
|
# @XFD::Axis::end::ISA = qw( XFD::Axis ); |
3059
|
|
|
|
|
|
|
#sub XFD::Axis::end::principal_event_type { "start_element" } |
3060
|
|
|
|
|
|
|
#sub XFD::Axis::end::possible_event_type_map { { |
3061
|
|
|
|
|
|
|
# start_document => [qw( end_document )], |
3062
|
|
|
|
|
|
|
# start_element => [qw( end_element )], |
3063
|
|
|
|
|
|
|
#} } |
3064
|
|
|
|
|
|
|
#sub XFD::Axis::end::useful_event_contexts { qw( start_document start_element ) } |
3065
|
|
|
|
|
|
|
# |
3066
|
|
|
|
|
|
|
#sub XFD::Axis::end::as_incr_code { ## not ..._template()! |
3067
|
|
|
|
|
|
|
# my $self = shift; |
3068
|
|
|
|
|
|
|
# my ( $context ) = @_; |
3069
|
|
|
|
|
|
|
# |
3070
|
|
|
|
|
|
|
# $self->check_context( $context ); |
3071
|
|
|
|
|
|
|
# |
3072
|
|
|
|
|
|
|
# ## This is the lengthy one, as it needs to curry itself |
3073
|
|
|
|
|
|
|
# ## until the end element rolls around, while playing |
3074
|
|
|
|
|
|
|
# ## nicely with postponements. |
3075
|
|
|
|
|
|
|
# |
3076
|
|
|
|
|
|
|
# ## TODO: check how this interacts with nodeset-returning |
3077
|
|
|
|
|
|
|
# ## paths. |
3078
|
|
|
|
|
|
|
# |
3079
|
|
|
|
|
|
|
# local $context->{Axis} = $self->op_type; |
3080
|
|
|
|
|
|
|
# |
3081
|
|
|
|
|
|
|
# local $context->{PrincipalEventType} = $self->principal_event_type; |
3082
|
|
|
|
|
|
|
# local $context->{PossibleEventTypes} = [ $self->possible_event_types( @_ ) ]; |
3083
|
|
|
|
|
|
|
# local $context->{PossiblesSetBy} = $self; |
3084
|
|
|
|
|
|
|
# |
3085
|
|
|
|
|
|
|
# if ( ! defined $context->{precursorize_action} ) { |
3086
|
|
|
|
|
|
|
# ## There are no predicates to leftwards |
3087
|
|
|
|
|
|
|
# local $context->{delay_to_end} = 1; |
3088
|
|
|
|
|
|
|
# |
3089
|
|
|
|
|
|
|
# ## This is more like self:: than child::, no need to |
3090
|
|
|
|
|
|
|
# ## wrap the next set of tests. |
3091
|
|
|
|
|
|
|
# return $self->[_next]->as_incr_code( $context ); |
3092
|
|
|
|
|
|
|
# } |
3093
|
|
|
|
|
|
|
# else { |
3094
|
|
|
|
|
|
|
# ## There's a predicate to our left that's set the various |
3095
|
|
|
|
|
|
|
# ## precursor... and action_wrapper, so dance with it... |
3096
|
|
|
|
|
|
|
# |
3097
|
|
|
|
|
|
|
# ## the 'action' pushes the context on to the postponement's |
3098
|
|
|
|
|
|
|
# ## list of contexts. We want that to occur in the end_document. |
3099
|
|
|
|
|
|
|
# my $action_code = <
|
3100
|
|
|
|
|
|
|
#push \@{\$ctx->{EndSubs}}, [ |
3101
|
|
|
|
|
|
|
# sub { |
3102
|
|
|
|
|
|
|
# my ( \$ctx ) = \@_; |
3103
|
|
|
|
|
|
|
# emit_trace_SAX_message "EventPath: running end::" if is_tracing; |
3104
|
|
|
|
|
|
|
# |
3105
|
|
|
|
|
|
|
# }, |
3106
|
|
|
|
|
|
|
# \$ctx |
3107
|
|
|
|
|
|
|
#]; |
3108
|
|
|
|
|
|
|
#CODE_END |
3109
|
|
|
|
|
|
|
# |
3110
|
|
|
|
|
|
|
# _replace_NEXT $action_code, $context->{precursorize_action}, ""; |
3111
|
|
|
|
|
|
|
# |
3112
|
|
|
|
|
|
|
# local $context->{precursorize_action} = $action_code; |
3113
|
|
|
|
|
|
|
# |
3114
|
|
|
|
|
|
|
# return $self->[_next]->as_incr_code( $context ); |
3115
|
|
|
|
|
|
|
# } |
3116
|
|
|
|
|
|
|
#} |
3117
|
|
|
|
|
|
|
# |
3118
|
|
|
|
|
|
|
# |
3119
|
|
|
|
|
|
|
########## |
3120
|
|
|
|
|
|
|
@XFD::Axis::end_document::ISA = qw( XFD::Axis ); |
3121
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::end_document::principal_event_type { "start_document" } |
3122
|
|
|
|
|
|
|
sub XFD::Axis::end_document::possible_event_type_map { { |
3123
|
0
|
|
|
0
|
|
0
|
start_document => [qw( end_document )], |
3124
|
|
|
|
|
|
|
} } |
3125
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::end_document::useful_event_contexts { qw( start_document ) } |
3126
|
|
|
|
|
|
|
|
3127
|
|
|
|
|
|
|
sub XFD::Axis::end_document::fixup { |
3128
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3129
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3130
|
|
|
|
|
|
|
|
3131
|
|
|
|
|
|
|
## There are no predicates to leftwards |
3132
|
0
|
|
|
|
|
0
|
local $context->{DelayToEnd} = 1; |
3133
|
0
|
|
|
|
|
0
|
$self->XFD::Axis::fixup( @_ ); |
3134
|
|
|
|
|
|
|
} |
3135
|
|
|
|
|
|
|
|
3136
|
|
|
|
|
|
|
|
3137
|
|
|
|
|
|
|
sub XFD::Axis::end_document::as_incr_code { ## not ..._template()! |
3138
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3139
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3140
|
|
|
|
|
|
|
|
3141
|
0
|
|
|
|
|
0
|
$self->check_context( $context ); |
3142
|
|
|
|
|
|
|
|
3143
|
|
|
|
|
|
|
## This is the lengthy one, as it needs to curry itself |
3144
|
|
|
|
|
|
|
## until the end element rolls around, while playing |
3145
|
|
|
|
|
|
|
## nicely with postponements. |
3146
|
|
|
|
|
|
|
|
3147
|
|
|
|
|
|
|
## TODO: check how this interacts with nodeset-returning |
3148
|
|
|
|
|
|
|
## paths. |
3149
|
|
|
|
|
|
|
|
3150
|
0
|
|
|
|
|
0
|
local $context->{Axis} = $self->op_type; |
3151
|
|
|
|
|
|
|
|
3152
|
0
|
|
|
|
|
0
|
local $context->{PrincipalEventType} = $self->principal_event_type; |
3153
|
0
|
|
|
|
|
0
|
local $context->{PossibleEventTypes} = [ $self->possible_event_types( @_ ) ]; |
3154
|
0
|
|
|
|
|
0
|
local $context->{PossiblesSetBy} = $self; |
3155
|
|
|
|
|
|
|
|
3156
|
0
|
0
|
|
|
|
0
|
if ( ! defined $context->{precursorize_action} ) { |
3157
|
|
|
|
|
|
|
## This is more like self:: than child::, no need to |
3158
|
|
|
|
|
|
|
## wrap the next set of tests. |
3159
|
0
|
|
|
|
|
0
|
return $self->[_next]->as_incr_code( $context ); |
3160
|
|
|
|
|
|
|
} |
3161
|
|
|
|
|
|
|
else { |
3162
|
|
|
|
|
|
|
## There's a predicate to our left that's set the various |
3163
|
|
|
|
|
|
|
## precursor... and action_wrapper, so dance with it... |
3164
|
|
|
|
|
|
|
|
3165
|
|
|
|
|
|
|
## The assumption made in the fixup phase is invalid; we |
3166
|
|
|
|
|
|
|
## now need to queue an EndSub instead of putting the |
3167
|
|
|
|
|
|
|
## action right in to PendingEndActions so that the |
3168
|
|
|
|
|
|
|
## postponement can be tested. |
3169
|
0
|
|
|
|
|
0
|
local $context->{IgnoreDelayToEnd} = 1; |
3170
|
|
|
|
|
|
|
|
3171
|
|
|
|
|
|
|
## the 'action' pushes the context on to the postponement's |
3172
|
|
|
|
|
|
|
## list of contexts. We want that to occur in the end_document. |
3173
|
0
|
|
|
|
|
0
|
my $action_code = <
|
3174
|
|
|
|
|
|
|
push \@{\$ctx->{EndSubs}}, [ |
3175
|
|
|
|
|
|
|
sub { |
3176
|
|
|
|
|
|
|
my ( \$ctx ) = \@_; |
3177
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: running end_document::" if is_tracing; |
3178
|
|
|
|
|
|
|
|
3179
|
|
|
|
|
|
|
}, |
3180
|
|
|
|
|
|
|
\$ctx |
3181
|
|
|
|
|
|
|
]; |
3182
|
|
|
|
|
|
|
CODE_END |
3183
|
|
|
|
|
|
|
|
3184
|
0
|
|
|
|
|
0
|
_replace_NEXT $action_code, $context->{precursorize_action}, ""; |
3185
|
|
|
|
|
|
|
|
3186
|
0
|
|
|
|
|
0
|
local $context->{precursorize_action} = $action_code; |
3187
|
|
|
|
|
|
|
|
3188
|
0
|
|
|
|
|
0
|
return $self->[_next]->as_incr_code( $context ); |
3189
|
|
|
|
|
|
|
} |
3190
|
|
|
|
|
|
|
} |
3191
|
|
|
|
|
|
|
|
3192
|
|
|
|
|
|
|
|
3193
|
|
|
|
|
|
|
########## |
3194
|
|
|
|
|
|
|
@XFD::Axis::end_element::ISA = qw( XFD::Axis ); |
3195
|
|
|
|
|
|
|
sub XFD::Axis::end_element::possible_event_type_map { { |
3196
|
0
|
|
|
0
|
|
0
|
start_element => [qw( end_element )], |
3197
|
|
|
|
|
|
|
} } |
3198
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::end_element::useful_event_contexts { qw( start_document start_element ) } |
3199
|
|
|
|
|
|
|
|
3200
|
|
|
|
|
|
|
sub XFD::Axis::end_element::fixup { |
3201
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3202
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3203
|
|
|
|
|
|
|
|
3204
|
|
|
|
|
|
|
## Tell the Action that it should delay itself to the end_... event |
3205
|
|
|
|
|
|
|
## by using PendingEndActions. This gets overridden in the compile |
3206
|
|
|
|
|
|
|
## phase by setting IgnoreDelayToEnd if need be. |
3207
|
|
|
|
|
|
|
## |
3208
|
|
|
|
|
|
|
## Doing this here facilitates optimizing end:: into child:: in |
3209
|
|
|
|
|
|
|
## certain cases. |
3210
|
0
|
|
|
|
|
0
|
local $context->{DelayToEnd} = 1; |
3211
|
0
|
|
|
|
|
0
|
$self->XFD::Axis::fixup( @_ ); |
3212
|
|
|
|
|
|
|
} |
3213
|
|
|
|
|
|
|
|
3214
|
|
|
|
|
|
|
|
3215
|
|
|
|
|
|
|
sub XFD::Axis::end_element::as_incr_code { ## not ..._template()! |
3216
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3217
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3218
|
|
|
|
|
|
|
|
3219
|
0
|
|
|
|
|
0
|
$self->check_context( $context ); |
3220
|
|
|
|
|
|
|
|
3221
|
|
|
|
|
|
|
## This is the lengthy one, as it needs to curry itself |
3222
|
|
|
|
|
|
|
## until the end element rolls around, while playing |
3223
|
|
|
|
|
|
|
## nicely with postponements. |
3224
|
|
|
|
|
|
|
|
3225
|
|
|
|
|
|
|
## end-element:: is a bit like child::, except it selects the |
3226
|
|
|
|
|
|
|
## child's end element. So, it queues up something for the |
3227
|
|
|
|
|
|
|
## child's start_element event (so, for instance, the node_name |
3228
|
|
|
|
|
|
|
## or attr tests or predicates, etc. run), which then queue |
3229
|
|
|
|
|
|
|
## up the action for the child's EndSubs. |
3230
|
|
|
|
|
|
|
|
3231
|
|
|
|
|
|
|
## TODO: check how this interacts with nodeset-returning |
3232
|
|
|
|
|
|
|
## paths. |
3233
|
|
|
|
|
|
|
|
3234
|
0
|
|
|
|
|
0
|
local $context->{PrincipalEventType} = $self->principal_event_type; |
3235
|
0
|
|
|
|
|
0
|
local $context->{Axis} = $self->op_type; |
3236
|
0
|
|
|
|
|
0
|
local $context->{PossibleEventTypes} = [ $self->possible_event_types( @_ ) ]; |
3237
|
0
|
|
|
|
|
0
|
local $context->{PossiblesSetBy} = $self; |
3238
|
|
|
|
|
|
|
|
3239
|
0
|
0
|
|
|
|
0
|
if ( ! defined $context->{precursorize_action} ) { |
3240
|
|
|
|
|
|
|
## There are no predicates to leftwards |
3241
|
|
|
|
|
|
|
|
3242
|
0
|
|
|
|
|
0
|
my $code = <
|
3243
|
|
|
|
|
|
|
## end_element:: |
3244
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for end_element::" if is_tracing; |
3245
|
|
|
|
|
|
|
push \@{\$ctx->{ChildCtx}->{start_element}}, [ |
3246
|
|
|
|
|
|
|
sub { |
3247
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
3248
|
|
|
|
|
|
|
|
3249
|
|
|
|
|
|
|
}, |
3250
|
|
|
|
|
|
|
\$postponement |
3251
|
|
|
|
|
|
|
]; |
3252
|
|
|
|
|
|
|
CODE_END |
3253
|
|
|
|
|
|
|
|
3254
|
0
|
|
|
|
|
0
|
_replace_NEXT $code, $self->[_next]->as_incr_code( $context ); |
3255
|
0
|
|
|
|
|
0
|
return $code; |
3256
|
|
|
|
|
|
|
} |
3257
|
|
|
|
|
|
|
else { |
3258
|
|
|
|
|
|
|
## There's a predicate to our left that's set the various |
3259
|
|
|
|
|
|
|
## precursor... and action_wrapper, so dance with it... |
3260
|
|
|
|
|
|
|
|
3261
|
|
|
|
|
|
|
## The assumption made in the fixup phase is invalid; we |
3262
|
|
|
|
|
|
|
## now need to queue an EndSub instead of putting the |
3263
|
|
|
|
|
|
|
## action right in to PendingEndActions so that the |
3264
|
|
|
|
|
|
|
## postponement can be tested. |
3265
|
|
|
|
|
|
|
## TODO: see if we can move the detection of precursors in to |
3266
|
|
|
|
|
|
|
## the fixup phase so we can avoid setting IgnoreDelayToEnd |
3267
|
|
|
|
|
|
|
## in that case. |
3268
|
0
|
|
|
|
|
0
|
local $context->{IgnoreDelayToEnd} = 1; |
3269
|
|
|
|
|
|
|
|
3270
|
|
|
|
|
|
|
## the 'action' pushes the context on to the postponement's |
3271
|
|
|
|
|
|
|
## list of contexts. We want that to occur in the end_element. |
3272
|
0
|
|
|
|
|
0
|
my $action_code = <
|
3273
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for end_element::" if is_tracing; |
3274
|
|
|
|
|
|
|
push \@{\$ctx->{EndSubs}}, [ |
3275
|
|
|
|
|
|
|
sub { |
3276
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: running end_element::" if is_tracing; |
3277
|
|
|
|
|
|
|
|
3278
|
|
|
|
|
|
|
}, |
3279
|
|
|
|
|
|
|
]; |
3280
|
|
|
|
|
|
|
CODE_END |
3281
|
|
|
|
|
|
|
|
3282
|
0
|
|
|
|
|
0
|
_replace_NEXT $action_code, $context->{precursorize_action}, ""; |
3283
|
|
|
|
|
|
|
|
3284
|
0
|
|
|
|
|
0
|
local $context->{precursorize_action} = $action_code; |
3285
|
|
|
|
|
|
|
|
3286
|
0
|
|
|
|
|
0
|
my $code = <
|
3287
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for end_element::" if is_tracing; |
3288
|
|
|
|
|
|
|
push \@{\$ctx->{ChildCtx}->{start_element}}, [ |
3289
|
|
|
|
|
|
|
sub { |
3290
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
3291
|
|
|
|
|
|
|
|
3292
|
|
|
|
|
|
|
}, |
3293
|
|
|
|
|
|
|
\$postponement |
3294
|
|
|
|
|
|
|
]; |
3295
|
|
|
|
|
|
|
# end_element:: |
3296
|
|
|
|
|
|
|
CODE_END |
3297
|
|
|
|
|
|
|
|
3298
|
0
|
|
|
|
|
0
|
_replace_NEXT $code, $self->[_next]->as_incr_code( $context ); |
3299
|
|
|
|
|
|
|
|
3300
|
0
|
|
|
|
|
0
|
return $code; |
3301
|
|
|
|
|
|
|
} |
3302
|
|
|
|
|
|
|
} |
3303
|
|
|
|
|
|
|
|
3304
|
|
|
|
|
|
|
|
3305
|
|
|
|
|
|
|
########## |
3306
|
|
|
|
|
|
|
@XFD::Axis::self::ISA = qw( XFD::Axis ); |
3307
|
|
|
|
|
|
|
## don't define possible_node_types; pass the current ones |
3308
|
|
|
|
|
|
|
## through from LHS to RHS. |
3309
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::self::possible_node_types { () } ## () means "all". |
3310
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::self::incr_code_template { "" } |
3311
|
|
|
|
|
|
|
|
3312
|
|
|
|
|
|
|
########## |
3313
|
|
|
|
|
|
|
@XFD::Axis::start::ISA = qw( XFD::Axis::start_element ); |
3314
|
|
|
|
|
|
|
# @XFD::Axis::start::ISA = qw( XFD::Axis ); |
3315
|
|
|
|
|
|
|
#sub XFD::Axis::start::principal_event_type { "start_element" } |
3316
|
|
|
|
|
|
|
#sub XFD::Axis::start::possible_event_type_map { { |
3317
|
|
|
|
|
|
|
# start_document => [qw( start_document )], |
3318
|
|
|
|
|
|
|
# start_element => [qw( start_element )], |
3319
|
|
|
|
|
|
|
#} } |
3320
|
|
|
|
|
|
|
#sub XFD::Axis::start::useful_event_contexts {qw( start_document start_element )} |
3321
|
|
|
|
|
|
|
#sub XFD::Axis::start::incr_code_template { "" } |
3322
|
|
|
|
|
|
|
|
3323
|
|
|
|
|
|
|
########## |
3324
|
|
|
|
|
|
|
@XFD::Axis::start_document::ISA = qw( XFD::Axis ); |
3325
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::start_document::principal_event_type { "start_document" } |
3326
|
|
|
|
|
|
|
sub XFD::Axis::start_document::possible_event_type_map { { |
3327
|
0
|
|
|
0
|
|
0
|
start_document => [qw( start_document )], |
3328
|
|
|
|
|
|
|
} } |
3329
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::start_document::useful_event_contexts { qw( start_document ) } |
3330
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::start_document::incr_code_template { "" } |
3331
|
|
|
|
|
|
|
|
3332
|
|
|
|
|
|
|
########## |
3333
|
|
|
|
|
|
|
@XFD::Axis::start_element::ISA = qw( XFD::Axis ); |
3334
|
|
|
|
|
|
|
sub XFD::Axis::start_element::possible_event_type_map { { |
3335
|
0
|
|
|
0
|
|
0
|
start_element => [qw( start_element )], |
3336
|
|
|
|
|
|
|
} } |
3337
|
0
|
|
|
0
|
|
0
|
sub XFD::Axis::start_element::useful_event_contexts { qw( start_document start_element ) } |
3338
|
|
|
|
|
|
|
sub XFD::Axis::start_element::incr_code_template { |
3339
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3340
|
|
|
|
|
|
|
|
3341
|
0
|
|
|
|
|
0
|
return <
|
3342
|
|
|
|
|
|
|
## start_element:: |
3343
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: queuing for start-element::" if is_tracing; |
3344
|
|
|
|
|
|
|
push \@{\$ctx->{ChildCtx}->{start_element}}, [ |
3345
|
|
|
|
|
|
|
sub { |
3346
|
|
|
|
|
|
|
my ( \$postponement ) = \@_; |
3347
|
|
|
|
|
|
|
|
3348
|
|
|
|
|
|
|
}, |
3349
|
|
|
|
|
|
|
\$postponement |
3350
|
|
|
|
|
|
|
]; |
3351
|
|
|
|
|
|
|
CODE_END |
3352
|
|
|
|
|
|
|
} |
3353
|
|
|
|
|
|
|
|
3354
|
|
|
|
|
|
|
|
3355
|
|
|
|
|
|
|
############################################################################### |
3356
|
|
|
|
|
|
|
## |
3357
|
|
|
|
|
|
|
## Node Type Tests |
3358
|
|
|
|
|
|
|
## |
3359
|
|
|
|
|
|
|
@XFD::EventType::ISA = qw( XFD::PathTest ); |
3360
|
|
|
|
|
|
|
|
3361
|
|
|
|
|
|
|
## Node type tests work by only getting |
3362
|
|
|
|
|
|
|
## curried to the appropriate event types. |
3363
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::incr_code_template { "" } |
3364
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::op_type { shift->XFD::Op::op_type . "()" } |
3365
|
|
|
|
|
|
|
|
3366
|
|
|
|
|
|
|
########## |
3367
|
|
|
|
|
|
|
@XFD::EventType::node::ISA = qw( XFD::EventType ); |
3368
|
|
|
|
|
|
|
## node() has no parameters and is inherently foldable. |
3369
|
|
|
|
|
|
|
## node() ops that need to be curried for different |
3370
|
|
|
|
|
|
|
## event types can't be folded. |
3371
|
|
|
|
|
|
|
sub XFD::EventType::node::optim_signature { |
3372
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3373
|
0
|
0
|
|
|
|
0
|
join "", ref $self, "(", defined $self->[_next] ? $self->[_next]->curry_tests : (), ")"; |
3374
|
|
|
|
|
|
|
} |
3375
|
|
|
|
|
|
|
|
3376
|
|
|
|
|
|
|
|
3377
|
|
|
|
|
|
|
sub XFD::EventType::node::curry_tests { |
3378
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3379
|
0
|
0
|
|
|
|
0
|
return $self->[_next]->curry_tests |
3380
|
|
|
|
|
|
|
if defined $self->[_next]; |
3381
|
|
|
|
|
|
|
|
3382
|
0
|
|
|
|
|
0
|
return @all_curry_tests, "start_prefix_mapping", "end_element", "end_document"; |
3383
|
|
|
|
|
|
|
} |
3384
|
|
|
|
|
|
|
########## |
3385
|
|
|
|
|
|
|
@XFD::EventType::text::ISA = qw( XFD::EventType ); |
3386
|
|
|
|
|
|
|
sub XFD::EventType::text::possible_event_type_map { { |
3387
|
0
|
|
|
0
|
|
0
|
start_element => [qw( characters )], |
3388
|
|
|
|
|
|
|
} } |
3389
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::text::useful_event_contexts { qw( start_element ) } |
3390
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::text::curry_tests { "characters" } |
3391
|
|
|
|
|
|
|
########## |
3392
|
|
|
|
|
|
|
@XFD::EventType::comment::ISA = qw( XFD::EventType ); |
3393
|
|
|
|
|
|
|
sub XFD::EventType::comment::possible_event_type_map { { |
3394
|
0
|
|
|
0
|
|
0
|
start_document => [qw( characters )], |
3395
|
|
|
|
|
|
|
start_element => [qw( characters )], |
3396
|
|
|
|
|
|
|
} } |
3397
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::comment::useful_event_contexts { qw( start_document start_element ) } |
3398
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::comment::curry_tests { "comment" } |
3399
|
|
|
|
|
|
|
########## |
3400
|
|
|
|
|
|
|
@XFD::EventType::processing_instruction::ISA = qw( XFD::EventType ); |
3401
|
|
|
|
|
|
|
sub XFD::EventType::processing_instruction::possible_event_type_map { { |
3402
|
0
|
|
|
0
|
|
0
|
start_document => [qw( processing_instruction )], |
3403
|
|
|
|
|
|
|
start_element => [qw( processing_instruction )], |
3404
|
|
|
|
|
|
|
} } |
3405
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::processing_instruction::useful_event_contexts { qw( start_document start_element ) } |
3406
|
0
|
|
|
0
|
|
0
|
sub XFD::EventType::processing_instruction::curry_tests { "processing_instruction" } |
3407
|
|
|
|
|
|
|
########## |
3408
|
|
|
|
|
|
|
@XFD::EventType::principal_event_type::ISA = qw( XFD::EventType ); |
3409
|
|
|
|
|
|
|
sub XFD::EventType::principal_event_type::curry_tests { |
3410
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3411
|
|
|
|
|
|
|
## 'twould be good if we could see PrincipalEventType here. |
3412
|
|
|
|
|
|
|
## TODO: pass $context down through curry_tests. |
3413
|
0
|
|
|
|
|
0
|
return @all_curry_tests; |
3414
|
|
|
|
|
|
|
} |
3415
|
|
|
|
|
|
|
|
3416
|
|
|
|
|
|
|
sub XFD::EventType::principal_event_type::incr_code_template { |
3417
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3418
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3419
|
|
|
|
|
|
|
|
3420
|
0
|
|
|
|
|
0
|
my $desired_event_type = $context->{PrincipalEventType}; |
3421
|
0
|
0
|
|
|
|
0
|
my @possible_event_types = @{$context->{PossibleEventTypes} || []}; |
|
0
|
|
|
|
|
0
|
|
3422
|
|
|
|
|
|
|
#warn @possible_event_types; |
3423
|
|
|
|
|
|
|
|
3424
|
0
|
0
|
0
|
|
|
0
|
return "" |
3425
|
|
|
|
|
|
|
if @possible_event_types == 1 |
3426
|
|
|
|
|
|
|
&& $possible_event_types[0] eq $desired_event_type; |
3427
|
|
|
|
|
|
|
|
3428
|
0
|
|
|
|
|
0
|
local $" = ", "; |
3429
|
0
|
|
|
|
|
0
|
return <
|
3430
|
|
|
|
|
|
|
## ::* |
3431
|
|
|
|
|
|
|
## possible event types: @possible_event_types |
3432
|
|
|
|
|
|
|
if ( \$ctx->{EventType} eq "$desired_event_type" ) { |
3433
|
|
|
|
|
|
|
emit_trace_SAX_message "EventPath: principal event type $desired_event_type found" if is_tracing; |
3434
|
|
|
|
|
|
|
|
3435
|
|
|
|
|
|
|
} # ::* |
3436
|
|
|
|
|
|
|
CODE_END |
3437
|
|
|
|
|
|
|
} |
3438
|
|
|
|
|
|
|
|
3439
|
|
|
|
|
|
|
#Xsub XFD::EventType::principal_event_type::immed_code_template { |
3440
|
|
|
|
|
|
|
#X my $self = shift; |
3441
|
|
|
|
|
|
|
#X my ( $context ) = @_; |
3442
|
|
|
|
|
|
|
#X |
3443
|
|
|
|
|
|
|
#X my $desired_event_type = $context->{PrincipalEventType}; |
3444
|
|
|
|
|
|
|
#X my @possible_event_types = @{$context->{PossibleEventTypes} || []}; |
3445
|
|
|
|
|
|
|
#X |
3446
|
|
|
|
|
|
|
#X return "" |
3447
|
|
|
|
|
|
|
#X if @possible_event_types == 1 |
3448
|
|
|
|
|
|
|
#X && $possible_event_types[0] eq $desired_event_type; |
3449
|
|
|
|
|
|
|
#X |
3450
|
|
|
|
|
|
|
#X return qq{\$ctx->{EventType} eq "$desired_event_type" ? : ()}; |
3451
|
|
|
|
|
|
|
#X} |
3452
|
|
|
|
|
|
|
|
3453
|
|
|
|
|
|
|
############################################################################### |
3454
|
|
|
|
|
|
|
## |
3455
|
|
|
|
|
|
|
## Optimizer Ops |
3456
|
|
|
|
|
|
|
## |
3457
|
|
|
|
|
|
|
## The optimizer rearranges and tears apart the op tree in to multiple |
3458
|
|
|
|
|
|
|
## trees. Those trees need to be compiled a bit differently and |
3459
|
|
|
|
|
|
|
## need to create a suitable compiletime environment for their children. |
3460
|
|
|
|
|
|
|
## |
3461
|
|
|
|
|
|
|
|
3462
|
|
|
|
|
|
|
########## |
3463
|
|
|
|
|
|
|
@XFD::Optim::attribute::ISA = qw( XFD::union ); |
3464
|
0
|
|
|
0
|
|
0
|
sub XFD::Optim::attribute::possible_event_types { qw( start_element ) } |
3465
|
|
|
|
|
|
|
sub XFD::Optim::attribute::as_incr_code { |
3466
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3467
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3468
|
0
|
|
|
|
|
0
|
local $context->{PossibleEventTypes} = [qw( attribute )]; |
3469
|
0
|
|
|
|
|
0
|
$self->XFD::union::as_incr_code( @_ ); |
3470
|
|
|
|
|
|
|
} |
3471
|
|
|
|
|
|
|
|
3472
|
|
|
|
|
|
|
########## |
3473
|
|
|
|
|
|
|
@XFD::Optim::characters::ISA = qw( XFD::union ); |
3474
|
0
|
|
|
0
|
|
0
|
sub XFD::Optim::characters::possible_event_types { qw( start_element ) } |
3475
|
|
|
|
|
|
|
sub XFD::Optim::characters::as_incr_code { |
3476
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3477
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3478
|
0
|
|
|
|
|
0
|
local $context->{PossibleEventTypes} = [qw( characters )]; |
3479
|
0
|
|
|
|
|
0
|
$self->XFD::union::as_incr_code( @_ ); |
3480
|
|
|
|
|
|
|
} |
3481
|
|
|
|
|
|
|
|
3482
|
|
|
|
|
|
|
########## |
3483
|
|
|
|
|
|
|
@XFD::Optim::comment::ISA = qw( XFD::union ); |
3484
|
|
|
|
|
|
|
sub XFD::Optim::comment::possible_event_types { |
3485
|
0
|
|
|
0
|
|
0
|
qw( start_document start_element ) |
3486
|
|
|
|
|
|
|
} |
3487
|
|
|
|
|
|
|
sub XFD::Optim::comment::as_incr_code { |
3488
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3489
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3490
|
0
|
|
|
|
|
0
|
local $context->{PossibleEventTypes} = [qw( comment )]; |
3491
|
0
|
|
|
|
|
0
|
$self->XFD::union::as_incr_code( @_ ); |
3492
|
|
|
|
|
|
|
} |
3493
|
|
|
|
|
|
|
|
3494
|
|
|
|
|
|
|
########## |
3495
|
|
|
|
|
|
|
@XFD::Optim::processing_instruction::ISA = qw( XFD::union ); |
3496
|
|
|
|
|
|
|
sub XFD::Optim::processing_instruction::possible_event_types { |
3497
|
0
|
|
|
0
|
|
0
|
qw( start_document start_element ) |
3498
|
|
|
|
|
|
|
} |
3499
|
|
|
|
|
|
|
sub XFD::Optim::processing_instruction::as_incr_code { |
3500
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
3501
|
0
|
|
|
|
|
0
|
my ( $context ) = @_; |
3502
|
0
|
|
|
|
|
0
|
local $context->{PossibleEventTypes} = [qw( processing_instruction )]; |
3503
|
0
|
|
|
|
|
0
|
$self->XFD::union::as_incr_code( @_ ); |
3504
|
|
|
|
|
|
|
} |
3505
|
|
|
|
|
|
|
|
3506
|
|
|
|
|
|
|
########## |
3507
|
|
|
|
|
|
|
@XFD::Optim::start_element::ISA = qw( XFD::union ); |
3508
|
0
|
|
|
0
|
|
0
|
sub XFD::Optim::start_element::possible_event_types { qw( start_element ) } |
3509
|
|
|
|
|
|
|
sub XFD::Optim::start_element::as_incr_code { |
3510
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
3511
|
2
|
|
|
|
|
4
|
my ( $context ) = @_; |
3512
|
2
|
|
|
|
|
8
|
local $context->{PossibleEventTypes} = [qw( start_element )]; |
3513
|
2
|
|
|
|
|
10
|
$self->XFD::union::as_incr_code( @_ ); |
3514
|
|
|
|
|
|
|
} |
3515
|
|
|
|
|
|
|
|
3516
|
|
|
|
|
|
|
########## |
3517
|
|
|
|
|
|
|
@XFD::Optim::start_prefix_mapping::ISA = qw( XFD::union ); |
3518
|
0
|
|
|
0
|
|
|
sub XFD::Optim::start_prefix_mapping::possible_event_types { qw( start_document start_element ) } |
3519
|
|
|
|
|
|
|
sub XFD::Optim::start_prefix_mapping::as_incr_code { |
3520
|
0
|
|
|
0
|
|
|
my $self = shift; |
3521
|
0
|
|
|
|
|
|
my ( $context ) = @_; |
3522
|
0
|
|
|
|
|
|
local $context->{PossibleEventTypes} = [qw( start_prefix_mapping )]; |
3523
|
0
|
|
|
|
|
|
$self->XFD::union::as_incr_code( @_ ); |
3524
|
|
|
|
|
|
|
} |
3525
|
|
|
|
|
|
|
|
3526
|
|
|
|
|
|
|
1; |