1993-07-28 09:05:47 +00:00
|
|
|
#ifndef Py_PARSER_H
|
|
|
|
|
#define Py_PARSER_H
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
1991-02-19 12:39:46 +00:00
|
|
|
|
1990-10-14 12:07:46 +00:00
|
|
|
/* Parser interface */
|
|
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900,60902-60906,60908,60911-60917,60919-60920,60922,60926,60929-60931,60933-60935,60937,60939-60941,60943-60954,60959-60961,60963-60969,60971-60976 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60965 | eric.smith | 2008-02-22 18:43:17 +0100 (Fri, 22 Feb 2008) | 1 line
Tests for bin() builtin. These need to get merged into py3k, which has no tests for bin.
........
r60968 | raymond.hettinger | 2008-02-22 20:50:06 +0100 (Fri, 22 Feb 2008) | 1 line
Document itertools.product().
........
r60969 | raymond.hettinger | 2008-02-23 03:20:41 +0100 (Sat, 23 Feb 2008) | 9 lines
Improve the implementation of itertools.product()
* Fix-up issues pointed-out by Neal Norwitz.
* Add extensive comments.
* The lz->result variable is now a tuple instead of a list.
* Use fast macro getitem/setitem calls so most code is in-line.
* Re-use the result tuple if available (modify in-place instead of copy).
........
r60972 | raymond.hettinger | 2008-02-23 05:03:50 +0100 (Sat, 23 Feb 2008) | 1 line
Add more comments
........
r60973 | raymond.hettinger | 2008-02-23 11:04:15 +0100 (Sat, 23 Feb 2008) | 1 line
Add recipe using itertools.product().
........
r60974 | facundo.batista | 2008-02-23 13:01:13 +0100 (Sat, 23 Feb 2008) | 6 lines
Issue 1881. Increased the stack limit from 500 to 1500. Also added
a test for this (and because of this test you'll see in stderr a
message that parser.c sends before raising MemoryError).
Thanks Ralf Schmitt.
........
r60975 | facundo.batista | 2008-02-23 13:27:17 +0100 (Sat, 23 Feb 2008) | 4 lines
Issue 1776581. Minor corrections to smtplib, and two small tests.
Thanks Alan McIntyre.
........
r60976 | facundo.batista | 2008-02-23 13:46:10 +0100 (Sat, 23 Feb 2008) | 5 lines
Issue 1781. Now ConfigParser.add_section does not let you add a
DEFAULT section any more, because it duplicated sections with
the rest of the machinery. Thanks Tim Lesher and Manuel Kaufmann.
........
2008-02-23 13:18:03 +00:00
|
|
|
#define MAXSTACK 1500
|
1990-10-14 12:07:46 +00:00
|
|
|
|
1994-08-30 08:27:36 +00:00
|
|
|
typedef struct {
|
2017-11-28 17:56:10 +02:00
|
|
|
int s_state; /* State in current DFA */
|
|
|
|
|
dfa *s_dfa; /* Current DFA */
|
|
|
|
|
struct _node *s_parent; /* Where to add next node */
|
1990-10-14 12:07:46 +00:00
|
|
|
} stackentry;
|
|
|
|
|
|
1994-08-30 08:27:36 +00:00
|
|
|
typedef struct {
|
2017-11-28 17:56:10 +02:00
|
|
|
stackentry *s_top; /* Top entry */
|
|
|
|
|
stackentry s_base[MAXSTACK];/* Array of stack entries */
|
|
|
|
|
/* NB The stack grows down */
|
1990-10-14 12:07:46 +00:00
|
|
|
} stack;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2017-11-28 17:56:10 +02:00
|
|
|
stack p_stack; /* Stack of parser states */
|
|
|
|
|
grammar *p_grammar; /* Grammar to use */
|
|
|
|
|
node *p_tree; /* Top of parse tree */
|
2006-02-28 19:02:24 +00:00
|
|
|
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
|
2017-11-28 17:56:10 +02:00
|
|
|
unsigned long p_flags; /* see co_flags in Include/code.h */
|
2002-03-22 23:53:36 +00:00
|
|
|
#endif
|
1990-10-14 12:07:46 +00:00
|
|
|
} parser_state;
|
|
|
|
|
|
2000-07-09 03:09:57 +00:00
|
|
|
parser_state *PyParser_New(grammar *g, int start);
|
|
|
|
|
void PyParser_Delete(parser_state *ps);
|
bpo-33416: Add end positions to Python AST (GH-11605)
The majority of this PR is tediously passing `end_lineno` and `end_col_offset` everywhere. Here are non-trivial points:
* It is not possible to reconstruct end positions in AST "on the fly", some information is lost after an AST node is constructed, so we need two more attributes for every AST node `end_lineno` and `end_col_offset`.
* I add end position information to both CST and AST. Although it may be technically possible to avoid adding end positions to CST, the code becomes more cumbersome and less efficient.
* Since the end position is not known for non-leaf CST nodes while the next token is added, this requires a bit of extra care (see `_PyNode_FinalizeEndPos`). Unless I made some mistake, the algorithm should be linear.
* For statements, I "trim" the end position of suites to not include the terminal newlines and dedent (this seems to be what people would expect), for example in
```python
class C:
pass
pass
```
the end line and end column for the class definition is (2, 8).
* For `end_col_offset` I use the common Python convention for indexing, for example for `pass` the `end_col_offset` is 4 (not 3), so that `[0:4]` gives one the source code that corresponds to the node.
* I added a helper function `ast.get_source_segment()`, to get source text segment corresponding to a given AST node. It is also useful for testing.
An (inevitable) downside of this PR is that AST now takes almost 25% more memory. I think however it is probably justified by the benefits.
2019-01-22 11:18:22 +00:00
|
|
|
int PyParser_AddToken(parser_state *ps, int type, char *str,
|
|
|
|
|
int lineno, int col_offset,
|
|
|
|
|
int end_lineno, int end_col_offset,
|
2000-07-11 17:53:00 +00:00
|
|
|
int *expected_ret);
|
2000-07-09 03:09:57 +00:00
|
|
|
void PyGrammar_AddAccelerators(grammar *g);
|
1993-07-28 09:05:47 +00:00
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif /* !Py_PARSER_H */
|