11% Module and documentation by Eric S. Raymond, 21 Dec 1998
2- \section {Standard Module \module {shlex} }
3- \stmodindex {shlex}
4- \label {module-shlex }
52
6- The \code {shlex} class makes it easy to write lexical analyzers for
7- simple syntaxes resembling that of the Unix shell. This will often
8- be useful for writing minilanguages, e.g. in run control files for
3+ \section {\module {shlex} ---
4+ Simple lexical analysis }
5+
6+ \declaremodule {standard}{shlex}
7+ \moduleauthor {Eric S. Raymond}{
[email protected] }
8+ \sectionauthor {Eric S. Raymond}{
[email protected] }
9+
10+
11+ The \class {shlex} class makes it easy to write lexical analyzers for
12+ simple syntaxes resembling that of the \UNIX {} shell. This will often
13+ be useful for writing minilanguages, e.g.\ in run control files for
914Python applications.
1015
1116\begin {classdesc }{shlex}{\optional {stream}}
1217A \class {shlex} instance or subclass instance is a lexical analyzer
1318object. The initialization argument, if present, specifies where to
1419read characters from. It must be a file- or stream-like object with
15- \method {read} and \method {readline} methods. If no argument is given,
16- input will be taken from sys.stdin.
20+ \method {read() } and \method {readline() } methods. If no argument is given,
21+ input will be taken from \code { sys.stdin} .
1722
1823\end {classdesc }
1924
20- \subsection {shlex Objects }
21- \label {shlex-objects }
25+ \subsection {shlex Objects \label {shlex-objects } }
2226
2327A \class {shlex} instance has the following methods:
2428
2529\begin {methoddesc }{get_token}{}
26- Return a token. If tokens have been stacked using \method {push_token},
27- pop a token off the stack. Otherwise, read one from the input stream.
28- If reading encounters an immediate end-of-file, '' is returned.
30+ Return a token. If tokens have been stacked using
31+ \method {push_token()}, pop a token off the stack. Otherwise, read one
32+ from the input stream. If reading encounters an immediate
33+ end-of-file, an empty string is returned.
2934\end {methoddesc }
3035
3136\begin {methoddesc }{push_token}{str}
@@ -39,39 +44,40 @@ \subsection{shlex Objects}
3944\begin {memberdesc }{commenters}
4045The string of characters that are recognized as comment beginners.
4146All characters from the comment beginner to end of line are ignored.
42- Includes just '#' by default.
47+ Includes just \character { \# } by default.
4348\end {memberdesc }
4449
4550\begin {memberdesc }{wordchars}
4651The string of characters that will accumulate into multi-character
47- tokens. By default, includes all ASCII alphanumerics and underscore.
52+ tokens. By default, includes all \ASCII {} alphanumerics and
53+ underscore.
4854\end {memberdesc }
4955
5056\begin {memberdesc }{whitespace}
5157Characters that will be considered whitespace and skipped. Whitespace
52- bounds tokens. By default, includes space and tab and linefeed and
58+ bounds tokens. By default, includes space, tab, linefeed and
5359carriage-return.
5460\end {memberdesc }
5561
5662\begin {memberdesc }{quotes}
5763Characters that will be considered string quotes. The token
5864accumulates until the same quote is encountered again (thus, different
5965quote types protect each other as in the shall.) By default, includes
60- ASCII single and double quotes.
66+ \ ASCII{} single and double quotes.
6167\end {memberdesc }
6268
6369Note that any character not declared to be a word character,
6470whitespace, or a quote will be returned as a single-character token.
6571
6672Quote and comment characters are not recognized within words. Thus,
67- the bare words `` ain't'' and `` ain#t '' would be returned as single
73+ the bare words \samp { ain't} and \samp { ain\# t} would be returned as single
6874tokens by the default parser.
6975
7076\begin {memberdesc }{lineno}
7177Source line number (count of newlines seen so far plus one).
7278\end {memberdesc }
7379
7480\begin {memberdesc }{token}
75- The token buffer. It may be useful to examine this when catching exceptions.
81+ The token buffer. It may be useful to examine this when catching
82+ exceptions.
7683\end {memberdesc }
77-
0 commit comments