ViewVC logotype

Contents of /code/trunk/doc/pcrecallout.3

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1335 - (show annotations)
Tue May 28 09:13:59 2013 UTC (6 years, 4 months ago) by ph10
File size: 9189 byte(s)
Final source file tidies for 8.33 release.
1 .TH PCRECALLOUT 3 "03 March 2013" "PCRE 8.33"
3 PCRE - Perl-compatible regular expressions
5 .rs
6 .sp
7 .B #include <pcre.h>
8 .PP
9 .SM
10 .B int (*pcre_callout)(pcre_callout_block *);
11 .PP
12 .B int (*pcre16_callout)(pcre16_callout_block *);
13 .PP
14 .B int (*pcre32_callout)(pcre32_callout_block *);
15 .
17 .rs
18 .sp
19 PCRE provides a feature called "callout", which is a means of temporarily
20 passing control to the caller of PCRE in the middle of pattern matching. The
21 caller of PCRE provides an external function by putting its entry point in the
22 global variable \fIpcre_callout\fP (\fIpcre16_callout\fP for the 16-bit
23 library, \fIpcre32_callout\fP for the 32-bit library). By default, this
24 variable contains NULL, which disables all calling out.
25 .P
26 Within a regular expression, (?C) indicates the points at which the external
27 function is to be called. Different callout points can be identified by putting
28 a number less than 256 after the letter C. The default value is zero.
29 For example, this pattern has two callout points:
30 .sp
31 (?C1)abc(?C2)def
32 .sp
33 If the PCRE_AUTO_CALLOUT option bit is set when a pattern is compiled, PCRE
34 automatically inserts callouts, all with number 255, before each item in the
35 pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern
36 .sp
37 A(\ed{2}|--)
38 .sp
39 it is processed as if it were
40 .sp
41 (?C255)A(?C255)((?C255)\ed{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255)
42 .sp
43 Notice that there is a callout before and after each parenthesis and
44 alternation bar. If the pattern contains a conditional group whose condition is
45 an assertion, an automatic callout is inserted immediately before the
46 condition. Such a callout may also be inserted explicitly, for example:
47 .sp
48 (?(?C9)(?=a)ab|de)
49 .sp
50 This applies only to assertion conditions (because they are themselves
51 independent groups).
52 .P
53 Automatic callouts can be used for tracking the progress of pattern matching.
54 The
55 .\" HREF
56 \fBpcretest\fP
57 .\"
58 command has an option that sets automatic callouts; when it is used, the output
59 indicates how the pattern is matched. This is useful information when you are
60 trying to optimize the performance of a particular pattern.
61 .
62 .
64 .rs
65 .sp
66 You should be aware that, because of optimizations in the way PCRE matches
67 patterns by default, callouts sometimes do not happen. For example, if the
68 pattern is
69 .sp
70 ab(?C4)cd
71 .sp
72 PCRE knows that any matching string must contain the letter "d". If the subject
73 string is "abyz", the lack of "d" means that matching doesn't ever start, and
74 the callout is never reached. However, with "abyd", though the result is still
75 no match, the callout is obeyed.
76 .P
77 If the pattern is studied, PCRE knows the minimum length of a matching string,
78 and will immediately give a "no match" return without actually running a match
79 if the subject is not long enough, or, for unanchored patterns, if it has
80 been scanned far enough.
81 .P
82 You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE
83 option to the matching function, or by starting the pattern with
84 (*NO_START_OPT). This slows down the matching process, but does ensure that
85 callouts such as the example above are obeyed.
86 .
87 .
89 .rs
90 .sp
91 During matching, when PCRE reaches a callout point, the external function
92 defined by \fIpcre_callout\fP or \fIpcre[16|32]_callout\fP is called
93 (if it is set). This applies to both normal and DFA matching. The only
94 argument to the callout function is a pointer to a \fBpcre_callout\fP
95 or \fBpcre[16|32]_callout\fP block.
96 These structures contains the following fields:
97 .sp
98 int \fIversion\fP;
99 int \fIcallout_number\fP;
100 int *\fIoffset_vector\fP;
101 const char *\fIsubject\fP; (8-bit version)
102 PCRE_SPTR16 \fIsubject\fP; (16-bit version)
103 PCRE_SPTR32 \fIsubject\fP; (32-bit version)
104 int \fIsubject_length\fP;
105 int \fIstart_match\fP;
106 int \fIcurrent_position\fP;
107 int \fIcapture_top\fP;
108 int \fIcapture_last\fP;
109 void *\fIcallout_data\fP;
110 int \fIpattern_position\fP;
111 int \fInext_item_length\fP;
112 const unsigned char *\fImark\fP; (8-bit version)
113 const PCRE_UCHAR16 *\fImark\fP; (16-bit version)
114 const PCRE_UCHAR32 *\fImark\fP; (32-bit version)
115 .sp
116 The \fIversion\fP field is an integer containing the version number of the
117 block format. The initial version was 0; the current version is 2. The version
118 number will change again in future if additional fields are added, but the
119 intention is never to remove any of the existing fields.
120 .P
121 The \fIcallout_number\fP field contains the number of the callout, as compiled
122 into the pattern (that is, the number after ?C for manual callouts, and 255 for
123 automatically generated callouts).
124 .P
125 The \fIoffset_vector\fP field is a pointer to the vector of offsets that was
126 passed by the caller to the matching function. When \fBpcre_exec()\fP or
127 \fBpcre[16|32]_exec()\fP is used, the contents can be inspected, in order to
128 extract substrings that have been matched so far, in the same way as for
129 extracting substrings after a match has completed. For the DFA matching
130 functions, this field is not useful.
131 .P
132 The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values
133 that were passed to the matching function.
134 .P
135 The \fIstart_match\fP field normally contains the offset within the subject at
136 which the current match attempt started. However, if the escape sequence \eK
137 has been encountered, this value is changed to reflect the modified starting
138 point. If the pattern is not anchored, the callout function may be called
139 several times from the same point in the pattern for different starting points
140 in the subject.
141 .P
142 The \fIcurrent_position\fP field contains the offset within the subject of the
143 current match pointer.
144 .P
145 When the \fBpcre_exec()\fP or \fBpcre[16|32]_exec()\fP is used, the
146 \fIcapture_top\fP field contains one more than the number of the highest
147 numbered captured substring so far. If no substrings have been captured, the
148 value of \fIcapture_top\fP is one. This is always the case when the DFA
149 functions are used, because they do not support captured substrings.
150 .P
151 The \fIcapture_last\fP field contains the number of the most recently captured
152 substring. However, when a recursion exits, the value reverts to what it was
153 outside the recursion, as do the values of all captured substrings. If no
154 substrings have been captured, the value of \fIcapture_last\fP is -1. This is
155 always the case for the DFA matching functions.
156 .P
157 The \fIcallout_data\fP field contains a value that is passed to a matching
158 function specifically so that it can be passed back in callouts. It is passed
159 in the \fIcallout_data\fP field of a \fBpcre_extra\fP or \fBpcre[16|32]_extra\fP
160 data structure. If no such data was passed, the value of \fIcallout_data\fP in
161 a callout block is NULL. There is a description of the \fBpcre_extra\fP
162 structure in the
163 .\" HREF
164 \fBpcreapi\fP
165 .\"
166 documentation.
167 .P
168 The \fIpattern_position\fP field is present from version 1 of the callout
169 structure. It contains the offset to the next item to be matched in the pattern
170 string.
171 .P
172 The \fInext_item_length\fP field is present from version 1 of the callout
173 structure. It contains the length of the next item to be matched in the pattern
174 string. When the callout immediately precedes an alternation bar, a closing
175 parenthesis, or the end of the pattern, the length is zero. When the callout
176 precedes an opening parenthesis, the length is that of the entire subpattern.
177 .P
178 The \fIpattern_position\fP and \fInext_item_length\fP fields are intended to
179 help in distinguishing between different automatic callouts, which all have the
180 same callout number. However, they are set for all callouts.
181 .P
182 The \fImark\fP field is present from version 2 of the callout structure. In
183 callouts from \fBpcre_exec()\fP or \fBpcre[16|32]_exec()\fP it contains a
184 pointer to the zero-terminated name of the most recently passed (*MARK),
185 (*PRUNE), or (*THEN) item in the match, or NULL if no such items have been
186 passed. Instances of (*PRUNE) or (*THEN) without a name do not obliterate a
187 previous (*MARK). In callouts from the DFA matching functions this field always
188 contains NULL.
189 .
190 .
192 .rs
193 .sp
194 The external callout function returns an integer to PCRE. If the value is zero,
195 matching proceeds as normal. If the value is greater than zero, matching fails
196 at the current point, but the testing of other matching possibilities goes
197 ahead, just as if a lookahead assertion had failed. If the value is less than
198 zero, the match is abandoned, the matching function returns the negative value.
199 .P
200 Negative values should normally be chosen from the set of PCRE_ERROR_xxx
201 values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
202 The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
203 it will never be used by PCRE itself.
204 .
205 .
207 .rs
208 .sp
209 .nf
210 Philip Hazel
211 University Computing Service
212 Cambridge CB2 3QH, England.
213 .fi
214 .
215 .
217 .rs
218 .sp
219 .nf
220 Last updated: 03 March 2013
221 Copyright (c) 1997-2013 University of Cambridge.
222 .fi


Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

  ViewVC Help
Powered by ViewVC 1.1.5