From c69e0ec6e6fd5e7018ab78026625c5c04dbf5d54 Mon Sep 17 00:00:00 2001 From: John Millaway Date: Fri, 24 Mar 2006 18:57:57 +0000 Subject: Added appendix of patterns to manual. --- doc/flex.texi | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 13 deletions(-) (limited to 'doc') diff --git a/doc/flex.texi b/doc/flex.texi index 0a9be3e..9a0ac04 100644 --- a/doc/flex.texi +++ b/doc/flex.texi @@ -8339,28 +8339,100 @@ scanner is ordinary C or C++, and does @emph{not} require @code{m4}. This appendix provides examples of common regular expressions you might use in your scanner. -Numbers +@menu +* Numbers:: +* Quoted Constructs:: +* Addresses:: +@end menu + + +@node Numbers, Quoted Constructs, ,Common Patterns +@subsection Numbers @table @asis -@item an signed integer -@code{[+-]?([[:digit:]]@{-@}[0])[[:digit:]]*} +@item C99 decimal constant +@code{([[:digit:]]@{-@}[0])[[:digit:]]*} + +@item C99 hexadecimal constant +@code{0[xX][[:xdigit:]]+} + +@item C99 octal constant +@code{0[0123456]*} + +@item C99 floating point constant +@verbatim + {dseq} ([[:digit:]]+) + {dseq_opt} ([[:digit:]]*) + {frac} (({dseq_opt}"."{dseq})|{dseq}".") + {exp} ([eE][+-]?{dseq}) + {exp_opt} ({exp}?) + {fsuff} [flFL] + {fsuff_opt} ({fsuff}?) + {hpref} (0[xX]) + {hdseq} ([[:xdigit:]]+) + {hdseq_opt} ([[:xdigit:]]*) + {hfrac} (({hdseq_opt}"."{hdseq})|({hdseq}".")) + {bexp} ([pP][+-]?{dseq}) + {dfc} (({frac}{exp_opt}{fsuff_opt})|({dseq}{exp}{fsuff_opt})) + {hfc} (({hpref}{hfrac}{bexp}{fsuff_opt})|({hpref}{hdseq}{bexp}{fsuff_opt})) -@item a hexadecimal constant -@code{0x[[:xdigit:]]+} + {c99_floating_point_constant} ({dfc}|{hfc}) +@end verbatim + +See C99 section 6.4.4.2 for the gory details. + +@end table + +@node Quoted Constructs, Addresses, Numbers, Common Patterns +@subsection Quoted Constructs + +@table @asis +@item C99 String Literal +@code{L?\"([^\"\\\n]|(\\['\"?\\abfnrtv])|(\\([0123456]@{1,3@}))|(\\x[[:xdigit:]]+)|(\\[uU]([[:xdigit:]]@{4@})))*\"} -@item an octal constant -@code{0[0123456]+} +@item C99 Comment +@code{("/*"([^*]|"*"[^/])*"*/")|(/(\\\n)*/[^\n]*)} -@item a decimal constant -@code{[+-]([[:digit:]]@{-@}[0])[[:digit:]]*("."[[:digit:]]+)?} +Note that in C99, a @samp{//}-style comment may be split across lines, and, contrary to popular belief, +does not include the trailing @samp{\n} character. -@c TODO -@item a C99 floating point constant -@code{[+-] ([[:digit:]]*"."[[:digit:]]+|[[:digit:]]+\.) ([E]?[[:digit:]]+) [FL]? |INF|INFINITY|(NAN("("")")?)} +A better way to scan @samp{/* */} comments is by line, rather than matching +possibly huge comments all at once. This will allow you to scan comments of +unlimited length, as long as line breaks appear at sane intervals. This is also +more efficient when used with automatic line number processing. @xref{option-yylineno}. -(See C99 section 6.4.4.2.) +@verbatim +{ + "/*" BEGIN(COMMENT); +} +{ + "*/" BEGIN(0); + [^*\n]+ ; + "*"[^/] ; + \n ; +} +@end verbatim + +@end table + +@node Addresses, ,Quoted Constructs, Common Patterns +@subsection Addresses + +@table @asis + +@item IPv4 Address +@code{(([[:digit:]]@{1,3@}".")@{3@}([[:digit:]]@{1,3@}))} + +@item IPv6 Address +@verbatim +hex4 ([[:xdigit:]]{1,4}) +hexseq ({hex4}(:{hex4}*)) +hexpart ({hexseq}|({hexseq}::({hexseq}?))|::{hexseq}) +IPv6address ({hexpart}(":"{IPv4address})?) +@end verbatim +See RFC 2373 for details. @end table -- cgit v1.2.3