diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-09-09 20:36:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-09 20:36:13 (GMT) |
commit | 832e8640086ac4fa547c055a72929879cc5a963a (patch) | |
tree | a53bf8e8b0b8982eb1c1fbe6b858a426f3284c24 /Doc/library/ast.rst | |
parent | b9f65f01fd761da7799f36d29b54518399d3458e (diff) | |
download | cpython-832e8640086ac4fa547c055a72929879cc5a963a.zip cpython-832e8640086ac4fa547c055a72929879cc5a963a.tar.gz cpython-832e8640086ac4fa547c055a72929879cc5a963a.tar.bz2 |
bpo-38049: Add command-line interface for the ast module. (GH-15724)
Diffstat (limited to 'Doc/library/ast.rst')
-rw-r--r-- | Doc/library/ast.rst | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index cb8e7ec..b468f42 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -340,6 +340,42 @@ and classes for traversing abstract syntax trees: Added the *indent* option. +.. _ast-cli: + +Command-Line Usage +------------------ + +.. versionadded:: 3.9 + +The :mod:`ast` module can be executed as a script from the command line. +It is as simple as: + +.. code-block:: sh + + python -m ast [-m <mode>] [-a] [infile] + +The following options are accepted: + +.. program:: ast + +.. cmdoption:: -h, --help + + Show the help message and exit. + +.. cmdoption:: -m <mode> + --mode <mode> + + Specify what kind of code must be compiled, like the *mode* argument + in :func:`parse`. + +.. cmdoption:: -a, --include-attributes + + Include attributes such as line numbers and column offsets. + +If :file:`infile` is specified its contents are parsed to AST and dumped +to stdout. Otherwise, the content is read from stdin. + + .. seealso:: `Green Tree Snakes <https://greentreesnakes.readthedocs.io/>`_, an external documentation resource, has good |