summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-11-10 12:53:24 (GMT)
committerGuido van Rossum <guido@python.org>1993-11-10 12:53:24 (GMT)
commit52f2c05401ab13eab45a91d39089866f55ef3c9b (patch)
treeae73dc8f72a56cc6c15ae30e9b2e78ef654ae20c
parenta3d78fb268da5cf7cd4d990cf118bfc01650a8d9 (diff)
downloadcpython-52f2c05401ab13eab45a91d39089866f55ef3c9b.zip
cpython-52f2c05401ab13eab45a91d39089866f55ef3c9b.tar.gz
cpython-52f2c05401ab13eab45a91d39089866f55ef3c9b.tar.bz2
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
parser. * mappingobject.c (lookmapping): 'freeslot' was never used due to a bug in the code.
-rw-r--r--Modules/config.c.in7
-rw-r--r--Modules/parsermodule.c108
-rw-r--r--Objects/dictobject.c2
-rw-r--r--Objects/mappingobject.c2
4 files changed, 117 insertions, 2 deletions
diff --git a/Modules/config.c.in b/Modules/config.c.in
index c9f56ac..b8fc15f 100644
--- a/Modules/config.c.in
+++ b/Modules/config.c.in
@@ -296,6 +296,9 @@ extern void initHTML();
#ifdef USE_XLIB
extern void initXlib();
#endif
+#ifdef USE_PARSER
+extern void initparser();
+#endif
/* -- ADDMODULE MARKER 1 -- */
struct {
@@ -475,6 +478,10 @@ struct {
{"Xlib", initXlib},
#endif
+#ifdef USE_PARSER
+ {"parser", initparser},
+#endif
+
/* -- ADDMODULE MARKER 2 -- */
{0, 0} /* Sentinel */
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
new file mode 100644
index 0000000..3274c1a
--- /dev/null
+++ b/Modules/parsermodule.c
@@ -0,0 +1,108 @@
+/***********************************************************
+Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+#include "allobjects.h"
+#include "node.h"
+#include "token.h"
+#include "pythonrun.h"
+#include "graminit.h"
+#include "errcode.h"
+
+object *
+node2tuple(n)
+ node *n;
+{
+ if (n == NULL) {
+ INCREF(None);
+ return None;
+ }
+ if (ISNONTERMINAL(TYPE(n))) {
+ int i;
+ object *v, *w;
+ v = newtupleobject(1 + NCH(n));
+ if (v == NULL)
+ return v;
+ w = newintobject(TYPE(n));
+ if (w == NULL) {
+ DECREF(v);
+ return NULL;
+ }
+ settupleitem(v, 0, w);
+ for (i = 0; i < NCH(n); i++) {
+ w = node2tuple(CHILD(n, i));
+ if (w == NULL) {
+ DECREF(v);
+ return NULL;
+ }
+ settupleitem(v, i+1, w);
+ }
+ return v;
+ }
+ else if (ISTERMINAL(TYPE(n))) {
+ return mkvalue("(is)", TYPE(n), STR(n));
+ }
+ else {
+ err_setstr(SystemError, "unrecognized parse tree node type");
+ return NULL;
+ }
+}
+
+static object *
+parser_parsefile(self, args)
+ object *self;
+ object *args;
+{
+ char *filename;
+ FILE *fp;
+ node *n = NULL;
+ int err;
+ object *res;
+ if (!getargs(args, "s", &filename))
+ return NULL;
+ fp = fopen(filename, "r");
+ if (fp == NULL) {
+ err_errno(IOError);
+ return NULL;
+ }
+ err = parse_file(fp, filename, file_input, &n);
+ fclose(fp);
+ if (err != E_DONE) {
+ err_input(err);
+ return NULL;
+ }
+ res = node2tuple(n);
+ freetree(n);
+ return res;
+}
+
+static struct methodlist parser_methods[] = {
+ {"parsefile", parser_parsefile},
+ {0, 0} /* Sentinel */
+};
+
+void
+initparser()
+{
+ initmodule("parser", parser_methods);
+}
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index c1c1c19..65512be 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -147,7 +147,7 @@ lookmapping(mp, key, hash)
return ep;
}
if (ep->me_key == dummy) {
- if (freeslot != NULL)
+ if (freeslot == NULL)
freeslot = ep;
}
else if (ep->me_hash == hash &&
diff --git a/Objects/mappingobject.c b/Objects/mappingobject.c
index c1c1c19..65512be 100644
--- a/Objects/mappingobject.c
+++ b/Objects/mappingobject.c
@@ -147,7 +147,7 @@ lookmapping(mp, key, hash)
return ep;
}
if (ep->me_key == dummy) {
- if (freeslot != NULL)
+ if (freeslot == NULL)
freeslot = ep;
}
else if (ep->me_hash == hash &&
8e0e491477614bae33c29f6e00d0d48c20b'>Doc/library/textwrap.rst4
-rw-r--r--Doc/library/threading.rst5
-rw-r--r--Doc/library/tokenize.rst5
-rw-r--r--Doc/library/trace.rst4
-rw-r--r--Doc/library/uu.rst4
29 files changed, 134 insertions, 0 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index 66b29e0..a9821e1 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -19,6 +19,9 @@ helper provided in this module. The result will be a tree of objects whose
classes all inherit from :class:`ast.AST`. An abstract syntax tree can be
compiled into a Python code object using the built-in :func:`compile` function.
+.. seealso::
+
+ Latest version of the :source:`ast module Python source code <Lib/ast.py>`
Node classes
------------
diff --git a/Doc/library/atexit.rst b/Doc/library/atexit.rst
index 104c730..1ce45c4 100644
--- a/Doc/library/atexit.rst
+++ b/Doc/library/atexit.rst
@@ -11,6 +11,11 @@ The :mod:`atexit` module defines functions to register and unregister cleanup
functions. Functions thus registered are automatically executed upon normal
interpreter termination.
+.. seealso::
+
+ Latest version of the :source:`atexit Python source code
+ <Lib/atexit.py>`
+
Note: the functions registered via this module are not called when the program
is killed by a signal not handled by Python, when a Python fatal internal error
is detected, or when :func:`os._exit` is called.
diff --git a/Doc/library/bisect.rst b/Doc/library/bisect.rst
index eb23159..ca853e0 100644
--- a/Doc/library/bisect.rst
+++ b/Doc/library/bisect.rst
@@ -14,6 +14,11 @@ approach. The module is called :mod:`bisect` because it uses a basic bisection
algorithm to do its work. The source code may be most useful as a working
example of the algorithm (the boundary conditions are already right!).
+.. seealso::
+
+ Latest version of the :source:`bisect module Python source code
+ <Lib/bisect.py>`
+
The following functions are provided:
diff --git a/Doc/library/calendar.rst b/Doc/library/calendar.rst
index c8dac49..4ebe616 100644
--- a/Doc/library/calendar.rst
+++ b/Doc/library/calendar.rst
@@ -21,6 +21,10 @@ in both directions. This matches the definition of the "proleptic Gregorian"
calendar in Dershowitz and Reingold's book "Calendrical Calculations", where
it's the base calendar for all computations.
+.. seealso::
+
+ Latest version of the :source:`calendar module Python source code
+ <Lib/calendar.py>`
.. class:: Calendar(firstweekday=0)
diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst
index d0332aa..53d62c5 100644
--- a/Doc/library/cmd.rst
+++ b/Doc/library/cmd.rst
@@ -11,6 +11,9 @@ command interpreters. These are often useful for test harnesses, administrative
tools, and prototypes that will later be wrapped in a more sophisticated
interface.
+.. seealso::
+
+ Latest version of the :source:`cmd module Python source code <Lib/cmd.py>`
.. class:: Cmd(completekey='tab', stdin=None, stdout=None)
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 439e3bf..e34e394 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -31,6 +31,11 @@ In addition to the concrete container classes, the collections module provides
ABCs (abstract base classes) that can be used to test whether a class provides a
particular interface, for example, whether it is hashable or a mapping.
+.. seealso::
+
+ Latest version of the :source:`collections module Python source code
+ <Lib/collections.py>`
+
:class:`Counter` objects
------------------------
@@ -1059,6 +1064,9 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
.. seealso::
+ * Latest version of the :source:`Python source code for the collections
+ abstract base classes <Lib/_abcoll.py>`
+
* `OrderedSet recipe <http://code.activestate.com/recipes/576694/>`_ for an
example built on :class:`MutableSet`.
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index 35eb882..5e1a11a 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -9,6 +9,11 @@ This module provides utilities for common tasks involving the :keyword:`with`
statement. For more information see also :ref:`typecontextmanager` and
:ref:`context-managers`.
+.. seealso::
+
+ Latest version of the :source:`contextlib Python source code
+ <Lib/contextlib.py>`
+
Functions provided:
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index b6f1d9f..cf880fc 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -10,6 +10,10 @@ disassembling it. The CPython bytecode which this module takes as an
input is defined in the file :file:`Include/opcode.h` and used by the compiler
and the interpreter.
+.. seealso::
+
+ Latest version of the :source:`dis module Python source code <Lib/dis.py>`
+
.. impl-detail::
Bytecode is an implementation detail of the CPython interpreter! No
diff --git a/Doc/library/filecmp.rst b/Doc/library/filecmp.rst