You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

849 lines
26 KiB

Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
Merged revisions 55007-55179 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ........ r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines Use the new print syntax, at least. ........ r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line remove old cruftiness ........ r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line make this work with the new Python ........ r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line Get asdl code gen working with Python 2.3. Should continue to work with 3.0 ........ r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line Verify checkins to p3yk (sic) branch go to 3000 list. ........ r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line Fix this test so it runs again by importing warnings_test properly. ........ r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines So long xrange. range() now supports values that are outside -sys.maxint to sys.maxint. floats raise a TypeError. This has been sitting for a long time. It probably has some problems and needs cleanup. Objects/rangeobject.c now uses 4-space indents since it is almost completely new. ........ r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines Fix two tests that were previously depending on significant spaces at the end of a line (and before that on Python 2.x print behavior that has no exact equivalent in 3.0). ........
19 years ago
  1. # Copyright (c) 1998-2002 John Aycock
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining
  4. # a copy of this software and associated documentation files (the
  5. # "Software"), to deal in the Software without restriction, including
  6. # without limitation the rights to use, copy, modify, merge, publish,
  7. # distribute, sublicense, and/or sell copies of the Software, and to
  8. # permit persons to whom the Software is furnished to do so, subject to
  9. # the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be
  12. # included in all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  18. # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  19. # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. __version__ = 'SPARK-0.7 (pre-alpha-5)'
  22. import re
  23. # Compatibility with older pythons.
  24. def output(string='', end='\n'):
  25. sys.stdout.write(string + end)
  26. try:
  27. sorted
  28. except NameError:
  29. def sorted(seq):
  30. seq2 = seq[:]
  31. seq2.sort()
  32. return seq2
  33. def _namelist(instance):
  34. namelist, namedict, classlist = [], {}, [instance.__class__]
  35. for c in classlist:
  36. for b in c.__bases__:
  37. classlist.append(b)
  38. for name in c.__dict__.keys():
  39. if name not in namedict:
  40. namelist.append(name)
  41. namedict[name] = 1
  42. return namelist
  43. class GenericScanner:
  44. def __init__(self, flags=0):
  45. pattern = self.reflect()
  46. self.re = re.compile(pattern, re.VERBOSE|flags)
  47. self.index2func = {}
  48. for name, number in self.re.groupindex.items():
  49. self.index2func[number-1] = getattr(self, 't_' + name)
  50. def makeRE(self, name):
  51. doc = getattr(self, name).__doc__
  52. rv = '(?P<%s>%s)' % (name[2:], doc)
  53. return rv
  54. def reflect(self):
  55. rv = []
  56. for name in _namelist(self):
  57. if name[:2] == 't_' and name != 't_default':
  58. rv.append(self.makeRE(name))
  59. rv.append(self.makeRE('t_default'))
  60. return '|'.join(rv)
  61. def error(self, s, pos):
  62. output("Lexical error at position %s" % pos)
  63. raise SystemExit
  64. def tokenize(self, s):
  65. pos = 0
  66. n = len(s)
  67. while pos < n:
  68. m = self.re.match(s, pos)
  69. if m is None:
  70. self.error(s, pos)
  71. groups = m.groups()
  72. for i in range(len(groups)):
  73. if groups[i] and i in self.index2func:
  74. self.index2func[i](groups[i])
  75. pos = m.end()
  76. def t_default(self, s):
  77. r'( . | \n )+'
  78. output("Specification error: unmatched input")
  79. raise SystemExit
  80. #
  81. # Extracted from GenericParser and made global so that [un]picking works.
  82. #
  83. class _State:
  84. def __init__(self, stateno, items):
  85. self.T, self.complete, self.items = [], [], items
  86. self.stateno = stateno
  87. class GenericParser:
  88. #
  89. # An Earley parser, as per J. Earley, "An Efficient Context-Free
  90. # Parsing Algorithm", CACM 13(2), pp. 94-102. Also J. C. Earley,
  91. # "An Efficient Context-Free Parsing Algorithm", Ph.D. thesis,
  92. # Carnegie-Mellon University, August 1968. New formulation of
  93. # the parser according to J. Aycock, "Practical Earley Parsing
  94. # and the SPARK Toolkit", Ph.D. thesis, University of Victoria,
  95. # 2001, and J. Aycock and R. N. Horspool, "Practical Earley
  96. # Parsing", unpublished paper, 2001.
  97. #
  98. def __init__(self, start):
  99. self.rules = {}
  100. self.rule2func = {}
  101. self.rule2name = {}
  102. self.collectRules()
  103. self.augment(start)
  104. self.ruleschanged = 1
  105. _NULLABLE = '\e_'
  106. _START = 'START'
  107. _BOF = '|-'
  108. #
  109. # When pickling, take the time to generate the full state machine;
  110. # some information is then extraneous, too. Unfortunately we
  111. # can't save the rule2func map.
  112. #
  113. def __getstate__(self):
  114. if self.ruleschanged:
  115. #
  116. # XXX - duplicated from parse()
  117. #
  118. self.computeNull()
  119. self.newrules = {}
  120. self.new2old = {}
  121. self.makeNewRules()
  122. self.ruleschanged = 0
  123. self.edges, self.cores = {}, {}
  124. self.states = { 0: self.makeState0() }
  125. self.makeState(0, self._BOF)
  126. #
  127. # XXX - should find a better way to do this..
  128. #
  129. changes = 1
  130. while changes:
  131. changes = 0
  132. for k, v in self.edges.items():
  133. if v is None:
  134. state, sym = k
  135. if state in self.states:
  136. self.goto(state, sym)
  137. changes = 1
  138. rv = self.__dict__.copy()
  139. for s in self.states.values():
  140. del s.items
  141. del rv['rule2func']
  142. del rv['nullable']
  143. del rv['cores']
  144. return rv
  145. def __setstate__(self, D):
  146. self.rules = {}
  147. self.rule2func = {}
  148. self.rule2name = {}
  149. self.collectRules()
  150. start = D['rules'][self._START][0][1][1] # Blech.
  151. self.augment(start)
  152. D['rule2func'] = self.rule2func
  153. D['makeSet'] = self.makeSet_fast
  154. self.__dict__ = D
  155. #
  156. # A hook for GenericASTBuilder and GenericASTMatcher. Mess
  157. # thee not with this; nor shall thee toucheth the _preprocess
  158. # argument to addRule.
  159. #
  160. def preprocess(self, rule, func): return rule, func
  161. def addRule(self, doc, func, _preprocess=1):
  162. fn = func
  163. rules = doc.split()
  164. index = []
  165. for i in range(len(rules)):
  166. if rules[i] == '::=':
  167. index.append(i-1)
  168. index.append(len(rules))
  169. for i in range(len(index)-1):
  170. lhs = rules[index[i]]
  171. rhs = rules[index[i]+2:index[i+1]]
  172. rule = (lhs, tuple(rhs))
  173. if _preprocess:
  174. rule, fn = self.preprocess(rule, func)
  175. if lhs in self.rules:
  176. self.rules[lhs].append(rule)
  177. else:
  178. self.rules[lhs] = [ rule ]
  179. self.rule2func[rule] = fn
  180. self.rule2name[rule] = func.__name__[2:]
  181. self.ruleschanged = 1
  182. def collectRules(self):
  183. for name in _namelist(self):
  184. if name[:2] == 'p_':
  185. func = getattr(self, name)
  186. doc = func.__doc__
  187. self.addRule(doc, func)
  188. def augment(self, start):
  189. rule = '%s ::= %s %s' % (self._START, self._BOF, start)
  190. self.addRule(rule, lambda args: args[1], 0)
  191. def computeNull(self):
  192. self.nullable = {}
  193. tbd = []
  194. for rulelist in self.rules.values():
  195. lhs = rulelist[0][0]
  196. self.nullable[lhs] = 0
  197. for rule in rulelist:
  198. rhs = rule[1]
  199. if len(rhs) == 0:
  200. self.nullable[lhs] = 1
  201. continue
  202. #
  203. # We only need to consider rules which
  204. # consist entirely of nonterminal symbols.
  205. # This should be a savings on typical
  206. # grammars.
  207. #
  208. for sym in rhs:
  209. if sym not in self.rules:
  210. break
  211. else:
  212. tbd.append(rule)
  213. changes = 1
  214. while changes:
  215. changes = 0
  216. for lhs, rhs in tbd:
  217. if self.nullable[lhs]:
  218. continue
  219. for sym in rhs:
  220. if not self.nullable[sym]:
  221. break
  222. else:
  223. self.nullable[lhs] = 1
  224. changes = 1
  225. def makeState0(self):
  226. s0 = _State(0, [])
  227. for rule in self.newrules[self._START]:
  228. s0.items.append((rule, 0))
  229. return s0
  230. def finalState(self, tokens):
  231. #
  232. # Yuck.
  233. #
  234. if len(self.newrules[self._START]) == 2 and len(tokens) == 0:
  235. return 1
  236. start = self.rules[self._START][0][1][1]
  237. return self.goto(1, start)
  238. def makeNewRules(self):
  239. worklist = []
  240. for rulelist in self.rules.values():
  241. for rule in rulelist:
  242. worklist.append((rule, 0, 1, rule))
  243. for rule, i, candidate, oldrule in worklist:
  244. lhs, rhs = rule
  245. n = len(rhs)
  246. while i < n:
  247. sym = rhs[i]
  248. if sym not in self.rules or \
  249. not self.nullable[sym]:
  250. candidate = 0
  251. i = i + 1
  252. continue
  253. newrhs = list(rhs)
  254. newrhs[i] = self._NULLABLE+sym
  255. newrule = (lhs, tuple(newrhs))
  256. worklist.append((newrule, i+1,
  257. candidate, oldrule))
  258. candidate = 0
  259. i = i + 1
  260. else:
  261. if candidate:
  262. lhs = self._NULLABLE+lhs
  263. rule = (lhs, rhs)
  264. if lhs in self.newrules:
  265. self.newrules[lhs].append(rule)
  266. else:
  267. self.newrules[lhs] = [ rule ]
  268. self.new2old[rule] = oldrule
  269. def typestring(self, token):
  270. return None
  271. def error(self, token):
  272. output("Syntax error at or near `%s' token" % token)
  273. raise SystemExit
  274. def parse(self, tokens):
  275. sets = [ [(1,0), (2,0)] ]
  276. self.links = {}
  277. if self.ruleschanged:
  278. self.computeNull()
  279. self.newrules = {}
  280. self.new2old = {}
  281. self.makeNewRules()
  282. self.ruleschanged = 0
  283. self.edges, self.cores = {}, {}
  284. self.states = { 0: self.makeState0() }
  285. self.makeState(0, self._BOF)
  286. for i in range(len(tokens)):
  287. sets.append([])
  288. if sets[i] == []:
  289. break
  290. self.makeSet(tokens[i], sets, i)
  291. else:
  292. sets.append([])
  293. self.makeSet(None, sets, len(tokens))
  294. #_dump(tokens, sets, self.states)
  295. finalitem = (self.finalState(tokens), 0)
  296. if finalitem not in sets[-2]:
  297. if len(tokens) > 0:
  298. self.error(tokens[i-1])
  299. else:
  300. self.error(None)
  301. return self.buildTree(self._START, finalitem,
  302. tokens, len(sets)-2)
  303. def isnullable(self, sym):
  304. #
  305. # For symbols in G_e only. If we weren't supporting 1.5,
  306. # could just use sym.startswith().
  307. #
  308. return self._NULLABLE == sym[0:len(self._NULLABLE)]
  309. def skip(self, hs, pos=0):
  310. n = len(hs[1])
  311. while pos < n:
  312. if not self.isnullable(hs[1][pos]):
  313. break
  314. pos = pos + 1
  315. return pos
  316. def makeState(self, state, sym):
  317. assert sym is not None
  318. #
  319. # Compute \epsilon-kernel state's core and see if
  320. # it exists already.
  321. #
  322. kitems = []
  323. for rule, pos in self.states[state].items:
  324. lhs, rhs = rule
  325. if rhs[pos:pos+1] == (sym,):
  326. kitems.append((rule, self.skip(rule, pos+1)))
  327. core = kitems
  328. core.sort()
  329. tcore = tuple(core)
  330. if tcore in self.cores:
  331. return self.cores[tcore]
  332. #
  333. # Nope, doesn't exist. Compute it and the associated
  334. # \epsilon-nonkernel state together; we'll need it right away.
  335. #
  336. k = self.cores[tcore] = len(self.states)
  337. K, NK = _State(k, kitems), _State(k+1, [])
  338. self.states[k] = K
  339. predicted = {}
  340. edges = self.edges
  341. rules = self.newrules
  342. for X in K, NK:
  343. worklist = X.items
  344. for item in worklist:
  345. rule, pos = item
  346. lhs, rhs = rule
  347. if pos == len(rhs):
  348. X.complete.append(rule)
  349. continue
  350. nextSym = rhs[pos]
  351. key = (X.stateno, nextSym)
  352. if nextSym not in rules:
  353. if key not in edges:
  354. edges[key] = None
  355. X.T.append(nextSym)
  356. else:
  357. edges[key] = None
  358. if nextSym not in predicted:
  359. predicted[nextSym] = 1
  360. for prule in rules[nextSym]:
  361. ppos = self.skip(prule)
  362. new = (prule, ppos)
  363. NK.items.append(new)
  364. #
  365. # Problem: we know K needs generating, but we
  366. # don't yet know about NK. Can't commit anything
  367. # regarding NK to self.edges until we're sure. Should
  368. # we delay committing on both K and NK to avoid this
  369. # hacky code? This creates other problems..
  370. #
  371. if X is K:
  372. edges = {}
  373. if NK.items == []:
  374. return k
  375. #
  376. # Check for \epsilon-nonkernel's core. Unfortunately we
  377. # need to know the entire set of predicted nonterminals
  378. # to do this without accidentally duplicating states.
  379. #
  380. core = sorted(predicted.keys())
  381. tcore = tuple(core)
  382. if tcore in self.cores:
  383. self.edges[(k, None)] = self.cores[tcore]
  384. return k
  385. nk = self.cores[tcore] = self.edges[(k, None)] = NK.stateno
  386. self.edges.update(edges)
  387. self.states[nk] = NK
  388. return k
  389. def goto(self, state, sym):
  390. key = (state, sym)
  391. if key not in self.edges:
  392. #
  393. # No transitions from state on sym.
  394. #
  395. return None
  396. rv = self.edges[key]
  397. if rv is None:
  398. #
  399. # Target state isn't generated yet. Remedy this.
  400. #
  401. rv = self.makeState(state, sym)
  402. self.edges[key] = rv
  403. return rv
  404. def gotoT(self, state, t):
  405. return [self.goto(state, t)]
  406. def gotoST(self, state, st):
  407. rv = []
  408. for t in self.states[state].T:
  409. if st == t:
  410. rv.append(self.goto(state, t))
  411. return rv
  412. def add(self, set, item, i=None, predecessor=None, causal=None):
  413. if predecessor is None:
  414. if item not in set:
  415. set.append(item)
  416. else:
  417. key = (item, i)
  418. if item not in set:
  419. self.links[key] = []
  420. set.append(item)
  421. self.links[key].append((predecessor, causal))
  422. def makeSet(self, token, sets, i):
  423. cur, next = sets[i], sets[i+1]
  424. ttype = token is not None and self.typestring(token) or None
  425. if ttype is not None:
  426. fn, arg = self.gotoT, ttype
  427. else:
  428. fn, arg = self.gotoST, token
  429. for item in cur:
  430. ptr = (item, i)
  431. state, parent = item
  432. add = fn(state, arg)
  433. for k in add:
  434. if k is not None:
  435. self.add(next, (k, parent), i+1, ptr)
  436. nk = self.goto(k, None)
  437. if nk is not None:
  438. self.add(next, (nk, i+1))
  439. if parent == i:
  440. continue
  441. for rule in self.states[state].complete:
  442. lhs, rhs = rule
  443. for pitem in sets[parent]:
  444. pstate, pparent = pitem
  445. k = self.goto(pstate, lhs)
  446. if k is not None:
  447. why = (item, i, rule)
  448. pptr = (pitem, parent)
  449. self.add(cur, (k, pparent),
  450. i, pptr, why)
  451. nk = self.goto(k, None)
  452. if nk is not None:
  453. self.add(cur, (nk, i))
  454. def makeSet_fast(self, token, sets, i):
  455. #
  456. # Call *only* when the entire state machine has been built!
  457. # It relies on self.edges being filled in completely, and
  458. # then duplicates and inlines code to boost speed at the
  459. # cost of extreme ugliness.
  460. #
  461. cur, next = sets[i], sets[i+1]
  462. ttype = token is not None and self.typestring(token) or None
  463. for item in cur:
  464. ptr = (item, i)
  465. state, parent = item
  466. if ttype is not None:
  467. k = self.edges.get((state, ttype), None)
  468. if k is not None:
  469. #self.add(next, (k, parent), i+1, ptr)
  470. #INLINED --v
  471. new = (k, parent)
  472. key = (new, i+1)
  473. if new not in next:
  474. self.links[key] = []
  475. next.append(new)
  476. self.links[key].append((ptr, None))
  477. #INLINED --^
  478. #nk = self.goto(k, None)
  479. nk = self.edges.get((k, None), None)
  480. if nk is not None:
  481. #self.add(next, (nk, i+1))
  482. #INLINED --v
  483. new = (nk, i+1)
  484. if new not in next:
  485. next.append(new)
  486. #INLINED --^
  487. else:
  488. add = self.gotoST(state, token)
  489. for k in add:
  490. if k is not None:
  491. self.add(next, (k, parent), i+1, ptr)
  492. #nk = self.goto(k, None)
  493. nk = self.edges.get((k, None), None)
  494. if nk is not None:
  495. self.add(next, (nk, i+1))
  496. if parent == i:
  497. continue
  498. for rule in self.states[state].complete:
  499. lhs, rhs = rule
  500. for pitem in sets[parent]:
  501. pstate, pparent = pitem
  502. #k = self.goto(pstate, lhs)
  503. k = self.edges.get((pstate, lhs), None)
  504. if k is not None:
  505. why = (item, i, rule)
  506. pptr = (pitem, parent)
  507. #self.add(cur, (k, pparent),
  508. # i, pptr, why)
  509. #INLINED --v
  510. new = (k, pparent)
  511. key = (new, i)
  512. if new not in cur:
  513. self.links[key] = []
  514. cur.append(new)
  515. self.links[key].append((pptr, why))
  516. #INLINED --^
  517. #nk = self.goto(k, None)
  518. nk = self.edges.get((k, None), None)
  519. if nk is not None:
  520. #self.add(cur, (nk, i))
  521. #INLINED --v
  522. new = (nk, i)
  523. if new not in cur:
  524. cur.append(new)
  525. #INLINED --^
  526. def predecessor(self, key, causal):
  527. for p, c in self.links[key]:
  528. if c == causal:
  529. return p
  530. assert 0
  531. def causal(self, key):
  532. links = self.links[key]
  533. if len(links) == 1:
  534. return links[0][1]
  535. choices = []
  536. rule2cause = {}
  537. for p, c in links:
  538. rule = c[2]
  539. choices.append(rule)
  540. rule2cause[rule] = c
  541. return rule2cause[self.ambiguity(choices)]
  542. def deriveEpsilon(self, nt):
  543. if len(self.newrules[nt]) > 1:
  544. rule = self.ambiguity(self.newrules[nt])
  545. else:
  546. rule = self.newrules[nt][0]
  547. #output(rule)
  548. rhs = rule[1]
  549. attr = [None] * len(rhs)
  550. for i in range(len(rhs)-1, -1, -1):
  551. attr[i] = self.deriveEpsilon(rhs[i])
  552. return self.rule2func[self.new2old[rule]](attr)
  553. def buildTree(self, nt, item, tokens, k):
  554. state, parent = item
  555. choices = []
  556. for rule in self.states[state].complete:
  557. if rule[0] == nt:
  558. choices.append(rule)
  559. rule = choices[0]
  560. if len(choices) > 1:
  561. rule = self.ambiguity(choices)
  562. #output(rule)
  563. rhs = rule[1]
  564. attr = [None] * len(rhs)
  565. for i in range(len(rhs)-1, -1, -1):
  566. sym = rhs[i]
  567. if sym not in self.newrules:
  568. if sym != self._BOF:
  569. attr[i] = tokens[k-1]
  570. key = (item, k)
  571. item, k = self.predecessor(key, None)
  572. #elif self.isnullable(sym):
  573. elif self._NULLABLE == sym[0:len(self._NULLABLE)]:
  574. attr[i] = self.deriveEpsilon(sym)
  575. else:
  576. key = (item, k)
  577. why = self.causal(key)
  578. attr[i] = self.buildTree(sym, why[0],
  579. tokens, why[1])
  580. item, k = self.predecessor(key, why)
  581. return self.rule2func[self.new2old[rule]](attr)
  582. def ambiguity(self, rules):
  583. #
  584. # XXX - problem here and in collectRules() if the same rule
  585. # appears in >1 method. Also undefined results if rules
  586. # causing the ambiguity appear in the same method.
  587. #
  588. sortlist = []
  589. name2index = {}
  590. for i in range(len(rules)):
  591. lhs, rhs = rule = rules[i]
  592. name = self.rule2name[self.new2old[rule]]
  593. sortlist.append((len(rhs), name))
  594. name2index[name] = i
  595. sortlist.sort()
  596. list = [b for a, b in sortlist]
  597. return rules[name2index[self.resolve(list)]]
  598. def resolve(self, list):
  599. #
  600. # Resolve ambiguity in favor of the shortest RHS.
  601. # Since we walk the tree from the top down, this
  602. # should effectively resolve in favor of a "shift".
  603. #
  604. return list[0]
  605. #
  606. # GenericASTBuilder automagically constructs a concrete/abstract syntax tree
  607. # for a given input. The extra argument is a class (not an instance!)
  608. # which supports the "__setslice__" and "__len__" methods.
  609. #
  610. # XXX - silently overrides any user code in methods.
  611. #
  612. class GenericASTBuilder(GenericParser):
  613. def __init__(self, AST, start):
  614. GenericParser.__init__(self, start)
  615. self.AST = AST
  616. def preprocess(self, rule, func):
  617. rebind = lambda lhs, self=self: \
  618. lambda args, lhs=lhs, self=self: \
  619. self.buildASTNode(args, lhs)
  620. lhs, rhs = rule
  621. return rule, rebind(lhs)
  622. def buildASTNode(self, args, lhs):
  623. children = []
  624. for arg in args:
  625. if isinstance(arg, self.AST):
  626. children.append(arg)
  627. else:
  628. children.append(self.terminal(arg))
  629. return self.nonterminal(lhs, children)
  630. def terminal(self, token): return token
  631. def nonterminal(self, type, args):
  632. rv = self.AST(type)
  633. rv[:len(args)] = args
  634. return rv
  635. #
  636. # GenericASTTraversal is a Visitor pattern according to Design Patterns. For
  637. # each node it attempts to invoke the method n_<node type>, falling
  638. # back onto the default() method if the n_* can't be found. The preorder
  639. # traversal also looks for an exit hook named n_<node type>_exit (no default
  640. # routine is called if it's not found). To prematurely halt traversal
  641. # of a subtree, call the prune() method -- this only makes sense for a
  642. # preorder traversal. Node type is determined via the typestring() method.
  643. #
  644. class GenericASTTraversalPruningException:
  645. pass
  646. class GenericASTTraversal:
  647. def __init__(self, ast):
  648. self.ast = ast
  649. def typestring(self, node):
  650. return node.type
  651. def prune(self):
  652. raise GenericASTTraversalPruningException
  653. def preorder(self, node=None):
  654. if node is None:
  655. node = self.ast
  656. try:
  657. name = 'n_' + self.typestring(node)
  658. if hasattr(self, name):
  659. func = getattr(self, name)
  660. func(node)
  661. else:
  662. self.default(node)
  663. except GenericASTTraversalPruningException:
  664. return
  665. for kid in node:
  666. self.preorder(kid)
  667. name = name + '_exit'
  668. if hasattr(self, name):
  669. func = getattr(self, name)
  670. func(node)
  671. def postorder(self, node=None):
  672. if node is None:
  673. node = self.ast
  674. for kid in node:
  675. self.postorder(kid)
  676. name = 'n_' + self.typestring(node)
  677. if hasattr(self, name):
  678. func = getattr(self, name)
  679. func(node)
  680. else:
  681. self.default(node)
  682. def default(self, node):
  683. pass
  684. #
  685. # GenericASTMatcher. AST nodes must have "__getitem__" and "__cmp__"
  686. # implemented.
  687. #
  688. # XXX - makes assumptions about how GenericParser walks the parse tree.
  689. #
  690. class GenericASTMatcher(GenericParser):
  691. def __init__(self, start, ast):
  692. GenericParser.__init__(self, start)
  693. self.ast = ast
  694. def preprocess(self, rule, func):
  695. rebind = lambda func, self=self: \
  696. lambda args, func=func, self=self: \
  697. self.foundMatch(args, func)
  698. lhs, rhs = rule
  699. rhslist = list(rhs)
  700. rhslist.reverse()
  701. return (lhs, tuple(rhslist)), rebind(func)
  702. def foundMatch(self, args, func):
  703. func(args[-1])
  704. return args[-1]
  705. def match_r(self, node):
  706. self.input.insert(0, node)
  707. children = 0
  708. for child in node:
  709. if children == 0:
  710. self.input.insert(0, '(')
  711. children = children + 1
  712. self.match_r(child)
  713. if children > 0:
  714. self.input.insert(0, ')')
  715. def match(self, ast=None):
  716. if ast is None:
  717. ast = self.ast
  718. self.input = []
  719. self.match_r(ast)
  720. self.parse(self.input)
  721. def resolve(self, list):
  722. #
  723. # Resolve ambiguity in favor of the longest RHS.
  724. #
  725. return list[-1]
  726. def _dump(tokens, sets, states):
  727. for i in range(len(sets)):
  728. output('set %d' % i)
  729. for item in sets[i]:
  730. output('\t', item)
  731. for (lhs, rhs), pos in states[item[0]].items:
  732. output('\t\t', lhs, '::=', end='')
  733. output(' '.join(rhs[:pos]), end='')
  734. output('.', end='')
  735. output(' '.join(rhs[pos:]))
  736. if i < len(tokens):
  737. output()
  738. output('token %s' % str(tokens[i]))
  739. output()