ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log

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


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

  ViewVC Help
Powered by ViewVC 1.1.5