1 /* regexprops.c -- document the properties of the regular expressions
4 Copyright 2005 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 /* Written by James Youngman, <jay@gnu.org>. */
31 #include "regextype.h"
34 static void output(const char *s
, int escape
)
40 static void newline(void)
45 static void content(const char *s
)
50 static void literal(const char *s
)
55 static void directive(const char *s
)
60 static void enum_item(const char *s
)
67 static void table_item(const char *s
)
75 static void code(const char *s
)
82 static void begin_subsection(const char *name
,
99 directive("@subsection ");
104 static void begintable_asis()
107 directive("@table @asis");
111 static void begintable_markup(char const *markup
)
114 directive("@table ");
119 static void endtable()
122 directive("@end table");
126 static void beginenum()
129 directive("@enumerate");
133 static void endenum()
136 directive("@end enumerate");
140 static void newpara()
146 static int describe_regex_syntax(int options
)
149 if (options
& RE_NO_BK_PARENS
)
151 literal("Grouping is performed with parentheses @samp{()}. ");
153 if (options
& RE_UNMATCHED_RIGHT_PAREN_ORD
)
154 literal("An unmatched @samp{)} matches just itself. ");
158 literal("Grouping is performed with backslashes followed by parentheses @samp{\\(}, @samp{\\)}. ");
161 if (options
& RE_NO_BK_REFS
)
163 content("A backslash followed by a digit matches that digit. ");
167 literal("A backslash followed by a digit acts as a back-reference and matches the same thing as the previous grouped expression indicated by that number. For example @samp{\\2} matches the second group expression. The order of group expressions is determined by the position of their opening parenthesis ");
168 if (options
& RE_NO_BK_PARENS
)
171 literal("@samp{\\(}");
177 if (!(options
& RE_LIMITED_OPS
))
179 if (options
& RE_NO_BK_VBAR
)
180 literal("The alternation operator is @samp{|}. ");
182 literal("The alternation operator is @samp{\\|}. ");
185 content("Bracket expressions are used to match ranges of characters. ");
186 literal("Bracket expressions where the range is backward, for example @samp{[z-a]}, are ");
187 if (options
& RE_NO_EMPTY_RANGES
)
193 if (options
& RE_BACKSLASH_ESCAPE_IN_LISTS
)
194 literal("Within square brackets, @samp{\\} can be used to quote "
195 "the following character. ");
197 literal("Within square brackets, @samp{\\} is taken literally. ");
200 if (!(options
& RE_LIMITED_OPS
))
202 begintable_markup("@samp");
203 if (options
& RE_BK_PLUS_QM
)
206 content("indicates that the regular expression should match one"
207 " or more occurrences of the previous atom or regexp. ");
209 content("indicates that the regular expression should match zero"
210 " or one occurrence of the previous atom or regexp. ");
211 enum_item("+ and ? ");
212 content("match themselves. ");
217 content("indicates that the regular expression should match one"
218 " or more occurrences of the previous atom or regexp. ");
220 content("indicates that the regular expression should match zero"
221 " or one occurrence of the previous atom or regexp. ");
223 literal("matches a @samp{+}");
225 literal("matches a @samp{?}. ");
231 if (options
& RE_CHAR_CLASSES
)
232 content("Character classes are supported. ");
234 literal("Character classes are not not supported, so for example you would need to use @samp{[0-9]} instead of @samp{[[:digit:]]}. ");
238 if (options
& RE_CONTEXT_INDEP_ANCHORS
)
240 literal("The characters @samp{^} and @samp{$} always represent the beginning and end of a string respectively, except within square brackets. Within brackets, @samp{^} can be used to invert the membership of the character class being specified. ");
244 literal("The character @samp{^} only represents the beginning of a string when it appears:");
246 enum_item("\nAt the beginning of a regular expression");
247 enum_item("After an open-group, signified by ");
248 if (options
& RE_NO_BK_PARENS
)
254 literal("@samp{\\(}");
257 if (!(options
& RE_LIMITED_OPS
))
259 if (options
& RE_NEWLINE_ALT
)
260 enum_item("After a newline");
262 if (options
& RE_NO_BK_VBAR
)
263 enum_item("After the alternation operator @samp{|}");
265 enum_item("After the alternation operator @samp{\\|}");
270 literal("The character @samp{$} only represents the end of a string when it appears:");
272 enum_item("At the end of a regular expression");
273 enum_item("Before an close-group, signified by ");
274 if (options
& RE_NO_BK_PARENS
)
280 literal("@samp{\\)}");
282 if (!(options
& RE_LIMITED_OPS
))
284 if (options
& RE_NEWLINE_ALT
)
285 enum_item("Before a newline");
287 if (options
& RE_NO_BK_VBAR
)
288 enum_item("Before the alternation operator @samp{|}");
290 enum_item("Before the alternation operator @samp{\\|}");
296 if (!(options
& RE_LIMITED_OPS
) )
298 if ((options
& RE_CONTEXT_INDEP_OPS
)
299 && !(options
& RE_CONTEXT_INVALID_OPS
))
301 literal("The characters @samp{*}, @samp{+} and @samp{?} are special anywhere in a regular expression. ");
305 if (options
& RE_BK_PLUS_QM
)
306 literal("@samp{\\*}, @samp{\\+} and @samp{\\?} ");
308 literal("@samp{*}, @samp{+} and @samp{?} ");
310 if (options
& RE_CONTEXT_INVALID_OPS
)
312 content("are special at any point in a regular expression except the following places, where they are illegal:");
316 content("are special at any point in a regular expression except:");
320 enum_item("At the beginning of a regular expression");
321 enum_item("After an open-group, signified by ");
322 if (options
& RE_NO_BK_PARENS
)
328 literal("@samp{\\(}");
330 if (!(options
& RE_LIMITED_OPS
))
332 if (options
& RE_NEWLINE_ALT
)
333 enum_item("After a newline");
335 if (options
& RE_NO_BK_VBAR
)
336 enum_item("After the alternation operator @samp{|}");
338 enum_item("After the alternation operator @samp{\\|}");
345 content("The character @samp{.} matches any single character");
346 if ( (options
& RE_DOT_NEWLINE
) == 0 )
348 content(" except newline");
350 if (options
& RE_DOT_NOT_NULL
)
352 if ( (options
& RE_DOT_NEWLINE
) == 0 )
357 content(" the null character");
361 if (options
& RE_HAT_LISTS_NOT_NEWLINE
)
363 literal("Non-matching lists @samp{[^.....]} do not ever match newline. ");
366 if (options
& RE_INTERVALS
)
368 if (options
& RE_NO_BK_BRACES
)
369 literal("Intervals are specified by @samp{@{} and @samp{@}}. ");
371 literal("Intervals are specified by @samp{\\@{} and @samp{\\@}}. ");
373 if (options
& RE_INVALID_INTERVAL_ORD
)
375 literal("Invalid intervals are treated as literals, for example @samp{a@{1} is treated as @samp{a\\@{1}");
379 literal("Invalid intervals such as @samp{a@{1z} are not accepted. ");
383 if (options
& RE_NO_POSIX_BACKTRACKING
)
385 content("Matching succeeds as soon as the whole pattern is matched, meaning that the result may not be the longest possible match. ");
389 content("The longest possible match is returned; this applies to the regular expression as a whole and (subject to this constraint) to subexpressions within groups. ");
393 if (options
& RE_NO_GNU_OPS
)
395 content("GNU extensions are not supported and so "
396 "@samp{\\w}, @samp{\\W}, @samp{\\<}, @samp{\\>}, @samp{\\b}, @samp{\\B}, @samp{\\`}, and @samp{\\'} "
398 "@samp{w}, @samp{W}, @samp{<}, @samp{>}, @samp{b}, @samp{B}, @samp{`}, and @samp{'} respectively. ");
402 content("GNU extensions are supported:");
404 enum_item("@samp{\\w} matches a character within a word");
405 enum_item("@samp{\\W} matches a character which is not within a word");
406 enum_item("@samp{\\<} matches the beginning of a word");
407 enum_item("@samp{\\>} matches the end of a word");
408 enum_item("@samp{\\b} matches a word boundary");
409 enum_item("@samp{\\B} matches characters which are not a word boundaries");
410 enum_item("@samp{\\`} matches the beginning of the whole input");
411 enum_item("@samp{\\'} matches the end of the whole input");
423 output("@menu\n", 0);
425 options
= get_regex_type_flags(i
),
426 name
=get_regex_type_name(i
);
434 output("@end menu\n", 0);
438 static int describe_all(const char *up
)
440 const char *name
, *next
, *previous
;
449 options
= get_regex_type_flags(i
),
450 name
=get_regex_type_name(i
);
453 next
= get_regex_type_name(i
+1);
456 begin_subsection(name
, next
, previous
, up
);
457 parent
= get_regex_type_synonym(i
);
460 content("This is a synonym for ");
461 content(get_regex_type_name(parent
));
466 describe_regex_syntax(options
);
474 int main (int argc
, char *argv
[])