/[pcre]/code/trunk/doc/html/pcrecallout.html
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1194 - (show annotations)
Wed Oct 31 17:42:29 2012 UTC (6 years, 7 months ago) by ph10
File MIME type: text/html
File size: 10148 byte(s)
More documentation updates
1 <html>
2 <head>
3 <title>pcrecallout specification</title>
4 </head>
5 <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6 <h1>pcrecallout man page</h1>
7 <p>
8 Return to the <a href="index.html">PCRE index page</a>.
9 </p>
10 <p>
11 This page is part of the PCRE HTML documentation. It was generated automatically
12 from the original man page. If there is any nonsense in it, please consult the
13 man page, in case the conversion went wrong.
14 <br>
15 <ul>
16 <li><a name="TOC1" href="#SEC1">SYNOPSIS</a>
17 <li><a name="TOC2" href="#SEC2">DESCRIPTION</a>
18 <li><a name="TOC3" href="#SEC3">MISSING CALLOUTS</a>
19 <li><a name="TOC4" href="#SEC4">THE CALLOUT INTERFACE</a>
20 <li><a name="TOC5" href="#SEC5">RETURN VALUES</a>
21 <li><a name="TOC6" href="#SEC6">AUTHOR</a>
22 <li><a name="TOC7" href="#SEC7">REVISION</a>
23 </ul>
24 <br><a name="SEC1" href="#TOC1">SYNOPSIS</a><br>
25 <P>
26 <b>#include &#60;pcre.h&#62;</b>
27 </P>
28 <P>
29 <b>int (*pcre_callout)(pcre_callout_block *);</b>
30 </P>
31 <P>
32 <b>int (*pcre16_callout)(pcre16_callout_block *);</b>
33 </P>
34 <P>
35 <b>int (*pcre32_callout)(pcre32_callout_block *);</b>
36 </P>
37 <br><a name="SEC2" href="#TOC1">DESCRIPTION</a><br>
38 <P>
39 PCRE provides a feature called "callout", which is a means of temporarily
40 passing control to the caller of PCRE in the middle of pattern matching. The
41 caller of PCRE provides an external function by putting its entry point in the
42 global variable <i>pcre_callout</i> (<i>pcre16_callout</i> for the 16-bit
43 library, <i>pcre32_callout</i> for the 32-bit library). By default, this
44 variable contains NULL, which disables all calling out.
45 </P>
46 <P>
47 Within a regular expression, (?C) indicates the points at which the external
48 function is to be called. Different callout points can be identified by putting
49 a number less than 256 after the letter C. The default value is zero.
50 For example, this pattern has two callout points:
51 <pre>
52 (?C1)abc(?C2)def
53 </pre>
54 If the PCRE_AUTO_CALLOUT option bit is set when a pattern is compiled, PCRE
55 automatically inserts callouts, all with number 255, before each item in the
56 pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern
57 <pre>
58 A(\d{2}|--)
59 </pre>
60 it is processed as if it were
61 <br>
62 <br>
63 (?C255)A(?C255)((?C255)\d{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255)
64 <br>
65 <br>
66 Notice that there is a callout before and after each parenthesis and
67 alternation bar. Automatic callouts can be used for tracking the progress of
68 pattern matching. The
69 <a href="pcretest.html"><b>pcretest</b></a>
70 command has an option that sets automatic callouts; when it is used, the output
71 indicates how the pattern is matched. This is useful information when you are
72 trying to optimize the performance of a particular pattern.
73 </P>
74 <P>
75 The use of callouts in a pattern makes it ineligible for optimization by the
76 just-in-time compiler. Studying such a pattern with the PCRE_STUDY_JIT_COMPILE
77 option always fails.
78 </P>
79 <br><a name="SEC3" href="#TOC1">MISSING CALLOUTS</a><br>
80 <P>
81 You should be aware that, because of optimizations in the way PCRE matches
82 patterns by default, callouts sometimes do not happen. For example, if the
83 pattern is
84 <pre>
85 ab(?C4)cd
86 </pre>
87 PCRE knows that any matching string must contain the letter "d". If the subject
88 string is "abyz", the lack of "d" means that matching doesn't ever start, and
89 the callout is never reached. However, with "abyd", though the result is still
90 no match, the callout is obeyed.
91 </P>
92 <P>
93 If the pattern is studied, PCRE knows the minimum length of a matching string,
94 and will immediately give a "no match" return without actually running a match
95 if the subject is not long enough, or, for unanchored patterns, if it has
96 been scanned far enough.
97 </P>
98 <P>
99 You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE
100 option to the matching function, or by starting the pattern with
101 (*NO_START_OPT). This slows down the matching process, but does ensure that
102 callouts such as the example above are obeyed.
103 </P>
104 <br><a name="SEC4" href="#TOC1">THE CALLOUT INTERFACE</a><br>
105 <P>
106 During matching, when PCRE reaches a callout point, the external function
107 defined by <i>pcre_callout</i> or <i>pcre[16|32]_callout</i> is called
108 (if it is set). This applies to both normal and DFA matching. The only
109 argument to the callout function is a pointer to a <b>pcre_callout</b>
110 or <b>pcre[16|32]_callout</b> block.
111 These structures contains the following fields:
112 <pre>
113 int <i>version</i>;
114 int <i>callout_number</i>;
115 int *<i>offset_vector</i>;
116 const char *<i>subject</i>; (8-bit version)
117 PCRE_SPTR16 <i>subject</i>; (16-bit version)
118 PCRE_SPTR32 <i>subject</i>; (32-bit version)
119 int <i>subject_length</i>;
120 int <i>start_match</i>;
121 int <i>current_position</i>;
122 int <i>capture_top</i>;
123 int <i>capture_last</i>;
124 void *<i>callout_data</i>;
125 int <i>pattern_position</i>;
126 int <i>next_item_length</i>;
127 const unsigned char *<i>mark</i>; (8-bit version)
128 const PCRE_UCHAR16 *<i>mark</i>; (16-bit version)
129 const PCRE_UCHAR32 *<i>mark</i>; (32-bit version)
130 </pre>
131 The <i>version</i> field is an integer containing the version number of the
132 block format. The initial version was 0; the current version is 2. The version
133 number will change again in future if additional fields are added, but the
134 intention is never to remove any of the existing fields.
135 </P>
136 <P>
137 The <i>callout_number</i> field contains the number of the callout, as compiled
138 into the pattern (that is, the number after ?C for manual callouts, and 255 for
139 automatically generated callouts).
140 </P>
141 <P>
142 The <i>offset_vector</i> field is a pointer to the vector of offsets that was
143 passed by the caller to the matching function. When <b>pcre_exec()</b> or
144 <b>pcre[16|32]_exec()</b> is used, the contents can be inspected, in order to extract
145 substrings that have been matched so far, in the same way as for extracting
146 substrings after a match has completed. For the DFA matching functions, this
147 field is not useful.
148 </P>
149 <P>
150 The <i>subject</i> and <i>subject_length</i> fields contain copies of the values
151 that were passed to the matching function.
152 </P>
153 <P>
154 The <i>start_match</i> field normally contains the offset within the subject at
155 which the current match attempt started. However, if the escape sequence \K
156 has been encountered, this value is changed to reflect the modified starting
157 point. If the pattern is not anchored, the callout function may be called
158 several times from the same point in the pattern for different starting points
159 in the subject.
160 </P>
161 <P>
162 The <i>current_position</i> field contains the offset within the subject of the
163 current match pointer.
164 </P>
165 <P>
166 When the <b>pcre_exec()</b> or <b>pcre[16|32]_exec()</b> is used, the
167 <i>capture_top</i> field contains one more than the number of the highest
168 numbered captured substring so far. If no substrings have been captured, the
169 value of <i>capture_top</i> is one. This is always the case when the DFA
170 functions are used, because they do not support captured substrings.
171 </P>
172 <P>
173 The <i>capture_last</i> field contains the number of the most recently captured
174 substring. If no substrings have been captured, its value is -1. This is always
175 the case for the DFA matching functions.
176 </P>
177 <P>
178 The <i>callout_data</i> field contains a value that is passed to a matching
179 function specifically so that it can be passed back in callouts. It is passed
180 in the <i>callout_data</i> field of a <b>pcre_extra</b> or <b>pcre[16|32]_extra</b>
181 data structure. If no such data was passed, the value of <i>callout_data</i> in
182 a callout block is NULL. There is a description of the <b>pcre_extra</b>
183 structure in the
184 <a href="pcreapi.html"><b>pcreapi</b></a>
185 documentation.
186 </P>
187 <P>
188 The <i>pattern_position</i> field is present from version 1 of the callout
189 structure. It contains the offset to the next item to be matched in the pattern
190 string.
191 </P>
192 <P>
193 The <i>next_item_length</i> field is present from version 1 of the callout
194 structure. It contains the length of the next item to be matched in the pattern
195 string. When the callout immediately precedes an alternation bar, a closing
196 parenthesis, or the end of the pattern, the length is zero. When the callout
197 precedes an opening parenthesis, the length is that of the entire subpattern.
198 </P>
199 <P>
200 The <i>pattern_position</i> and <i>next_item_length</i> fields are intended to
201 help in distinguishing between different automatic callouts, which all have the
202 same callout number. However, they are set for all callouts.
203 </P>
204 <P>
205 The <i>mark</i> field is present from version 2 of the callout structure. In
206 callouts from <b>pcre_exec()</b> or <b>pcre[16|32]_exec()</b> it contains a pointer to
207 the zero-terminated name of the most recently passed (*MARK), (*PRUNE), or
208 (*THEN) item in the match, or NULL if no such items have been passed. Instances
209 of (*PRUNE) or (*THEN) without a name do not obliterate a previous (*MARK). In
210 callouts from the DFA matching functions this field always contains NULL.
211 </P>
212 <br><a name="SEC5" href="#TOC1">RETURN VALUES</a><br>
213 <P>
214 The external callout function returns an integer to PCRE. If the value is zero,
215 matching proceeds as normal. If the value is greater than zero, matching fails
216 at the current point, but the testing of other matching possibilities goes
217 ahead, just as if a lookahead assertion had failed. If the value is less than
218 zero, the match is abandoned, the matching function returns the negative value.
219 </P>
220 <P>
221 Negative values should normally be chosen from the set of PCRE_ERROR_xxx
222 values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
223 The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
224 it will never be used by PCRE itself.
225 </P>
226 <br><a name="SEC6" href="#TOC1">AUTHOR</a><br>
227 <P>
228 Philip Hazel
229 <br>
230 University Computing Service
231 <br>
232 Cambridge CB2 3QH, England.
233 <br>
234 </P>
235 <br><a name="SEC7" href="#TOC1">REVISION</a><br>
236 <P>
237 Last updated: 24 June 2012
238 <br>
239 Copyright &copy; 1997-2012 University of Cambridge.
240 <br>
241 <p>
242 Return to the <a href="index.html">PCRE index page</a>.
243 </p>

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.5