diff options
| author | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2002-12-07 03:02:18 +0000 |
|---|---|---|
| committer | goodger <goodger@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2002-12-07 03:02:18 +0000 |
| commit | e785b0053bb1ddb68b94a14c73d64321fc16adf7 (patch) | |
| tree | 43624bdcae72591a92834d63490d5b4b89b5401c | |
| parent | 11bf869ee3e2e53fdbbb925a57cc2e8f95d48d97 (diff) | |
| download | docutils-e785b0053bb1ddb68b94a14c73d64321fc16adf7.tar.gz | |
added stdin input capability
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@1001 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rwxr-xr-x | docutils/test/test_readers/test_python/showast | 16 | ||||
| -rwxr-xr-x | docutils/test/test_readers/test_python/showparse | 16 | ||||
| -rwxr-xr-x | docutils/test/test_readers/test_python/showtok | 16 |
3 files changed, 33 insertions, 15 deletions
diff --git a/docutils/test/test_readers/test_python/showast b/docutils/test/test_readers/test_python/showast index 2bb4ad3a6..e7d846307 100755 --- a/docutils/test/test_readers/test_python/showast +++ b/docutils/test/test_readers/test_python/showast @@ -3,14 +3,17 @@ """ This is a tool for exploring abstract syntax trees generated by ``compiler.parse()`` from test data in -docutils/test/test_readers/test_python/test_parser. +docutils/test/test_readers/test_python/test_parser or stdin. Usage:: showast <key> <index> + showast < <module.py> + Where ``<key>`` is the key to the ``totest`` dictionary, and ``<index>`` is -the index of the list ``totest[key]``. +the index of the list ``totest[key]``. If no arguments are given, stdin is +used for input. """ import sys @@ -41,9 +44,12 @@ def pformat(ast, indent=' ', level=0): result.extend(pformat(node, level=level+1)) return result -key, caseno = sys.argv[1:] -print 'totest["%s"][%s][0]:\n' % (key, caseno) -input_text = test_parser.totest[key][int(caseno)][0] +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 = compiler.parse(input_text) print module diff --git a/docutils/test/test_readers/test_python/showparse b/docutils/test/test_readers/test_python/showparse index 61e08ba92..8144256d6 100755 --- a/docutils/test/test_readers/test_python/showparse +++ b/docutils/test/test_readers/test_python/showparse @@ -3,14 +3,17 @@ """ 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. +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]``. +the index of the list ``totest[key]``. If no arguments are given, stdin is +used for input. """ import sys @@ -32,9 +35,12 @@ def name_elements(ast): if type(node) == types.ListType: name_elements(node) -key, caseno = sys.argv[1:] -print 'totest["%s"][%s][0]:\n' % (key, caseno) -input_text = test_parser.totest[key][int(caseno)][0] +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) diff --git a/docutils/test/test_readers/test_python/showtok b/docutils/test/test_readers/test_python/showtok index b844b6bc0..b2b750514 100755 --- a/docutils/test/test_readers/test_python/showtok +++ b/docutils/test/test_readers/test_python/showtok @@ -4,14 +4,17 @@ """ 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. +docutils/test/test_readers/test_python/test_parser or stdin. Usage:: showtok <key> <index> + showtok < <module.py> + Where ``<key>`` is the key to the ``totest`` dictionary, and ``<index>`` is -the index of the list ``totest[key]``. +the index of the list ``totest[key]``. If no arguments are given, stdin is +used for input. """ import sys @@ -25,9 +28,12 @@ def name_tokens(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] +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 tokens = list(tokenize.generate_tokens(iter(input_text.splitlines(1)).next)) name_tokens(tokens) |
