diff options
author | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-01-09 20:44:25 +0000 |
---|---|---|
committer | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-01-09 20:44:25 +0000 |
commit | d77fdfef70e08114f57cbef5d91707df8717ea9f (patch) | |
tree | 49444e3486c0c333cb7b33dfa721296c08ee4ece /test/test_readers/test_python/showparse | |
parent | 53cd16ca6ca5f638cbe5956988e88f9339e355cf (diff) | |
parent | 3993c4097756e9885bcfbd07cb1cc1e4e95e50e4 (diff) | |
download | docutils-0.4.tar.gz |
Release 0.4: tagging released revisiondocutils-0.4
git-svn-id: http://svn.code.sf.net/p/docutils/code/tags/docutils-0.4@4268 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'test/test_readers/test_python/showparse')
-rwxr-xr-x | test/test_readers/test_python/showparse | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/test_readers/test_python/showparse b/test/test_readers/test_python/showparse new file mode 100755 index 000000000..8144256d6 --- /dev/null +++ b/test/test_readers/test_python/showparse @@ -0,0 +1,48 @@ +#! /usr/bin/env python + +""" +This is a tool for exploring abstract syntax trees generated by +``parser.suite()`` from test data in +docutils/test/test_readers/test_python/test_parser or stdin. + +Usage:: + + showparse <key> <index> + + showparse < <module.py> + +Where ``<key>`` is the key to the ``totest`` dictionary, and ``<index>`` is +the index of the list ``totest[key]``. If no arguments are given, stdin is +used for input. +""" + +import sys +import types +import parser +import token +import symbol +import pprint +import test_parser + +names = token.tok_name.copy() +names.update(symbol.sym_name) + +def name_elements(ast): + if ast: + name = names[ast[0]] + ast[0] = '%s (%s)' % (name, ast[0]) + for node in ast[1:]: + if type(node) == types.ListType: + name_elements(node) + +if len(sys.argv) > 1: + key, caseno = sys.argv[1:] + print 'totest["%s"][%s][0]:\n' % (key, caseno) + input_text = test_parser.totest[key][int(caseno)][0] +else: + input_text = sys.stdin.read() +print input_text +module = parser.suite(input_text) +ast = parser.ast2list(module, line_info=1) +name_elements(ast) +pprint.pprint(ast) |