Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
30704ea0
Commit
30704ea0
authored
Jul 23, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove "ast" aliases from the parser module.
parent
4dcce175
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
32 deletions
+17
-32
Doc/library/parser.rst
Doc/library/parser.rst
+10
-15
Misc/NEWS
Misc/NEWS
+2
-0
Modules/parsermodule.c
Modules/parsermodule.c
+5
-17
No files found.
Doc/library/parser.rst
View file @
30704ea0
...
...
@@ -30,11 +30,6 @@ the code forming the application. It is also faster.
Syntax Tree (AST) generation and compilation stage, using the :mod:`ast`
module.
The :mod:`parser` module exports the names documented here also with "st"
replaced by "ast"; this is a legacy from the time when there was no other
AST and has nothing to do with the AST found in Python 2.5. This is also the
reason for the functions' keyword arguments being called *ast*, not *st*.
There are a few things to note about this module which are important to making
use of the data structures created. This is not a tutorial on editing the parse
trees for Python code, but some examples of using the :mod:`parser` module are
...
...
@@ -170,9 +165,9 @@ executable code objects. Parse trees may be extracted with or without line
numbering information.
.. function:: st2list(
a
st[, line_info])
.. function:: st2list(st[, line_info])
This function accepts an ST object from the caller in *
a
st* and returns a
This function accepts an ST object from the caller in *st* and returns a
Python list representing the equivalent parse tree. The resulting list
representation can be used for inspection or the creation of a new parse tree in
list form. This function does not fail so long as memory is available to build
...
...
@@ -188,9 +183,9 @@ numbering information.
This information is omitted if the flag is false or omitted.
.. function:: st2tuple(
a
st[, line_info])
.. function:: st2tuple(st[, line_info])
This function accepts an ST object from the caller in *
a
st* and returns a
This function accepts an ST object from the caller in *st* and returns a
Python tuple representing the equivalent parse tree. Other than returning a
tuple instead of a list, this function is identical to :func:`st2list`.
...
...
@@ -199,7 +194,7 @@ numbering information.
information is omitted if the flag is false or omitted.
.. function:: compilest(
a
st[, filename='<syntax-tree>'])
.. function:: compilest(st[, filename='<syntax-tree>'])
.. index::
builtin: exec
...
...
@@ -208,7 +203,7 @@ numbering information.
The Python byte compiler can be invoked on an ST object to produce code objects
which can be used as part of a call to the built-in :func:`exec` or :func:`eval`
functions. This function provides the interface to the compiler, passing the
internal parse tree from *
a
st* to the parser, using the source file name
internal parse tree from *st* to the parser, using the source file name
specified by the *filename* parameter. The default value supplied for *filename*
indicates that the source was an ST object.
...
...
@@ -233,22 +228,22 @@ determine if an ST was created from source code via :func:`expr` or
:func:`suite` or from a parse tree via :func:`sequence2st`.
.. function:: isexpr(
a
st)
.. function:: isexpr(st)
.. index:: builtin: compile
When *
a
st* represents an ``'eval'`` form, this function returns true, otherwise
When *st* represents an ``'eval'`` form, this function returns true, otherwise
it returns false. This is useful, since code objects normally cannot be queried
for this information using existing built-in functions. Note that the code
objects created by :func:`compilest` cannot be queried like this either, and
are identical to those created by the built-in :func:`compile` function.
.. function:: issuite(
a
st)
.. function:: issuite(st)
This function mirrors :func:`isexpr` in that it reports whether an ST object
represents an ``'exec'`` form, commonly known as a "suite." It is not safe to
assume that this function is equivalent to ``not isexpr(
a
st)``, as additional
assume that this function is equivalent to ``not isexpr(st)``, as additional
syntactic fragments may be supported in the future.
...
...
Misc/NEWS
View file @
30704ea0
...
...
@@ -34,6 +34,8 @@ Core and Builtins
Library
-------
- Removed "ast" function aliases from the parser module.
- Issue #3313: Fixed a crash when a failed dlopen() call does not set
a valid dlerror() message.
...
...
Modules/parsermodule.c
View file @
30704ea0
...
...
@@ -322,7 +322,7 @@ parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw)
PyObject
*
res
=
0
;
int
ok
;
static
char
*
keywords
[]
=
{
"
a
st"
,
"line_info"
,
"col_info"
,
NULL
};
static
char
*
keywords
[]
=
{
"st"
,
"line_info"
,
"col_info"
,
NULL
};
if
(
self
==
NULL
||
PyModule_Check
(
self
))
{
ok
=
PyArg_ParseTupleAndKeywords
(
args
,
kw
,
"O!|OO:st2tuple"
,
keywords
,
...
...
@@ -366,7 +366,7 @@ parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
PyObject
*
res
=
0
;
int
ok
;
static
char
*
keywords
[]
=
{
"
a
st"
,
"line_info"
,
"col_info"
,
NULL
};
static
char
*
keywords
[]
=
{
"st"
,
"line_info"
,
"col_info"
,
NULL
};
if
(
self
==
NULL
||
PyModule_Check
(
self
))
ok
=
PyArg_ParseTupleAndKeywords
(
args
,
kw
,
"O!|OO:st2list"
,
keywords
,
...
...
@@ -408,7 +408,7 @@ parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw)
char
*
str
=
"<syntax-tree>"
;
int
ok
;
static
char
*
keywords
[]
=
{
"
a
st"
,
"filename"
,
NULL
};
static
char
*
keywords
[]
=
{
"st"
,
"filename"
,
NULL
};
if
(
self
==
NULL
||
PyModule_Check
(
self
))
ok
=
PyArg_ParseTupleAndKeywords
(
args
,
kw
,
"O!|s:compilest"
,
keywords
,
...
...
@@ -437,7 +437,7 @@ parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw)
PyObject
*
res
=
0
;
int
ok
;
static
char
*
keywords
[]
=
{
"
a
st"
,
NULL
};
static
char
*
keywords
[]
=
{
"st"
,
NULL
};
if
(
self
==
NULL
||
PyModule_Check
(
self
))
ok
=
PyArg_ParseTupleAndKeywords
(
args
,
kw
,
"O!:isexpr"
,
keywords
,
...
...
@@ -460,7 +460,7 @@ parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw)
PyObject
*
res
=
0
;
int
ok
;
static
char
*
keywords
[]
=
{
"
a
st"
,
NULL
};
static
char
*
keywords
[]
=
{
"st"
,
NULL
};
if
(
self
==
NULL
||
PyModule_Check
(
self
))
ok
=
PyArg_ParseTupleAndKeywords
(
args
,
kw
,
"O!:issuite"
,
keywords
,
...
...
@@ -3011,12 +3011,6 @@ parser__pickler(PyObject *self, PyObject *args)
* inheritance.
*/
static
PyMethodDef
parser_functions
[]
=
{
{
"ast2tuple"
,
(
PyCFunction
)
parser_st2tuple
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates a tuple-tree representation of an ST."
)},
{
"ast2list"
,
(
PyCFunction
)
parser_st2list
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates a list-tree representation of an ST."
)},
{
"compileast"
,
(
PyCFunction
)
parser_compilest
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Compiles an ST object into a code object."
)},
{
"compilest"
,
(
PyCFunction
)
parser_compilest
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Compiles an ST object into a code object."
)},
{
"expr"
,
(
PyCFunction
)
parser_expr
,
PUBLIC_METHOD_TYPE
,
...
...
@@ -3027,16 +3021,12 @@ static PyMethodDef parser_functions[] = {
PyDoc_STR
(
"Determines if an ST object was created from a suite."
)},
{
"suite"
,
(
PyCFunction
)
parser_suite
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates an ST object from a suite."
)},
{
"sequence2ast"
,
(
PyCFunction
)
parser_tuple2st
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates an ST object from a tree representation."
)},
{
"sequence2st"
,
(
PyCFunction
)
parser_tuple2st
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates an ST object from a tree representation."
)},
{
"st2tuple"
,
(
PyCFunction
)
parser_st2tuple
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates a tuple-tree representation of an ST."
)},
{
"st2list"
,
(
PyCFunction
)
parser_st2list
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates a list-tree representation of an ST."
)},
{
"tuple2ast"
,
(
PyCFunction
)
parser_tuple2st
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates an ST object from a tree representation."
)},
{
"tuple2st"
,
(
PyCFunction
)
parser_tuple2st
,
PUBLIC_METHOD_TYPE
,
PyDoc_STR
(
"Creates an ST object from a tree representation."
)},
...
...
@@ -3089,8 +3079,6 @@ PyInit_parser(void)
if
(
PyModule_AddObject
(
module
,
"ParserError"
,
parser_error
)
!=
0
)
return
NULL
;
Py_INCREF
(
&
PyST_Type
);
PyModule_AddObject
(
module
,
"ASTType"
,
(
PyObject
*
)
&
PyST_Type
);
Py_INCREF
(
&
PyST_Type
);
PyModule_AddObject
(
module
,
"STType"
,
(
PyObject
*
)
&
PyST_Type
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment