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
,
91 content(" regular expression syntax");
94 directive("@subsection ");
98 content(" regular expression syntax");
102 static void begintable_asis()
105 directive("@table @asis");
109 static void begintable_markup(char const *markup
)
112 directive("@table ");
117 static void endtable()
120 directive("@end table");
124 static void beginenum()
127 directive("@enumerate");
131 static void endenum()
134 directive("@end enumerate");
138 static void newpara()
144 static int describe_regex_syntax(int options
)
147 content("The character @samp{.} matches any single character");
148 if ( (options
& RE_DOT_NEWLINE
) == 0 )
150 content(" except newline");
152 if (options
& RE_DOT_NOT_NULL
)
154 if ( (options
& RE_DOT_NEWLINE
) == 0 )
159 content(" the null character");
164 if (!(options
& RE_LIMITED_OPS
))
166 begintable_markup("@samp");
167 if (options
& RE_BK_PLUS_QM
)
170 content("indicates that the regular expression should match one"
171 " or more occurrences of the previous atom or regexp. ");
173 content("indicates that the regular expression should match zero"
174 " or one occurrence of the previous atom or regexp. ");
175 enum_item("+ and ? ");
176 content("match themselves. ");
181 content("indicates that the regular expression should match one"
182 " or more occurrences of the previous atom or regexp. ");
184 content("indicates that the regular expression should match zero"
185 " or one occurrence of the previous atom or regexp. ");
187 literal("matches a @samp{+}");
189 literal("matches a @samp{?}. ");
196 content("Bracket expressions are used to match ranges of characters. ");
197 literal("Bracket expressions where the range is backward, for example @samp{[z-a]}, are ");
198 if (options
& RE_NO_EMPTY_RANGES
)
204 if (options
& RE_BACKSLASH_ESCAPE_IN_LISTS
)
205 literal("Within square brackets, @samp{\\} can be used to quote "
206 "the following character. ");
208 literal("Within square brackets, @samp{\\} is taken literally. ");
210 if (options
& RE_CHAR_CLASSES
)
211 content("Character classes are supported. ");
213 literal("Character classes are not not supported, so for example you would need to use @samp{[0-9]} instead of @samp{[[:digit:]]}. ");
215 if (options
& RE_HAT_LISTS_NOT_NEWLINE
)
217 literal("Non-matching lists @samp{[^.....]} do not ever match newline. ");
220 if (options
& RE_NO_GNU_OPS
)
222 content("GNU extensions are not supported and so "
223 "@samp{\\w}, @samp{\\W}, @samp{\\<}, @samp{\\>}, @samp{\\b}, @samp{\\B}, @samp{\\`}, and @samp{\\'} "
225 "@samp{w}, @samp{W}, @samp{<}, @samp{>}, @samp{b}, @samp{B}, @samp{`}, and @samp{'} respectively. ");
229 content("GNU extensions are supported:");
231 enum_item("@samp{\\w} matches a character within a word");
232 enum_item("@samp{\\W} matches a character which is not within a word");
233 enum_item("@samp{\\<} matches the beginning of a word");
234 enum_item("@samp{\\>} matches the end of a word");
235 enum_item("@samp{\\b} matches a word boundary");
236 enum_item("@samp{\\B} matches characters which are not a word boundary");
237 enum_item("@samp{\\`} matches the beginning of the whole input");
238 enum_item("@samp{\\'} matches the end of the whole input");
245 if (options
& RE_NO_BK_PARENS
)
247 literal("Grouping is performed with parentheses @samp{()}. ");
249 if (options
& RE_UNMATCHED_RIGHT_PAREN_ORD
)
250 literal("An unmatched @samp{)} matches just itself. ");
254 literal("Grouping is performed with backslashes followed by parentheses @samp{\\(}, @samp{\\)}. ");
257 if (options
& RE_NO_BK_REFS
)
259 content("A backslash followed by a digit matches that digit. ");
263 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 ");
264 if (options
& RE_NO_BK_PARENS
)
267 literal("@samp{\\(}");
273 if (!(options
& RE_LIMITED_OPS
))
275 if (options
& RE_NO_BK_VBAR
)
276 literal("The alternation operator is @samp{|}. ");
278 literal("The alternation operator is @samp{\\|}. ");
282 if (options
& RE_CONTEXT_INDEP_ANCHORS
)
284 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. ");
288 literal("The character @samp{^} only represents the beginning of a string when it appears:");
290 enum_item("\nAt the beginning of a regular expression");
291 enum_item("After an open-group, signified by ");
292 if (options
& RE_NO_BK_PARENS
)
298 literal("@samp{\\(}");
301 if (!(options
& RE_LIMITED_OPS
))
303 if (options
& RE_NEWLINE_ALT
)
304 enum_item("After a newline");
306 if (options
& RE_NO_BK_VBAR
)
307 enum_item("After the alternation operator @samp{|}");
309 enum_item("After the alternation operator @samp{\\|}");
314 literal("The character @samp{$} only represents the end of a string when it appears:");
316 enum_item("At the end of a regular expression");
317 enum_item("Before an close-group, signified by ");
318 if (options
& RE_NO_BK_PARENS
)
324 literal("@samp{\\)}");
326 if (!(options
& RE_LIMITED_OPS
))
328 if (options
& RE_NEWLINE_ALT
)
329 enum_item("Before a newline");
331 if (options
& RE_NO_BK_VBAR
)
332 enum_item("Before the alternation operator @samp{|}");
334 enum_item("Before the alternation operator @samp{\\|}");
339 if (!(options
& RE_LIMITED_OPS
) )
341 if ((options
& RE_CONTEXT_INDEP_OPS
)
342 && !(options
& RE_CONTEXT_INVALID_OPS
))
344 literal("The characters @samp{*}, @samp{+} and @samp{?} are special anywhere in a regular expression. ");
348 if (options
& RE_BK_PLUS_QM
)
349 literal("@samp{\\*}, @samp{\\+} and @samp{\\?} ");
351 literal("@samp{*}, @samp{+} and @samp{?} ");
353 if (options
& RE_CONTEXT_INVALID_OPS
)
355 content("are special at any point in a regular expression except the following places, where they are illegal:");
359 content("are special at any point in a regular expression except:");
363 enum_item("At the beginning of a regular expression");
364 enum_item("After an open-group, signified by ");
365 if (options
& RE_NO_BK_PARENS
)
371 literal("@samp{\\(}");
373 if (!(options
& RE_LIMITED_OPS
))
375 if (options
& RE_NEWLINE_ALT
)
376 enum_item("After a newline");
378 if (options
& RE_NO_BK_VBAR
)
379 enum_item("After the alternation operator @samp{|}");
381 enum_item("After the alternation operator @samp{\\|}");
389 if (options
& RE_INTERVALS
)
391 if (options
& RE_NO_BK_BRACES
)
393 literal("Intervals are specified by @samp{@{} and @samp{@}}. ");
394 if (options
& RE_INVALID_INTERVAL_ORD
)
396 literal("Invalid intervals are treated as literals, for example @samp{a@{1} is treated as @samp{a\\@{1}");
400 literal("Invalid intervals such as @samp{a@{1z} are not accepted. ");
405 literal("Intervals are specified by @samp{\\@{} and @samp{\\@}}. ");
406 if (options
& RE_INVALID_INTERVAL_ORD
)
408 literal("Invalid intervals are treated as literals, for example @samp{a\\@{1} is treated as @samp{a@{1}");
412 literal("Invalid intervals such as @samp{a\\@{1z} are not accepted. ");
419 if (options
& RE_NO_POSIX_BACKTRACKING
)
421 content("Matching succeeds as soon as the whole pattern is matched, meaning that the result may not be the longest possible match. ");
425 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. ");
437 output("@menu\n", 0);
439 options
= get_regex_type_flags(i
),
440 name
=get_regex_type_name(i
);
445 content(" regular expression syntax");
449 output("@end menu\n", 0);
453 static int describe_all(const char *up
)
455 const char *name
, *next
, *previous
;
464 options
= get_regex_type_flags(i
),
465 name
=get_regex_type_name(i
);
468 next
= get_regex_type_name(i
+1);
471 begin_subsection(name
, next
, previous
, up
);
472 parent
= get_regex_type_synonym(i
);
475 content("This is a synonym for ");
476 content(get_regex_type_name(parent
));
481 describe_regex_syntax(options
);
489 int main (int argc
, char *argv
[])