annotate Doc/lib/libcodeop.tex @ 11036:5adbb3f04cbc legacy-trunk

Two more from Moshe!
author Fred Drake <fdrake@acm.org>
date Wed, 23 Jun 1999 13:33:40 +0000
parents
children e82e82b3b9ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11036
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 % LaTeXed from excellent doc-string.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
2 \section{\module{codeop} ---
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
3 Compile Python code}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
4
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 \declaremodule{standard}{codeop}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 \sectionauthor{Moshe Zadka}{mzadka@geocities.com}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 \modulesynopsis{Compile (possibly incomplete) Python code.}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9 The \module{codeop} module provides a function to compile Python code
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 with hints on whether it certainly complete, possible complete or
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 definitely incomplete. This is used by the \refmodule{code} module
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12 and should not normally be used directly.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14 The \module{codeop} module defines the following function:
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 \begin{funcdesc}{compile_command}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 {source\optional{, filename\optional{, symbol}}}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 Try to compile \var{source}, which should be a string of Python
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 code. Return a code object if \var{source} is valid
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 Python code. In that case, the filename attribute of the code object
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 will be \var{filename}, which defaults to \code{'<input>'}.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 Return \code{None} if \var{source} is \emph{not} valid Python
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 code, but is a prefix of valid Python code.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 Raise an exception if there is a problem with \var{source}:
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 \begin{itemize}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 \item \exception{SyntaxError}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30 if there is invalid Python syntax.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 \item \exception{OverflowError}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 if there is an invalid numeric constant.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 \end{itemize}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35 The \var{symbol} argument means whether to compile it as a statement
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 (\code{'single'}, the default) or as an expression (\code{'eval'}).
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38 \strong{Caveat:}
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 It is possible (but not likely) that the parser stops parsing
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 with a successful outcome before reaching the end of the source;
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41 in this case, trailing symbols may be ignored instead of causing an
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 error. For example, a backslash followed by two newlines may be
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 followed by arbitrary garbage. This will be fixed once the API
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44 for the parser is better.
5adbb3f04cbc Two more from Moshe!
Fred Drake <fdrake@acm.org>
parents:
diff changeset
45 \end{funcdesc}