diff options
| author | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2002-12-06 02:40:30 +0000 |
|---|---|---|
| committer | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2002-12-06 02:40:30 +0000 |
| commit | 7555fcc90eb26460984e126de87d58626065caa4 (patch) | |
| tree | 9ead2f2437c4696d6d04d5272216cfc4d81c6bef /docutils/test/test_readers/test_python | |
| parent | 84fba8b69a6f4172c858fdc7ea669fcd56f646db (diff) | |
| download | docutils-7555fcc90eb26460984e126de87d58626065caa4.tar.gz | |
a tool for exploring abstract syntax trees generated by ``tokenize.generate_tokens()``
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@999 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/test/test_readers/test_python')
| -rwxr-xr-x | docutils/test/test_readers/test_python/showtok | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/docutils/test/test_readers/test_python/showtok b/docutils/test/test_readers/test_python/showtok new file mode 100755 index 000000000..b844b6bc0 --- /dev/null +++ b/docutils/test/test_readers/test_python/showtok @@ -0,0 +1,34 @@ +#! /usr/bin/env python + + +""" +This is a tool for exploring token lists generated by +``tokenize.generate_tokens()`` from test data in +docutils/test/test_readers/test_python/test_parser. + +Usage:: + + showtok <key> <index> + +Where ``<key>`` is the key to the ``totest`` dictionary, and ``<index>`` is +the index of the list ``totest[key]``. +""" + +import sys +import tokenize +import pprint +from token import tok_name +import test_parser + +def name_tokens(tokens): + for i in range(len(tokens)): + tup = tokens[i] + tokens[i] = (tok_name[tup[0]],) + tup + +key, caseno = sys.argv[1:] +print 'totest["%s"][%s][0]:\n' % (key, caseno) +input_text = test_parser.totest[key][int(caseno)][0] +print input_text +tokens = list(tokenize.generate_tokens(iter(input_text.splitlines(1)).next)) +name_tokens(tokens) +pprint.pprint(tokens) |
