Mercurial > cpython-lru_cache-weakref
annotate Modules/parsermodule.c @ 87680:02d186e3af09 2.7
Fixed JSON tests on wide build when ran from *.pyc files (issue #11489).
| author | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| date | Sun, 01 Dec 2013 17:30:55 +0200 |
| parents | 8c2635afbfe1 |
| children |
| rev | line source |
|---|---|
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1 /* parsermodule.c |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2 * |
| 4084 | 3 * Copyright 1995-1996 by Fred L. Drake, Jr. and Virginia Polytechnic |
| 4 * Institute and State University, Blacksburg, Virginia, USA. | |
| 5 * Portions copyright 1991-1995 by Stichting Mathematisch Centrum, | |
| 6 * Amsterdam, The Netherlands. Copying is permitted under the terms | |
| 7 * associated with the main Python distribution, with the additional | |
| 8 * restriction that this additional notice be included and maintained | |
| 9 * on all distributed copies. | |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
10 * |
| 4084 | 11 * This module serves to replace the original parser module written |
| 12 * by Guido. The functionality is not matched precisely, but the | |
| 13 * original may be implemented on top of this. This is desirable | |
| 14 * since the source of the text to be parsed is now divorced from | |
| 15 * this interface. | |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
16 * |
| 4084 | 17 * Unlike the prior interface, the ability to give a parse tree |
| 18 * produced by Python code as a tuple to the compiler is enabled by | |
| 19 * this module. See the documentation for more details. | |
| 8196 | 20 * |
| 21 * I've added some annotations that help with the lint code-checking | |
| 22 * program, but they're not complete by a long shot. The real errors | |
| 23 * that lint detects are gone, but there are still warnings with | |
| 24 * Py_[X]DECREF() and Py_[X]INCREF() macros. The lint annotations | |
| 25 * look like "NOTE(...)". | |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
26 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
27 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
28 #include "Python.h" /* general Python API */ |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
29 #include "Python-ast.h" /* mod_ty */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
30 #include "graminit.h" /* symbols defined in the grammar */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
31 #include "node.h" /* internal parser structure */ |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
32 #include "errcode.h" /* error codes for PyNode_*() */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
33 #include "token.h" /* token definitions */ |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
34 #include "grammar.h" |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
35 #include "parsetok.h" |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
36 /* ISTERMINAL() / ISNONTERMINAL() */ |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
37 #include "compile.h" |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
38 #undef Yield |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
39 #include "ast.h" |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
40 #include "pyarena.h" |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
41 |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
42 extern grammar _PyParser_Grammar; /* From graminit.c */ |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
43 |
| 8196 | 44 #ifdef lint |
| 45 #include <note.h> | |
| 46 #else | |
| 47 #define NOTE(x) | |
| 48 #endif | |
| 49 | |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
50 /* String constants used to initialize module attributes. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
51 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
52 */ |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23538
diff
changeset
|
53 static char parser_copyright_string[] = |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23538
diff
changeset
|
54 "Copyright 1995-1996 by Virginia Polytechnic Institute & State\n\ |
|
4099
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
55 University, Blacksburg, Virginia, USA, and Fred L. Drake, Jr., Reston,\n\ |
|
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
56 Virginia, USA. Portions copyright 1991-1995 by Stichting Mathematisch\n\ |
|
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
57 Centrum, Amsterdam, The Netherlands."; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
58 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
59 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23538
diff
changeset
|
60 PyDoc_STRVAR(parser_doc_string, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23538
diff
changeset
|
61 "This is an interface to Python's internal parser."); |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23538
diff
changeset
|
62 |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23538
diff
changeset
|
63 static char parser_version_string[] = "0.5"; |
| 4084 | 64 |
| 65 | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
66 typedef PyObject* (*SeqMaker) (Py_ssize_t length); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
67 typedef int (*SeqInserter) (PyObject* sequence, |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
68 Py_ssize_t index, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
69 PyObject* element); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
70 |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
71 /* The function below is copyrighted by Stichting Mathematisch Centrum. The |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
72 * original copyright statement is included below, and continues to apply |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
73 * in full to the function immediately following. All other material is |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
74 * original, copyrighted by Fred L. Drake, Jr. and Virginia Polytechnic |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
75 * Institute and State University. Changes were made to comply with the |
|
4099
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
76 * new naming conventions. Added arguments to provide support for creating |
|
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
77 * lists as well as tuples, and optionally including the line numbers. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
78 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
79 |
|
1406
474823e5f7dc
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
81 static PyObject* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
82 node2tuple(node *n, /* node to convert */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
83 SeqMaker mkseq, /* create sequence */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
84 SeqInserter addelem, /* func. to add elem. in seq. */ |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
85 int lineno, /* include line numbers? */ |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
86 int col_offset) /* include column offsets? */ |
| 4084 | 87 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
88 if (n == NULL) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
89 Py_INCREF(Py_None); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
90 return (Py_None); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
91 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
92 if (ISNONTERMINAL(TYPE(n))) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
93 int i; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
94 PyObject *v; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
95 PyObject *w; |
| 8196 | 96 |
|
26979
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24796
diff
changeset
|
97 v = mkseq(1 + NCH(n) + (TYPE(n) == encoding_decl)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
98 if (v == NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
99 return (v); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
100 w = PyInt_FromLong(TYPE(n)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
101 if (w == NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
102 Py_DECREF(v); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
103 return ((PyObject*) NULL); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
104 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
105 (void) addelem(v, 0, w); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
106 for (i = 0; i < NCH(n); i++) { |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
107 w = node2tuple(CHILD(n, i), mkseq, addelem, lineno, col_offset); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
108 if (w == NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
109 Py_DECREF(v); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
110 return ((PyObject*) NULL); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
111 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
112 (void) addelem(v, i+1, w); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
113 } |
|
29952
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
114 |
|
26979
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24796
diff
changeset
|
115 if (TYPE(n) == encoding_decl) |
|
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24796
diff
changeset
|
116 (void) addelem(v, i+1, PyString_FromString(STR(n))); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
117 return (v); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
118 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
119 else if (ISTERMINAL(TYPE(n))) { |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
120 PyObject *result = mkseq(2 + lineno + col_offset); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
121 if (result != NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
122 (void) addelem(result, 0, PyInt_FromLong(TYPE(n))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
123 (void) addelem(result, 1, PyString_FromString(STR(n))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
124 if (lineno == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
125 (void) addelem(result, 2, PyInt_FromLong(n->n_lineno)); |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
126 if (col_offset == 1) |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
127 (void) addelem(result, 3, PyInt_FromLong(n->n_col_offset)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
128 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
129 return (result); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
130 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
131 else { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
132 PyErr_SetString(PyExc_SystemError, |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
133 "unrecognized parse tree node type"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
134 return ((PyObject*) NULL); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
135 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
136 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
137 /* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
138 * End of material copyrighted by Stichting Mathematisch Centrum. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
139 */ |
|
1406
474823e5f7dc
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
141 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
142 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
143 /* There are two types of intermediate objects we're interested in: |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
144 * 'eval' and 'exec' types. These constants can be used in the st_type |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
145 * field of the object type to identify which any given object represents. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
146 * These should probably go in an external header to allow other extensions |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
147 * to use them, but then, we really should be using C++ too. ;-) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
148 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
149 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
150 #define PyST_EXPR 1 |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
151 #define PyST_SUITE 2 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
152 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
153 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
154 /* These are the internal objects and definitions required to implement the |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
155 * ST type. Most of the internal names are more reminiscent of the 'old' |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
156 * naming style, but the code uses the new naming convention. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
157 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
158 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
159 static PyObject* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
160 parser_error = 0; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
161 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
162 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
163 typedef struct { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
164 PyObject_HEAD /* standard object header */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
165 node* st_node; /* the node* returned by the parser */ |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
166 int st_type; /* EXPR or SUITE ? */ |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
167 PyCompilerFlags st_flags; /* Parser and compiler flags */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
168 } PyST_Object; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
169 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
170 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
171 static void parser_free(PyST_Object *st); |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
172 static PyObject* parser_sizeof(PyST_Object *, void *); |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
173 static int parser_compare(PyST_Object *left, PyST_Object *right); |
| 36680 | 174 static PyObject *parser_getattr(PyObject *self, char *name); |
|
78399
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
175 static PyObject* parser_compilest(PyST_Object *, PyObject *, PyObject *); |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
176 static PyObject* parser_isexpr(PyST_Object *, PyObject *, PyObject *); |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
177 static PyObject* parser_issuite(PyST_Object *, PyObject *, PyObject *); |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
178 static PyObject* parser_st2list(PyST_Object *, PyObject *, PyObject *); |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
179 static PyObject* parser_st2tuple(PyST_Object *, PyObject *, PyObject *); |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
180 |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
181 #define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
182 |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
183 static PyMethodDef |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
184 parser_methods[] = { |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
185 {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
186 PyDoc_STR("Compile this ST object into a code object.")}, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
187 {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
188 PyDoc_STR("Determines if this ST object was created from an expression.")}, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
189 {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
190 PyDoc_STR("Determines if this ST object was created from a suite.")}, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
191 {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
192 PyDoc_STR("Creates a list-tree representation of this ST.")}, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
193 {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
194 PyDoc_STR("Creates a tuple-tree representation of this ST.")}, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
195 {"__sizeof__", (PyCFunction)parser_sizeof, METH_NOARGS, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
196 PyDoc_STR("Returns size in memory, in bytes.")}, |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
197 {NULL, NULL, 0, NULL} |
|
c5bf5a82a3f2
#15512: Declarations reorganization
Jesus Cea <jcea@jcea.es>
parents:
78390
diff
changeset
|
198 }; |
| 8196 | 199 |
| 200 static | |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
201 PyTypeObject PyST_Type = { |
|
42333
6620a510e9a9
PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents:
39635
diff
changeset
|
202 PyVarObject_HEAD_INIT(NULL, 0) |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
21237
diff
changeset
|
203 "parser.st", /* tp_name */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
204 (int) sizeof(PyST_Object), /* tp_basicsize */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
205 0, /* tp_itemsize */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
206 (destructor)parser_free, /* tp_dealloc */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
207 0, /* tp_print */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
208 parser_getattr, /* tp_getattr */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
209 0, /* tp_setattr */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
210 (cmpfunc)parser_compare, /* tp_compare */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
211 0, /* tp_repr */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
212 0, /* tp_as_number */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
213 0, /* tp_as_sequence */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
214 0, /* tp_as_mapping */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
215 0, /* tp_hash */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
216 0, /* tp_call */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
217 0, /* tp_str */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
218 0, /* tp_getattro */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
219 0, /* tp_setattro */ |
|
5613
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
220 |
|
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
221 /* Functions to access object as input/output buffer */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
222 0, /* tp_as_buffer */ |
|
5613
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
223 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
224 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
5613
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
225 |
|
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
226 /* __doc__ */ |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
227 "Intermediate representation of a Python parse tree.", |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
228 0, /* tp_traverse */ |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
229 0, /* tp_clear */ |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
230 0, /* tp_richcompare */ |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
231 0, /* tp_weaklistoffset */ |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
232 0, /* tp_iter */ |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
233 0, /* tp_iternext */ |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
234 parser_methods, /* tp_methods */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
235 }; /* PyST_Type */ |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
236 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
237 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
238 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
239 parser_compare_nodes(node *left, node *right) |
| 4084 | 240 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
241 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
242 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
243 if (TYPE(left) < TYPE(right)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
244 return (-1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
245 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
246 if (TYPE(right) < TYPE(left)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
247 return (1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
248 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
249 if (ISTERMINAL(TYPE(left))) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
250 return (strcmp(STR(left), STR(right))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
251 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
252 if (NCH(left) < NCH(right)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
253 return (-1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
254 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
255 if (NCH(right) < NCH(left)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
256 return (1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
257 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
258 for (j = 0; j < NCH(left); ++j) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
259 int v = parser_compare_nodes(CHILD(left, j), CHILD(right, j)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
260 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
261 if (v != 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
262 return (v); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
263 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
264 return (0); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
265 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
266 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
267 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
268 /* int parser_compare(PyST_Object* left, PyST_Object* right) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
269 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
270 * Comparison function used by the Python operators ==, !=, <, >, <=, >= |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
271 * This really just wraps a call to parser_compare_nodes() with some easy |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
272 * checks and protection code. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
273 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
274 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
275 static int |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
276 parser_compare(PyST_Object *left, PyST_Object *right) |
| 4084 | 277 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
278 if (left == right) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
279 return (0); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
280 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
281 if ((left == 0) || (right == 0)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
282 return (-1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
283 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
284 return (parser_compare_nodes(left->st_node, right->st_node)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
285 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
286 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
287 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
288 /* parser_newstobject(node* st) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
289 * |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
290 * Allocates a new Python object representing an ST. This is simply the |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
291 * 'wrapper' object that holds a node* and allows it to be passed around in |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
292 * Python code. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
293 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
294 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
295 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
296 parser_newstobject(node *st, int type) |
| 4084 | 297 { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
298 PyST_Object* o = PyObject_New(PyST_Object, &PyST_Type); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
299 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
300 if (o != 0) { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
301 o->st_node = st; |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
302 o->st_type = type; |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
303 o->st_flags.cf_flags = 0; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
304 } |
| 8196 | 305 else { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
306 PyNode_Free(st); |
| 8196 | 307 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
308 return ((PyObject*)o); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
309 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
310 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
311 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
312 /* void parser_free(PyST_Object* st) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
313 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
314 * This is called by a del statement that reduces the reference count to 0. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
315 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
316 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
317 static void |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
318 parser_free(PyST_Object *st) |
| 4084 | 319 { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
320 PyNode_Free(st->st_node); |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
321 PyObject_Del(st); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
322 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
323 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
324 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
325 /* parser_st2tuple(PyObject* self, PyObject* args, PyObject* kw) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
326 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
327 * This provides conversion from a node* to a tuple object that can be |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
328 * returned to the Python-level caller. The ST object is not modified. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
329 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
330 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
331 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
332 parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 333 { |
| 334 PyObject *line_option = 0; | |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
335 PyObject *col_option = 0; |
| 4084 | 336 PyObject *res = 0; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
337 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
338 |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
339 static char *keywords[] = {"ast", "line_info", "col_info", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
340 |
| 8196 | 341 if (self == NULL) { |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
342 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2tuple", keywords, |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
343 &PyST_Type, &self, &line_option, |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
344 &col_option); |
| 8196 | 345 } |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
346 else |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
347 ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:totuple", &keywords[1], |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
348 &line_option, &col_option); |
| 8196 | 349 if (ok != 0) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
350 int lineno = 0; |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
351 int col_offset = 0; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
352 if (line_option != NULL) { |
|
78603
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
353 lineno = PyObject_IsTrue(line_option); |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
354 if (lineno < 0) |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
355 return NULL; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
356 } |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
357 if (col_option != NULL) { |
|
78603
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
358 col_offset = PyObject_IsTrue(col_option); |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
359 if (col_offset < 0) |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
360 return NULL; |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
361 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
362 /* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
363 * Convert ST into a tuple representation. Use Guido's function, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
364 * since it's known to work already. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
365 */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
366 res = node2tuple(((PyST_Object*)self)->st_node, |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
367 PyTuple_New, PyTuple_SetItem, lineno, col_offset); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
368 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
369 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
370 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
371 |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
372 static PyObject* |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
373 parser_ast2tuple(PyST_Object *self, PyObject *args, PyObject *kw) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
374 { |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
375 if (PyErr_WarnPy3k("ast2tuple is removed in 3.x; use st2tuple", 1) < 0) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
376 return NULL; |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
377 return parser_st2tuple(self, args, kw); |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
378 } |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
379 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
380 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
381 /* parser_st2list(PyObject* self, PyObject* args, PyObject* kw) |
| 4084 | 382 * |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
383 * This provides conversion from a node* to a list object that can be |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
384 * returned to the Python-level caller. The ST object is not modified. |
| 4084 | 385 * |
| 386 */ | |
| 387 static PyObject* | |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
388 parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 389 { |
| 390 PyObject *line_option = 0; | |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
391 PyObject *col_option = 0; |
| 4084 | 392 PyObject *res = 0; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
393 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
394 |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
395 static char *keywords[] = {"ast", "line_info", "col_info", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
396 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
397 if (self == NULL) |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
398 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|OO:st2list", keywords, |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
399 &PyST_Type, &self, &line_option, |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
400 &col_option); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
401 else |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
402 ok = PyArg_ParseTupleAndKeywords(args, kw, "|OO:tolist", &keywords[1], |
|
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
403 &line_option, &col_option); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
404 if (ok) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
405 int lineno = 0; |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
406 int col_offset = 0; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
407 if (line_option != 0) { |
|
78603
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
408 lineno = PyObject_IsTrue(line_option); |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
409 if (lineno < 0) |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
410 return NULL; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
411 } |
|
78603
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
412 if (col_option != 0) { |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
413 col_offset = PyObject_IsTrue(col_option); |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
414 if (col_offset < 0) |
|
ba1c48f8b571
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Antoine Pitrou <solipsis@pitrou.net>
parents:
78399
diff
changeset
|
415 return NULL; |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
416 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
417 /* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
418 * Convert ST into a tuple representation. Use Guido's function, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
419 * since it's known to work already. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
420 */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
421 res = node2tuple(self->st_node, |
|
39635
f8a90d1825ce
Expose column offset information in parse trees.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
38314
diff
changeset
|
422 PyList_New, PyList_SetItem, lineno, col_offset); |
| 4084 | 423 } |
| 424 return (res); | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
425 } |
| 4084 | 426 |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
427 static PyObject* |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
428 parser_ast2list(PyST_Object *self, PyObject *args, PyObject *kw) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
429 { |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
430 if (PyErr_WarnPy3k("ast2list is removed in 3.x; use st2list", 1) < 0) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
431 return NULL; |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
432 return parser_st2list(self, args, kw); |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
433 } |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
434 |
| 4084 | 435 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
436 /* parser_compilest(PyObject* self, PyObject* args) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
437 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
438 * This function creates code objects from the parse tree represented by |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
439 * the passed-in data object. An optional file name is passed in as well. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
440 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
441 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
442 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
443 parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 444 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
445 PyObject* res = 0; |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
446 PyArena* arena; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
447 mod_ty mod; |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
448 char* str = "<syntax-tree>"; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
449 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
450 |
| 36680 | 451 static char *keywords[] = {"ast", "filename", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
452 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
453 if (self == NULL) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
454 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|s:compilest", keywords, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
455 &PyST_Type, &self, &str); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
456 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
457 ok = PyArg_ParseTupleAndKeywords(args, kw, "|s:compile", &keywords[1], |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
458 &str); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
459 |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
460 if (ok) { |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
461 arena = PyArena_New(); |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
462 if (arena) { |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
463 mod = PyAST_FromNode(self->st_node, &(self->st_flags), str, arena); |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
464 if (mod) { |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
465 res = (PyObject *)PyAST_Compile(mod, str, &(self->st_flags), arena); |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
466 } |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
467 PyArena_Free(arena); |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
468 } |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
469 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
470 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
471 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
472 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
473 |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
474 static PyObject* |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
475 parser_compileast(PyST_Object *self, PyObject *args, PyObject *kw) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
476 { |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
477 if (PyErr_WarnPy3k("compileast is removed in 3.x; use compilest", 1) < 0) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
478 return NULL; |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
479 return parser_compilest(self, args, kw); |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
480 } |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
481 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
482 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
483 /* PyObject* parser_isexpr(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
484 * PyObject* parser_issuite(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
485 * |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
486 * Checks the passed-in ST object to determine if it is an expression or |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
487 * a statement suite, respectively. The return is a Python truth value. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
488 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
489 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
490 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
491 parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 492 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
493 PyObject* res = 0; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
494 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
495 |
| 36680 | 496 static char *keywords[] = {"ast", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
497 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
498 if (self == NULL) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
499 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:isexpr", keywords, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
500 &PyST_Type, &self); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
501 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
502 ok = PyArg_ParseTupleAndKeywords(args, kw, ":isexpr", &keywords[1]); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
503 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
504 if (ok) { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
505 /* Check to see if the ST represents an expression or not. */ |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
506 res = (self->st_type == PyST_EXPR) ? Py_True : Py_False; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
507 Py_INCREF(res); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
508 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
509 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
510 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
511 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
512 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
513 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
514 parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 515 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
516 PyObject* res = 0; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
517 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
518 |
| 36680 | 519 static char *keywords[] = {"ast", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
520 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
521 if (self == NULL) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
522 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!:issuite", keywords, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
523 &PyST_Type, &self); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
524 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
525 ok = PyArg_ParseTupleAndKeywords(args, kw, ":issuite", &keywords[1]); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
526 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
527 if (ok) { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
528 /* Check to see if the ST represents an expression or not. */ |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
529 res = (self->st_type == PyST_EXPR) ? Py_False : Py_True; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
530 Py_INCREF(res); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
531 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
532 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
533 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
534 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
535 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
536 static PyObject* |
| 36680 | 537 parser_getattr(PyObject *self, char *name) |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
538 { |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
539 return (Py_FindMethod(parser_methods, self, name)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
540 } |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
541 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
542 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
543 /* err_string(char* message) |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
544 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
545 * Sets the error string for an exception of type ParserError. |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
546 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
547 */ |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
548 static void |
| 13503 | 549 err_string(char *message) |
| 4084 | 550 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
551 PyErr_SetString(parser_error, message); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
552 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
553 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
554 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
555 /* PyObject* parser_do_parse(PyObject* args, int type) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
556 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
557 * Internal function to actually execute the parse and return the result if |
|
26979
784e7fdf8c52
SF patch [ 597919 ] compiler package and SET_LINENO
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24796
diff
changeset
|
558 * successful or set an exception if not. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
559 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
560 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
561 static PyObject* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
562 parser_do_parse(PyObject *args, PyObject *kw, char *argspec, int type) |
| 4084 | 563 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
564 char* string = 0; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
565 PyObject* res = 0; |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
566 int flags = 0; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
567 perrdetail err; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
568 |
| 36680 | 569 static char *keywords[] = {"source", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
570 |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
571 if (PyArg_ParseTupleAndKeywords(args, kw, argspec, keywords, &string)) { |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
572 node* n = PyParser_ParseStringFlagsFilenameEx(string, NULL, |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
573 &_PyParser_Grammar, |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
574 (type == PyST_EXPR) |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
575 ? eval_input : file_input, |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
576 &err, &flags); |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
577 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
578 if (n) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
579 res = parser_newstobject(n, type); |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
580 if (res) |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
581 ((PyST_Object *)res)->st_flags.cf_flags = flags & PyCF_MASK; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
582 } |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
583 else |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48056
diff
changeset
|
584 PyParser_SetError(&err); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
585 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
586 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
587 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
588 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
589 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
590 /* PyObject* parser_expr(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
591 * PyObject* parser_suite(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
592 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
593 * External interfaces to the parser itself. Which is called determines if |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
594 * the parser attempts to recognize an expression ('eval' form) or statement |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
595 * suite ('exec' form). The real work is done by parser_do_parse() above. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
596 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
597 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
598 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
599 parser_expr(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 600 { |
| 8196 | 601 NOTE(ARGUNUSED(self)) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
602 return (parser_do_parse(args, kw, "s:expr", PyST_EXPR)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
603 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
604 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
605 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
606 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
607 parser_suite(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 608 { |
| 8196 | 609 NOTE(ARGUNUSED(self)) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
610 return (parser_do_parse(args, kw, "s:suite", PyST_SUITE)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
611 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
612 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
613 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
614 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
615 /* This is the messy part of the code. Conversion from a tuple to an ST |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
616 * object requires that the input tuple be valid without having to rely on |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
617 * catching an exception from the compiler. This is done to allow the |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
618 * compiler itself to remain fast, since most of its input will come from |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
619 * the parser directly, and therefore be known to be syntactically correct. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
620 * This validation is done to ensure that we don't core dump the compile |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
621 * phase, returning an exception instead. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
622 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
623 * Two aspects can be broken out in this code: creating a node tree from |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
624 * the tuple passed in, and verifying that it is indeed valid. It may be |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
625 * advantageous to expand the number of ST types to include funcdefs and |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
626 * lambdadefs to take advantage of the optimizer, recognizing those STs |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
627 * here. They are not necessary, and not quite as useful in a raw form. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
628 * For now, let's get expressions and suites working reliably. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
629 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
630 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
631 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
632 static node* build_node_tree(PyObject *tuple); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
633 static int validate_expr_tree(node *tree); |
|
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
634 static int validate_file_input(node *tree); |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
635 static int validate_encoding_decl(node *tree); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
636 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
637 /* PyObject* parser_tuple2st(PyObject* self, PyObject* args) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
638 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
639 * This is the public function, called from the Python code. It receives a |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
640 * single tuple object from the caller, and creates an ST object if the |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
641 * tuple can be validated. It does this by checking the first code of the |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
642 * tuple, and, if acceptable, builds the internal representation. If this |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
643 * step succeeds, the internal representation is validated as fully as |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
644 * possible with the various validate_*() routines defined below. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
645 * |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
646 * This function must be changed if support is to be added for PyST_FRAGMENT |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
647 * ST objects. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
648 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
649 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
650 static PyObject* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
651 parser_tuple2st(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 652 { |
| 8196 | 653 NOTE(ARGUNUSED(self)) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
654 PyObject *st = 0; |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
655 PyObject *tuple; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
656 node *tree; |
| 4084 | 657 |
| 36680 | 658 static char *keywords[] = {"sequence", NULL}; |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
659 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
660 if (!PyArg_ParseTupleAndKeywords(args, kw, "O:sequence2st", keywords, |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
661 &tuple)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
662 return (0); |
| 4084 | 663 if (!PySequence_Check(tuple)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
664 PyErr_SetString(PyExc_ValueError, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
665 "sequence2st() requires a single sequence argument"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
666 return (0); |
| 4084 | 667 } |
| 668 /* | |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
669 * Convert the tree to the internal form before checking it. |
| 4084 | 670 */ |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
671 tree = build_node_tree(tuple); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
672 if (tree != 0) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
673 int start_sym = TYPE(tree); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
674 if (start_sym == eval_input) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
675 /* Might be an eval form. */ |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
676 if (validate_expr_tree(tree)) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
677 st = parser_newstobject(tree, PyST_EXPR); |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
678 else |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
679 PyNode_Free(tree); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
680 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
681 else if (start_sym == file_input) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
682 /* This looks like an exec form so far. */ |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
683 if (validate_file_input(tree)) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
684 st = parser_newstobject(tree, PyST_SUITE); |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
685 else |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
686 PyNode_Free(tree); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
687 } |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
688 else if (start_sym == encoding_decl) { |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
689 /* This looks like an encoding_decl so far. */ |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
690 if (validate_encoding_decl(tree)) |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
691 st = parser_newstobject(tree, PyST_SUITE); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
692 else |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
693 PyNode_Free(tree); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
694 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
695 else { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
696 /* This is a fragment, at best. */ |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
697 PyNode_Free(tree); |
| 15318 | 698 err_string("parse tree does not use a valid start symbol"); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
699 } |
| 4084 | 700 } |
|
80931
8c2635afbfe1
Issue #16714: use 'raise' exceptions, don't 'throw'.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
78603
diff
changeset
|
701 /* Make sure we raise an exception on all errors. We should never |
| 4084 | 702 * get this, but we'd do well to be sure something is done. |
| 703 */ | |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
704 if (st == NULL && !PyErr_Occurred()) |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
705 err_string("unspecified ST error occurred"); |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
706 |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
707 return st; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
708 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
709 |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
710 static PyObject* |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
711 parser_tuple2ast(PyST_Object *self, PyObject *args, PyObject *kw) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
712 { |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
713 if (PyErr_WarnPy3k("tuple2ast is removed in 3.x; use tuple2st", 1) < 0) |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
714 return NULL; |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
715 return parser_tuple2st(self, args, kw); |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
716 } |
|
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
717 |
|
78390
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
718 static PyObject * |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
719 parser_sizeof(PyST_Object *st, void *unused) |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
720 { |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
721 Py_ssize_t res; |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
722 |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
723 res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node); |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
724 return PyLong_FromSsize_t(res); |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
725 } |
|
aceb975c4832
Closes #15512: Correct __sizeof__ support for parser
Jesus Cea <jcea@jcea.es>
parents:
68503
diff
changeset
|
726 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
727 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
728 /* node* build_node_children() |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
729 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
730 * Iterate across the children of the current non-terminal node and build |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
731 * their structures. If successful, return the root of this portion of |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
732 * the tree, otherwise, 0. Any required exception will be specified already, |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
733 * and no memory will have been deallocated. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
734 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
735 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
736 static node* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
737 build_node_children(PyObject *tuple, node *root, int *line_num) |
| 4084 | 738 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
739 Py_ssize_t len = PyObject_Size(tuple); |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
740 Py_ssize_t i; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
741 int err; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
742 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
743 for (i = 1; i < len; ++i) { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
744 /* elem must always be a sequence, however simple */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
745 PyObject* elem = PySequence_GetItem(tuple, i); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
746 int ok = elem != NULL; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
747 long type = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
748 char *strn = 0; |
| 4084 | 749 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
750 if (ok) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
751 ok = PySequence_Check(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
752 if (ok) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
753 PyObject *temp = PySequence_GetItem(elem, 0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
754 if (temp == NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
755 ok = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
756 else { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
757 ok = PyInt_Check(temp); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
758 if (ok) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
759 type = PyInt_AS_LONG(temp); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
760 Py_DECREF(temp); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
761 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
762 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
763 if (!ok) { |
|
37092
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
764 PyObject *err = Py_BuildValue("os", elem, |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
765 "Illegal node construct."); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
766 PyErr_SetObject(parser_error, err); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
767 Py_XDECREF(err); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
768 Py_XDECREF(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
769 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
770 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
771 if (ISTERMINAL(type)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
772 Py_ssize_t len = PyObject_Size(elem); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
773 PyObject *temp; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
774 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
775 if ((len != 2) && (len != 3)) { |
| 15318 | 776 err_string("terminal nodes must have 2 or 3 entries"); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
777 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
778 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
779 temp = PySequence_GetItem(elem, 1); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
780 if (temp == NULL) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
781 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
782 if (!PyString_Check(temp)) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
783 PyErr_Format(parser_error, |
| 15318 | 784 "second item in terminal node must be a string," |
| 785 " found %s", | |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
786 Py_TYPE(temp)->tp_name); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12487
diff
changeset
|
787 Py_DECREF(temp); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
788 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
789 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
790 if (len == 3) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
791 PyObject *o = PySequence_GetItem(elem, 2); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
792 if (o != NULL) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
793 if (PyInt_Check(o)) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
794 *line_num = PyInt_AS_LONG(o); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
795 else { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
796 PyErr_Format(parser_error, |
| 15318 | 797 "third item in terminal node must be an" |
| 798 " integer, found %s", | |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
799 Py_TYPE(temp)->tp_name); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
800 Py_DECREF(o); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
801 Py_DECREF(temp); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
802 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
803 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
804 Py_DECREF(o); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
805 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
806 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
807 len = PyString_GET_SIZE(temp) + 1; |
| 37229 | 808 strn = (char *)PyObject_MALLOC(len); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
809 if (strn != NULL) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
810 (void) memcpy(strn, PyString_AS_STRING(temp), len); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
811 Py_DECREF(temp); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
812 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
813 else if (!ISNONTERMINAL(type)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
814 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
815 * It has to be one or the other; this is an error. |
|
80931
8c2635afbfe1
Issue #16714: use 'raise' exceptions, don't 'throw'.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
78603
diff
changeset
|
816 * Raise an exception. |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
817 */ |
|
37092
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
818 PyObject *err = Py_BuildValue("os", elem, "unknown node type."); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
819 PyErr_SetObject(parser_error, err); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
820 Py_XDECREF(err); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
821 Py_XDECREF(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
822 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
823 } |
|
36786
57322cb2ca11
Patch #1440601: Add col_offset attribute to AST nodes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36712
diff
changeset
|
824 err = PyNode_AddChild(root, type, strn, *line_num, 0); |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
825 if (err == E_NOMEM) { |
| 37229 | 826 PyObject_FREE(strn); |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
827 return (node *) PyErr_NoMemory(); |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
828 } |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
829 if (err == E_OVERFLOW) { |
| 37229 | 830 PyObject_FREE(strn); |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
831 PyErr_SetString(PyExc_ValueError, |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
832 "unsupported number of child nodes"); |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
833 return NULL; |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
834 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
835 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
836 if (ISNONTERMINAL(type)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
837 node* new_child = CHILD(root, i - 1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
838 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
839 if (new_child != build_node_children(elem, new_child, line_num)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
840 Py_XDECREF(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
841 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
842 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
843 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
844 else if (type == NEWLINE) { /* It's true: we increment the */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
845 ++(*line_num); /* line number *after* the newline! */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
846 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
847 Py_XDECREF(elem); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
848 } |
| 37229 | 849 return root; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
850 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
851 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
852 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
853 static node* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
854 build_node_tree(PyObject *tuple) |
| 4084 | 855 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
856 node* res = 0; |
| 4084 | 857 PyObject *temp = PySequence_GetItem(tuple, 0); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
858 long num = -1; |
| 4084 | 859 |
| 860 if (temp != NULL) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
861 num = PyInt_AsLong(temp); |
| 4084 | 862 Py_XDECREF(temp); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
863 if (ISTERMINAL(num)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
864 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
865 * The tuple is simple, but it doesn't start with a start symbol. |
|
80931
8c2635afbfe1
Issue #16714: use 'raise' exceptions, don't 'throw'.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
78603
diff
changeset
|
866 * Raise an exception now and be done with it. |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
867 */ |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
868 tuple = Py_BuildValue("os", tuple, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
869 "Illegal syntax-tree; cannot start with terminal symbol."); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
870 PyErr_SetObject(parser_error, tuple); |
|
37092
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
871 Py_XDECREF(tuple); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
872 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
873 else if (ISNONTERMINAL(num)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
874 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
875 * Not efficient, but that can be handled later. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
876 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
877 int line_num = 0; |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
878 PyObject *encoding = NULL; |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
879 |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
880 if (num == encoding_decl) { |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
881 encoding = PySequence_GetItem(tuple, 2); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
882 /* tuple isn't borrowed anymore here, need to DECREF */ |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
883 tuple = PySequence_GetSlice(tuple, 0, 2); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
884 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
885 res = PyNode_New(num); |
|
21237
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
886 if (res != NULL) { |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
887 if (res != build_node_children(tuple, res, &line_num)) { |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
888 PyNode_Free(res); |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
889 res = NULL; |
|
42d0819546d6
Fix memory leak in the parser module: There were two leaks in
Fred Drake <fdrake@acm.org>
parents:
20432
diff
changeset
|
890 } |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
891 if (res && encoding) { |
|
36518
9f3f87e920a6
Use Py_ssize_t for counts and sizes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
892 Py_ssize_t len; |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
893 len = PyString_GET_SIZE(encoding) + 1; |
| 37229 | 894 res->n_str = (char *)PyObject_MALLOC(len); |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
895 if (res->n_str != NULL) |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
896 (void) memcpy(res->n_str, PyString_AS_STRING(encoding), len); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
897 Py_DECREF(encoding); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
898 Py_DECREF(tuple); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
899 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
900 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
901 } |
|
37092
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
902 else { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
903 /* The tuple is illegal -- if the number is neither TERMINAL nor |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
904 * NONTERMINAL, we can't use it. Not sure the implementation |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
905 * allows this condition, but the API doesn't preclude it. |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
906 */ |
|
37092
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
907 PyObject *err = Py_BuildValue("os", tuple, |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
908 "Illegal component tuple."); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
909 PyErr_SetObject(parser_error, err); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
910 Py_XDECREF(err); |
|
8d42f661fec8
SF #1445431, fix some leaks in error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36786
diff
changeset
|
911 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
912 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
913 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
914 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
915 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
916 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
917 /* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
918 * Validation routines used within the validation section: |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
919 */ |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23832
diff
changeset
|
920 static int validate_terminal(node *terminal, int type, char *string); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
921 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
922 #define validate_ampersand(ch) validate_terminal(ch, AMPER, "&") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
923 #define validate_circumflex(ch) validate_terminal(ch, CIRCUMFLEX, "^") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
924 #define validate_colon(ch) validate_terminal(ch, COLON, ":") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
925 #define validate_comma(ch) validate_terminal(ch, COMMA, ",") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
926 #define validate_dedent(ch) validate_terminal(ch, DEDENT, "") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
927 #define validate_equal(ch) validate_terminal(ch, EQUAL, "=") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
928 #define validate_indent(ch) validate_terminal(ch, INDENT, (char*)NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
929 #define validate_lparen(ch) validate_terminal(ch, LPAR, "(") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
930 #define validate_newline(ch) validate_terminal(ch, NEWLINE, (char*)NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
931 #define validate_rparen(ch) validate_terminal(ch, RPAR, ")") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
932 #define validate_semi(ch) validate_terminal(ch, SEMI, ";") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
933 #define validate_star(ch) validate_terminal(ch, STAR, "*") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
934 #define validate_vbar(ch) validate_terminal(ch, VBAR, "|") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
935 #define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
936 #define validate_dot(ch) validate_terminal(ch, DOT, ".") |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
937 #define validate_at(ch) validate_terminal(ch, AT, "@") |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
938 #define validate_name(ch, str) validate_terminal(ch, NAME, str) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
939 |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
940 #define VALIDATER(n) static int validate_##n(node *tree) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
941 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
942 VALIDATER(node); VALIDATER(small_stmt); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
943 VALIDATER(class); VALIDATER(node); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
944 VALIDATER(parameters); VALIDATER(suite); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
945 VALIDATER(testlist); VALIDATER(varargslist); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
946 VALIDATER(fpdef); VALIDATER(fplist); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
947 VALIDATER(stmt); VALIDATER(simple_stmt); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
948 VALIDATER(expr_stmt); VALIDATER(power); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
949 VALIDATER(print_stmt); VALIDATER(del_stmt); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
950 VALIDATER(return_stmt); VALIDATER(list_iter); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
951 VALIDATER(raise_stmt); VALIDATER(import_stmt); |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
952 VALIDATER(import_name); VALIDATER(import_from); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
953 VALIDATER(global_stmt); VALIDATER(list_if); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
954 VALIDATER(assert_stmt); VALIDATER(list_for); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
955 VALIDATER(exec_stmt); VALIDATER(compound_stmt); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
956 VALIDATER(while); VALIDATER(for); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
957 VALIDATER(try); VALIDATER(except_clause); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
958 VALIDATER(test); VALIDATER(and_test); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
959 VALIDATER(not_test); VALIDATER(comparison); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
960 VALIDATER(comp_op); VALIDATER(expr); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
961 VALIDATER(xor_expr); VALIDATER(and_expr); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
962 VALIDATER(shift_expr); VALIDATER(arith_expr); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
963 VALIDATER(term); VALIDATER(factor); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
964 VALIDATER(atom); VALIDATER(lambdef); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
965 VALIDATER(trailer); VALIDATER(subscript); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
966 VALIDATER(subscriptlist); VALIDATER(sliceop); |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
967 VALIDATER(exprlist); VALIDATER(dictorsetmaker); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
968 VALIDATER(arglist); VALIDATER(argument); |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
969 VALIDATER(listmaker); VALIDATER(yield_stmt); |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
970 VALIDATER(testlist1); VALIDATER(comp_for); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
971 VALIDATER(comp_iter); VALIDATER(comp_if); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
972 VALIDATER(testlist_comp); VALIDATER(yield_expr); |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
973 VALIDATER(yield_or_testlist); VALIDATER(or_test); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
974 VALIDATER(old_test); VALIDATER(old_lambdef); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
975 |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
976 #undef VALIDATER |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
977 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
978 #define is_even(n) (((n) & 1) == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
979 #define is_odd(n) (((n) & 1) == 1) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
980 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
981 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
982 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
983 validate_ntype(node *n, int t) |
| 4084 | 984 { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
985 if (TYPE(n) != t) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
986 PyErr_Format(parser_error, "Expected node type %d, got %d.", |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
987 t, TYPE(n)); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
988 return 0; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
989 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
990 return 1; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
991 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
992 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
993 |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
994 /* Verifies that the number of child nodes is exactly 'num', raising |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
995 * an exception if it isn't. The exception message does not indicate |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
996 * the exact number of nodes, allowing this to be used to raise the |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
997 * "right" exception when the wrong number of nodes is present in a |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
998 * specific variant of a statement's syntax. This is commonly used |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
999 * in that fashion. |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
1000 */ |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1001 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1002 validate_numnodes(node *n, int num, const char *const name) |
| 4084 | 1003 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1004 if (NCH(n) != num) { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1005 PyErr_Format(parser_error, |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1006 "Illegal number of children for %s node.", name); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1007 return 0; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1008 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1009 return 1; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1010 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1011 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1012 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1013 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1014 validate_terminal(node *terminal, int type, char *string) |
| 4084 | 1015 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1016 int res = (validate_ntype(terminal, type) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1017 && ((string == 0) || (strcmp(string, STR(terminal)) == 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1018 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1019 if (!res && !PyErr_Occurred()) { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1020 PyErr_Format(parser_error, |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1021 "Illegal terminal: expected \"%s\"", string); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1022 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1023 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1024 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1025 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1026 |
| 4084 | 1027 /* X (',' X) [','] |
| 1028 */ | |
| 1029 static int | |
|
13667
a6c7bfdd6777
Even more ANSIfication: fix as many function pointers and declarations as
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1030 validate_repeating_list(node *tree, int ntype, int (*vfunc)(node *), |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1031 const char *const name) |
| 4084 | 1032 { |
| 1033 int nch = NCH(tree); | |
| 1034 int res = (nch && validate_ntype(tree, ntype) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1035 && vfunc(CHILD(tree, 0))); |
| 4084 | 1036 |
| 1037 if (!res && !PyErr_Occurred()) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1038 (void) validate_numnodes(tree, 1, name); |
| 4084 | 1039 else { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1040 if (is_even(nch)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1041 res = validate_comma(CHILD(tree, --nch)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1042 if (res && nch > 1) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1043 int pos = 1; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1044 for ( ; res && pos < nch; pos += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1045 res = (validate_comma(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1046 && vfunc(CHILD(tree, pos + 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1047 } |
| 4084 | 1048 } |
| 1049 return (res); | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1050 } |
| 4084 | 1051 |
| 1052 | |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1053 /* validate_class() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1054 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1055 * classdef: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1056 * 'class' NAME ['(' testlist ')'] ':' suite |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1057 */ |
| 4084 | 1058 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1059 validate_class(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1060 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1061 int nch = NCH(tree); |
|
34887
7c2780c9e51b
Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents:
33353
diff
changeset
|
1062 int res = (validate_ntype(tree, classdef) && |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1063 ((nch == 4) || (nch == 6) || (nch == 7))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1064 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1065 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1066 res = (validate_name(CHILD(tree, 0), "class") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1067 && validate_ntype(CHILD(tree, 1), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1068 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1069 && validate_suite(CHILD(tree, nch - 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1070 } |
|
34887
7c2780c9e51b
Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents:
33353
diff
changeset
|
1071 else { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1072 (void) validate_numnodes(tree, 4, "class"); |
|
34887
7c2780c9e51b
Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents:
33353
diff
changeset
|
1073 } |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1074 |
|
34887
7c2780c9e51b
Flush out support for ``class B(): pass`` syntax by adding support to the
Brett Cannon <bcannon@gmail.com>
parents:
33353
diff
changeset
|
1075 if (res) { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1076 if (nch == 7) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1077 res = ((validate_lparen(CHILD(tree, 2)) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1078 validate_testlist(CHILD(tree, 3)) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1079 validate_rparen(CHILD(tree, 4)))); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1080 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1081 else if (nch == 6) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1082 res = (validate_lparen(CHILD(tree,2)) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1083 validate_rparen(CHILD(tree,3))); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1084 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1085 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1086 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1087 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1088 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1089 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1090 /* if_stmt: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1091 * 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1092 */ |
| 4084 | 1093 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1094 validate_if(node *tree) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1095 { |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1096 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1097 int res = (validate_ntype(tree, if_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1098 && (nch >= 4) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1099 && validate_name(CHILD(tree, 0), "if") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1100 && validate_test(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1101 && validate_colon(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1102 && validate_suite(CHILD(tree, 3))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1103 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1104 if (res && ((nch % 4) == 3)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1105 /* ... 'else' ':' suite */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1106 res = (validate_name(CHILD(tree, nch - 3), "else") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1107 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1108 && validate_suite(CHILD(tree, nch - 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1109 nch -= 3; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1110 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1111 else if (!res && !PyErr_Occurred()) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1112 (void) validate_numnodes(tree, 4, "if"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1113 if ((nch % 4) != 0) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1114 /* Will catch the case for nch < 4 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1115 res = validate_numnodes(tree, 0, "if"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1116 else if (res && (nch > 4)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1117 /* ... ('elif' test ':' suite)+ ... */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1118 int j = 4; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1119 while ((j < nch) && res) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1120 res = (validate_name(CHILD(tree, j), "elif") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1121 && validate_colon(CHILD(tree, j + 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1122 && validate_test(CHILD(tree, j + 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1123 && validate_suite(CHILD(tree, j + 3))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1124 j += 4; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1125 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1126 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1127 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1128 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1129 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1130 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1131 /* parameters: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1132 * '(' [varargslist] ')' |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1133 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1134 */ |
| 4084 | 1135 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1136 validate_parameters(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1137 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1138 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1139 int res = validate_ntype(tree, parameters) && ((nch == 2) || (nch == 3)); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1140 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1141 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1142 res = (validate_lparen(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1143 && validate_rparen(CHILD(tree, nch - 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1144 if (res && (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1145 res = validate_varargslist(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1146 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1147 else { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1148 (void) validate_numnodes(tree, 2, "parameters"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1149 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1150 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1151 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1152 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1153 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1154 /* validate_suite() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1155 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1156 * suite: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1157 * simple_stmt |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1158 * | NEWLINE INDENT stmt+ DEDENT |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1159 */ |
| 4084 | 1160 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1161 validate_suite(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1162 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1163 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1164 int res = (validate_ntype(tree, suite) && ((nch == 1) || (nch >= 4))); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1165 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1166 if (res && (nch == 1)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1167 res = validate_simple_stmt(CHILD(tree, 0)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1168 else if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1169 /* NEWLINE INDENT stmt+ DEDENT */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1170 res = (validate_newline(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1171 && validate_indent(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1172 && validate_stmt(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1173 && validate_dedent(CHILD(tree, nch - 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1174 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1175 if (res && (nch > 4)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1176 int i = 3; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1177 --nch; /* forget the DEDENT */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1178 for ( ; res && (i < nch); ++i) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1179 res = validate_stmt(CHILD(tree, i)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1180 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1181 else if (nch < 4) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1182 res = validate_numnodes(tree, 4, "suite"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1183 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1184 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1185 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1186 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1187 |
| 4084 | 1188 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1189 validate_testlist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1190 { |
| 4084 | 1191 return (validate_repeating_list(tree, testlist, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1192 validate_test, "testlist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1193 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1194 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1195 |
|
20432
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1196 static int |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1197 validate_testlist1(node *tree) |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1198 { |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1199 return (validate_repeating_list(tree, testlist1, |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1200 validate_test, "testlist1")); |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1201 } |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1202 |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1203 |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
1204 static int |
|
20432
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1205 validate_testlist_safe(node *tree) |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1206 { |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1207 return (validate_repeating_list(tree, testlist_safe, |
|
36673
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
1208 validate_old_test, "testlist_safe")); |
|
20432
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1209 } |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1210 |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1211 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1212 /* '*' NAME [',' '**' NAME] | '**' NAME |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1213 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1214 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1215 validate_varargslist_trailer(node *tree, int start) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1216 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1217 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1218 int res = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1219 int sym; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1220 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1221 if (nch <= start) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1222 err_string("expected variable argument trailer for varargslist"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1223 return 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1224 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1225 sym = TYPE(CHILD(tree, start)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1226 if (sym == STAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1227 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1228 * ('*' NAME [',' '**' NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1229 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1230 if (nch-start == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1231 res = validate_name(CHILD(tree, start+1), NULL); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1232 else if (nch-start == 5) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1233 res = (validate_name(CHILD(tree, start+1), NULL) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1234 && validate_comma(CHILD(tree, start+2)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1235 && validate_doublestar(CHILD(tree, start+3)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1236 && validate_name(CHILD(tree, start+4), NULL)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1237 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1238 else if (sym == DOUBLESTAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1239 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1240 * '**' NAME |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1241 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1242 if (nch-start == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1243 res = validate_name(CHILD(tree, start+1), NULL); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1244 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1245 if (!res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1246 err_string("illegal variable argument trailer for varargslist"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1247 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1248 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1249 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1250 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1251 /* validate_varargslist() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1252 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1253 * varargslist: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1254 * (fpdef ['=' test] ',')* |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1255 * ('*' NAME [',' '**' NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1256 * | '**' NAME) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1257 * | fpdef ['=' test] (',' fpdef ['=' test])* [','] |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1258 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1259 */ |
| 4084 | 1260 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1261 validate_varargslist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1262 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1263 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1264 int res = validate_ntype(tree, varargslist) && (nch != 0); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1265 int sym; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1266 |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1267 if (!res) |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1268 return 0; |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1269 if (nch < 1) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1270 err_string("varargslist missing child nodes"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1271 return 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1272 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1273 sym = TYPE(CHILD(tree, 0)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1274 if (sym == STAR || sym == DOUBLESTAR) |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1275 /* whole thing matches: |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1276 * '*' NAME [',' '**' NAME] | '**' NAME |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1277 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1278 res = validate_varargslist_trailer(tree, 0); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1279 else if (sym == fpdef) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1280 int i = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1281 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1282 sym = TYPE(CHILD(tree, nch-1)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1283 if (sym == NAME) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1284 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1285 * (fpdef ['=' test] ',')+ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1286 * ('*' NAME [',' '**' NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1287 * | '**' NAME) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1288 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1289 /* skip over (fpdef ['=' test] ',')+ */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1290 while (res && (i+2 <= nch)) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1291 res = validate_fpdef(CHILD(tree, i)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1292 ++i; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1293 if (res && TYPE(CHILD(tree, i)) == EQUAL && (i+2 <= nch)) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1294 res = (validate_equal(CHILD(tree, i)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1295 && validate_test(CHILD(tree, i+1))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1296 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1297 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1298 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1299 if (res && i < nch) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1300 res = validate_comma(CHILD(tree, i)); |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1301 ++i; |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1302 if (res && i < nch |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1303 && (TYPE(CHILD(tree, i)) == DOUBLESTAR |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1304 || TYPE(CHILD(tree, i)) == STAR)) |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1305 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1306 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1307 } |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1308 /* ... '*' NAME [',' '**' NAME] | '**' NAME |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1309 * i --^^^ |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1310 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1311 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1312 res = validate_varargslist_trailer(tree, i); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1313 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1314 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1315 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1316 * fpdef ['=' test] (',' fpdef ['=' test])* [','] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1317 */ |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1318 /* strip trailing comma node */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1319 if (sym == COMMA) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1320 res = validate_comma(CHILD(tree, nch-1)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1321 if (!res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1322 return 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1323 --nch; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1324 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1325 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1326 * fpdef ['=' test] (',' fpdef ['=' test])* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1327 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1328 res = validate_fpdef(CHILD(tree, 0)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1329 ++i; |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1330 if (res && (i+2 <= nch) && TYPE(CHILD(tree, i)) == EQUAL) { |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1331 res = (validate_equal(CHILD(tree, i)) |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1332 && validate_test(CHILD(tree, i+1))); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1333 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1334 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1335 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1336 * ... (',' fpdef ['=' test])* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1337 * i ---^^^ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1338 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1339 while (res && (nch - i) >= 2) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1340 res = (validate_comma(CHILD(tree, i)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1341 && validate_fpdef(CHILD(tree, i+1))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1342 i += 2; |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1343 if (res && (nch - i) >= 2 && TYPE(CHILD(tree, i)) == EQUAL) { |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1344 res = (validate_equal(CHILD(tree, i)) |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1345 && validate_test(CHILD(tree, i+1))); |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1346 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1347 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1348 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1349 if (res && nch - i != 0) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1350 res = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1351 err_string("illegal formation for varargslist"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1352 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1353 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1354 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1355 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1356 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1357 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1358 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1359 /* list_iter: list_for | list_if |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1360 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1361 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1362 validate_list_iter(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1363 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1364 int res = (validate_ntype(tree, list_iter) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1365 && validate_numnodes(tree, 1, "list_iter")); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1366 if (res && TYPE(CHILD(tree, 0)) == list_for) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1367 res = validate_list_for(CHILD(tree, 0)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1368 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1369 res = validate_list_if(CHILD(tree, 0)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1370 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1371 return res; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1372 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1373 |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1374 /* comp_iter: comp_for | comp_if |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1375 */ |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1376 static int |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1377 validate_comp_iter(node *tree) |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1378 { |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1379 int res = (validate_ntype(tree, comp_iter) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1380 && validate_numnodes(tree, 1, "comp_iter")); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1381 if (res && TYPE(CHILD(tree, 0)) == comp_for) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1382 res = validate_comp_for(CHILD(tree, 0)); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1383 else |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1384 res = validate_comp_if(CHILD(tree, 0)); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1385 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1386 return res; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1387 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1388 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1389 /* list_for: 'for' exprlist 'in' testlist [list_iter] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1390 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1391 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1392 validate_list_for(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1393 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1394 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1395 int res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1396 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1397 if (nch == 5) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1398 res = validate_list_iter(CHILD(tree, 4)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1399 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1400 res = validate_numnodes(tree, 4, "list_for"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1401 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1402 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1403 res = (validate_name(CHILD(tree, 0), "for") |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1404 && validate_exprlist(CHILD(tree, 1)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1405 && validate_name(CHILD(tree, 2), "in") |
|
20432
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1406 && validate_testlist_safe(CHILD(tree, 3))); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1407 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1408 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1409 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1410 |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1411 /* comp_for: 'for' exprlist 'in' test [comp_iter] |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1412 */ |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1413 static int |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1414 validate_comp_for(node *tree) |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1415 { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1416 int nch = NCH(tree); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1417 int res; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1418 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1419 if (nch == 5) |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1420 res = validate_comp_iter(CHILD(tree, 4)); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1421 else |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1422 res = validate_numnodes(tree, 4, "comp_for"); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1423 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1424 if (res) |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1425 res = (validate_name(CHILD(tree, 0), "for") |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1426 && validate_exprlist(CHILD(tree, 1)) |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1427 && validate_name(CHILD(tree, 2), "in") |
|
36673
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
1428 && validate_or_test(CHILD(tree, 3))); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1429 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1430 return res; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1431 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1432 |
| 37622 | 1433 /* list_if: 'if' old_test [list_iter] |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1434 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1435 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1436 validate_list_if(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1437 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1438 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1439 int res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1440 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1441 if (nch == 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1442 res = validate_list_iter(CHILD(tree, 2)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1443 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1444 res = validate_numnodes(tree, 2, "list_if"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1445 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1446 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1447 res = (validate_name(CHILD(tree, 0), "if") |
| 37622 | 1448 && validate_old_test(CHILD(tree, 1))); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1449 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1450 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1451 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1452 |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1453 /* comp_if: 'if' old_test [comp_iter] |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1454 */ |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1455 static int |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1456 validate_comp_if(node *tree) |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1457 { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1458 int nch = NCH(tree); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1459 int res; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1460 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1461 if (nch == 3) |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1462 res = validate_comp_iter(CHILD(tree, 2)); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1463 else |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
1464 res = validate_numnodes(tree, 2, "comp_if"); |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1465 |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1466 if (res) |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1467 res = (validate_name(CHILD(tree, 0), "if") |
| 37622 | 1468 && validate_old_test(CHILD(tree, 1))); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1469 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1470 return res; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
1471 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1472 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1473 /* validate_fpdef() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1474 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1475 * fpdef: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1476 * NAME |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1477 * | '(' fplist ')' |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1478 */ |
| 4084 | 1479 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1480 validate_fpdef(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1481 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1482 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1483 int res = validate_ntype(tree, fpdef); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1484 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1485 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1486 if (nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1487 res = validate_ntype(CHILD(tree, 0), NAME); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1488 else if (nch == 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1489 res = (validate_lparen(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1490 && validate_fplist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1491 && validate_rparen(CHILD(tree, 2))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1492 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1493 res = validate_numnodes(tree, 1, "fpdef"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1494 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1495 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1496 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1497 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1498 |
| 4084 | 1499 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1500 validate_fplist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1501 { |
| 4084 | 1502 return (validate_repeating_list(tree, fplist, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1503 validate_fpdef, "fplist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1504 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1505 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1506 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1507 /* simple_stmt | compound_stmt |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1508 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1509 */ |
| 4084 | 1510 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1511 validate_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1512 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1513 int res = (validate_ntype(tree, stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1514 && validate_numnodes(tree, 1, "stmt")); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1515 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1516 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1517 tree = CHILD(tree, 0); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1518 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1519 if (TYPE(tree) == simple_stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1520 res = validate_simple_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1521 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1522 res = validate_compound_stmt(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1523 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1524 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1525 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1526 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1527 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1528 /* small_stmt (';' small_stmt)* [';'] NEWLINE |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1529 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1530 */ |
| 4084 | 1531 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1532 validate_simple_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1533 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1534 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1535 int res = (validate_ntype(tree, simple_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1536 && (nch >= 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1537 && validate_small_stmt(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1538 && validate_newline(CHILD(tree, nch - 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1539 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1540 if (nch < 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1541 res = validate_numnodes(tree, 2, "simple_stmt"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1542 --nch; /* forget the NEWLINE */ |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1543 if (res && is_even(nch)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1544 res = validate_semi(CHILD(tree, --nch)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1545 if (res && (nch > 2)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1546 int i; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1547 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1548 for (i = 1; res && (i < nch); i += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1549 res = (validate_semi(CHILD(tree, i)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1550 && validate_small_stmt(CHILD(tree, i + 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1551 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1552 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1553 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1554 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1555 |
| 4084 | 1556 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1557 validate_small_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1558 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1559 int nch = NCH(tree); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1560 int res = validate_numnodes(tree, 1, "small_stmt"); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1561 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1562 if (res) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1563 int ntype = TYPE(CHILD(tree, 0)); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1564 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1565 if ( (ntype == expr_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1566 || (ntype == print_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1567 || (ntype == del_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1568 || (ntype == pass_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1569 || (ntype == flow_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1570 || (ntype == import_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1571 || (ntype == global_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1572 || (ntype == assert_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1573 || (ntype == exec_stmt)) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1574 res = validate_node(CHILD(tree, 0)); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1575 else { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1576 res = 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1577 err_string("illegal small_stmt child type"); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1578 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1579 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1580 else if (nch == 1) { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1581 res = 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1582 PyErr_Format(parser_error, |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1583 "Unrecognized child node of small_stmt: %d.", |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1584 TYPE(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1585 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1586 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1587 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1588 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1589 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1590 /* compound_stmt: |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
1591 * if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1592 */ |
| 4084 | 1593 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1594 validate_compound_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1595 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1596 int res = (validate_ntype(tree, compound_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1597 && validate_numnodes(tree, 1, "compound_stmt")); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1598 int ntype; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1599 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1600 if (!res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1601 return (0); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1602 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1603 tree = CHILD(tree, 0); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1604 ntype = TYPE(tree); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1605 if ( (ntype == if_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1606 || (ntype == while_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1607 || (ntype == for_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1608 || (ntype == try_stmt) |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
1609 || (ntype == with_stmt) |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1610 || (ntype == funcdef) |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
1611 || (ntype == classdef) |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
1612 || (ntype == decorated)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1613 res = validate_node(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1614 else { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1615 res = 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1616 PyErr_Format(parser_error, |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1617 "Illegal compound statement type: %d.", TYPE(tree)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1618 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1619 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1620 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1621 |
| 4084 | 1622 static int |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1623 validate_yield_or_testlist(node *tree) |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1624 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1625 if (TYPE(tree) == yield_expr) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1626 return validate_yield_expr(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1627 else |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1628 return validate_testlist(tree); |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1629 } |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1630 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1631 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1632 validate_expr_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1633 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1634 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1635 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1636 int res = (validate_ntype(tree, expr_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1637 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1638 && validate_testlist(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1639 |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1640 if (res && nch == 3 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1641 && TYPE(CHILD(tree, 1)) == augassign) { |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1642 res = validate_numnodes(CHILD(tree, 1), 1, "augassign") |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1643 && validate_yield_or_testlist(CHILD(tree, 2)); |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1644 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1645 if (res) { |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1646 char *s = STR(CHILD(CHILD(tree, 1), 0)); |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1647 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1648 res = (strcmp(s, "+=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1649 || strcmp(s, "-=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1650 || strcmp(s, "*=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1651 || strcmp(s, "/=") == 0 |
|
27517
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
26979
diff
changeset
|
1652 || strcmp(s, "//=") == 0 |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1653 || strcmp(s, "%=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1654 || strcmp(s, "&=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1655 || strcmp(s, "|=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1656 || strcmp(s, "^=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1657 || strcmp(s, "<<=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1658 || strcmp(s, ">>=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1659 || strcmp(s, "**=") == 0); |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1660 if (!res) |
|
68503
ee5350f1d0c2
#11515: fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
68256
diff
changeset
|
1661 err_string("illegal augmented assignment operator"); |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1662 } |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1663 } |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1664 else { |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1665 for (j = 1; res && (j < nch); j += 2) |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1666 res = validate_equal(CHILD(tree, j)) |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1667 && validate_yield_or_testlist(CHILD(tree, j + 1)); |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1668 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1669 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1670 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1671 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1672 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1673 /* print_stmt: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1674 * |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1675 * 'print' ( [ test (',' test)* [','] ] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1676 * | '>>' test [ (',' test)+ [','] ] ) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1677 */ |
| 4084 | 1678 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1679 validate_print_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1680 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1681 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1682 int res = (validate_ntype(tree, print_stmt) |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1683 && (nch > 0) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1684 && validate_name(CHILD(tree, 0), "print")); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1685 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1686 if (res && nch > 1) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1687 int sym = TYPE(CHILD(tree, 1)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1688 int i = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1689 int allow_trailing_comma = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1690 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1691 if (sym == test) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1692 res = validate_test(CHILD(tree, i++)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1693 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1694 if (nch < 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1695 res = validate_numnodes(tree, 3, "print_stmt"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1696 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1697 res = (validate_ntype(CHILD(tree, i), RIGHTSHIFT) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1698 && validate_test(CHILD(tree, i+1))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1699 i += 2; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1700 allow_trailing_comma = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1701 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1702 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1703 if (res) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1704 /* ... (',' test)* [','] */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1705 while (res && i+2 <= nch) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1706 res = (validate_comma(CHILD(tree, i)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1707 && validate_test(CHILD(tree, i+1))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1708 allow_trailing_comma = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1709 i += 2; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1710 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1711 if (res && !allow_trailing_comma) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1712 res = validate_numnodes(tree, i, "print_stmt"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1713 else if (res && i < nch) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1714 res = validate_comma(CHILD(tree, i)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1715 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1716 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1717 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1718 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1719 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1720 |
| 4084 | 1721 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1722 validate_del_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1723 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1724 return (validate_numnodes(tree, 2, "del_stmt") |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1725 && validate_name(CHILD(tree, 0), "del") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1726 && validate_exprlist(CHILD(tree, 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1727 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1728 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1729 |
| 4084 | 1730 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1731 validate_return_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1732 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1733 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1734 int res = (validate_ntype(tree, return_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1735 && ((nch == 1) || (nch == 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1736 && validate_name(CHILD(tree, 0), "return")); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1737 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1738 if (res && (nch == 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1739 res = validate_testlist(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1740 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1741 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1742 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1743 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1744 |
| 4084 | 1745 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1746 validate_raise_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1747 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1748 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1749 int res = (validate_ntype(tree, raise_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1750 && ((nch == 1) || (nch == 2) || (nch == 4) || (nch == 6))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1751 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1752 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1753 res = validate_name(CHILD(tree, 0), "raise"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1754 if (res && (nch >= 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1755 res = validate_test(CHILD(tree, 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1756 if (res && nch > 2) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1757 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1758 && validate_test(CHILD(tree, 3))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1759 if (res && (nch > 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1760 res = (validate_comma(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1761 && validate_test(CHILD(tree, 5))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1762 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1763 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1764 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1765 (void) validate_numnodes(tree, 2, "raise"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1766 if (res && (nch == 4)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1767 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1768 && validate_test(CHILD(tree, 3))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1769 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1770 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1771 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1772 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1773 |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1774 /* yield_expr: 'yield' [testlist] |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1775 */ |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1776 static int |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1777 validate_yield_expr(node *tree) |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1778 { |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1779 int nch = NCH(tree); |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1780 int res = (validate_ntype(tree, yield_expr) |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1781 && ((nch == 1) || (nch == 2)) |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1782 && validate_name(CHILD(tree, 0), "yield")); |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1783 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1784 if (res && (nch == 2)) |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1785 res = validate_testlist(CHILD(tree, 1)); |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1786 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1787 return (res); |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1788 } |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1789 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1790 |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1791 /* yield_stmt: yield_expr |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1792 */ |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1793 static int |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1794 validate_yield_stmt(node *tree) |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1795 { |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1796 return (validate_ntype(tree, yield_stmt) |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1797 && validate_numnodes(tree, 1, "yield_stmt") |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
1798 && validate_yield_expr(CHILD(tree, 0))); |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1799 } |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1800 |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1801 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1802 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1803 validate_import_as_name(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1804 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1805 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1806 int ok = validate_ntype(tree, import_as_name); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1807 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1808 if (ok) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1809 if (nch == 1) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1810 ok = validate_name(CHILD(tree, 0), NULL); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1811 else if (nch == 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1812 ok = (validate_name(CHILD(tree, 0), NULL) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1813 && validate_name(CHILD(tree, 1), "as") |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1814 && validate_name(CHILD(tree, 2), NULL)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1815 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1816 ok = validate_numnodes(tree, 3, "import_as_name"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1817 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1818 return ok; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1819 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1820 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1821 |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1822 /* dotted_name: NAME ("." NAME)* |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1823 */ |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1824 static int |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1825 validate_dotted_name(node *tree) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1826 { |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1827 int nch = NCH(tree); |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1828 int res = (validate_ntype(tree, dotted_name) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1829 && is_odd(nch) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1830 && validate_name(CHILD(tree, 0), NULL)); |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1831 int i; |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1832 |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1833 for (i = 1; res && (i < nch); i += 2) { |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1834 res = (validate_dot(CHILD(tree, i)) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1835 && validate_name(CHILD(tree, i+1), NULL)); |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1836 } |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1837 return res; |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1838 } |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1839 |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1840 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1841 /* dotted_as_name: dotted_name [NAME NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1842 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1843 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1844 validate_dotted_as_name(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1845 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1846 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1847 int res = validate_ntype(tree, dotted_as_name); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1848 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1849 if (res) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1850 if (nch == 1) |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1851 res = validate_dotted_name(CHILD(tree, 0)); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1852 else if (nch == 3) |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1853 res = (validate_dotted_name(CHILD(tree, 0)) |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1854 && validate_name(CHILD(tree, 1), "as") |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1855 && validate_name(CHILD(tree, 2), NULL)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1856 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1857 res = 0; |
| 15318 | 1858 err_string("illegal number of children for dotted_as_name"); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1859 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1860 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1861 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1862 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1863 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1864 |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1865 /* dotted_as_name (',' dotted_as_name)* */ |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1866 static int |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1867 validate_dotted_as_names(node *tree) |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1868 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1869 int nch = NCH(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1870 int res = is_odd(nch) && validate_dotted_as_name(CHILD(tree, 0)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1871 int i; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1872 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1873 for (i = 1; res && (i < nch); i += 2) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1874 res = (validate_comma(CHILD(tree, i)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1875 && validate_dotted_as_name(CHILD(tree, i + 1))); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1876 return (res); |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1877 } |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1878 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1879 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1880 /* import_as_name (',' import_as_name)* [','] */ |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1881 static int |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1882 validate_import_as_names(node *tree) |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1883 { |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1884 int nch = NCH(tree); |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1885 int res = validate_import_as_name(CHILD(tree, 0)); |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1886 int i; |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1887 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1888 for (i = 1; res && (i + 1 < nch); i += 2) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1889 res = (validate_comma(CHILD(tree, i)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1890 && validate_import_as_name(CHILD(tree, i + 1))); |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1891 return (res); |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1892 } |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1893 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1894 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1895 /* 'import' dotted_as_names */ |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1896 static int |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1897 validate_import_name(node *tree) |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1898 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1899 return (validate_ntype(tree, import_name) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1900 && validate_numnodes(tree, 2, "import_name") |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1901 && validate_name(CHILD(tree, 0), "import") |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1902 && validate_dotted_as_names(CHILD(tree, 1))); |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1903 } |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1904 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1905 /* Helper function to count the number of leading dots in |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1906 * 'from ...module import name' |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1907 */ |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1908 static int |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1909 count_from_dots(node *tree) |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1910 { |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1911 int i; |
|
49629
45ac5196fa67
backport r67077 from the trunk: parser module now correctly validates relative imports
Benjamin Peterson <benjamin@python.org>
parents:
38314
diff
changeset
|
1912 for (i = 1; i < NCH(tree); i++) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1913 if (TYPE(CHILD(tree, i)) != DOT) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1914 break; |
|
49629
45ac5196fa67
backport r67077 from the trunk: parser module now correctly validates relative imports
Benjamin Peterson <benjamin@python.org>
parents:
38314
diff
changeset
|
1915 return i-1; |
|
36712
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1916 } |
|
5c36c222e7ca
SF patch #1438387, PEP 328: relative and absolute imports.
Thomas Wouters <thomas@python.org>
parents:
36680
diff
changeset
|
1917 |
|
62781
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
1918 /* import_from: ('from' ('.'* dotted_name | '.'+) |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
1919 * 'import' ('*' | '(' import_as_names ')' | import_as_names)) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1920 */ |
| 4084 | 1921 static int |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1922 validate_import_from(node *tree) |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1923 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1924 int nch = NCH(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1925 int ndots = count_from_dots(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1926 int havename = (TYPE(CHILD(tree, ndots + 1)) == dotted_name); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1927 int offset = ndots + havename; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1928 int res = validate_ntype(tree, import_from) |
|
62781
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
1929 && (offset >= 1) |
|
be662d124385
Issue #9130: Fix validation of relative imports in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62769
diff
changeset
|
1930 && (nch >= 3 + offset) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1931 && validate_name(CHILD(tree, 0), "from") |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1932 && (!havename || validate_dotted_name(CHILD(tree, ndots + 1))) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1933 && validate_name(CHILD(tree, offset + 1), "import"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1934 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1935 if (res && TYPE(CHILD(tree, offset + 2)) == LPAR) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1936 res = ((nch == offset + 5) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1937 && validate_lparen(CHILD(tree, offset + 2)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1938 && validate_import_as_names(CHILD(tree, offset + 3)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1939 && validate_rparen(CHILD(tree, offset + 4))); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1940 else if (res && TYPE(CHILD(tree, offset + 2)) != STAR) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1941 res = validate_import_as_names(CHILD(tree, offset + 2)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1942 return (res); |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1943 } |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1944 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1945 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1946 /* import_stmt: import_name | import_from */ |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1947 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1948 validate_import_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1949 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1950 int nch = NCH(tree); |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1951 int res = validate_numnodes(tree, 1, "import_stmt"); |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1952 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1953 if (res) { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1954 int ntype = TYPE(CHILD(tree, 0)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1955 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
1956 if (ntype == import_name || ntype == import_from) |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1957 res = validate_node(CHILD(tree, 0)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1958 else { |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1959 res = 0; |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1960 err_string("illegal import_stmt child type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1961 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1962 } |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1963 else if (nch == 1) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1964 res = 0; |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1965 PyErr_Format(parser_error, |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1966 "Unrecognized child node of import_stmt: %d.", |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1967 TYPE(CHILD(tree, 0))); |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1968 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1969 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1970 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1971 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1972 |
|
33353
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1973 |
|
f7474d31ba3f
SF patch #1007189, multi-line imports, for instance:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33166
diff
changeset
|
1974 |
| 4084 | 1975 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1976 validate_global_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1977 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1978 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1979 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1980 int res = (validate_ntype(tree, global_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1981 && is_even(nch) && (nch >= 2)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1982 |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
1983 if (!res && !PyErr_Occurred()) |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
1984 err_string("illegal global statement"); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
1985 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1986 if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1987 res = (validate_name(CHILD(tree, 0), "global") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1988 && validate_ntype(CHILD(tree, 1), NAME)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1989 for (j = 2; res && (j < nch); j += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1990 res = (validate_comma(CHILD(tree, j)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1991 && validate_ntype(CHILD(tree, j + 1), NAME)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1992 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1993 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1994 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1995 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1996 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1997 /* exec_stmt: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1998 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1999 * 'exec' expr ['in' test [',' test]] |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2000 */ |
| 4084 | 2001 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2002 validate_exec_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2003 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2004 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2005 int res = (validate_ntype(tree, exec_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2006 && ((nch == 2) || (nch == 4) || (nch == 6)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2007 && validate_name(CHILD(tree, 0), "exec") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2008 && validate_expr(CHILD(tree, 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2009 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2010 if (!res && !PyErr_Occurred()) |
| 15318 | 2011 err_string("illegal exec statement"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2012 if (res && (nch > 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2013 res = (validate_name(CHILD(tree, 2), "in") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2014 && validate_test(CHILD(tree, 3))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2015 if (res && (nch == 6)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2016 res = (validate_comma(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2017 && validate_test(CHILD(tree, 5))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2018 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2019 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2020 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2021 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2022 |
| 5236 | 2023 /* assert_stmt: |
| 2024 * | |
| 2025 * 'assert' test [',' test] | |
| 2026 */ | |
| 2027 static int | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2028 validate_assert_stmt(node *tree) |
| 5236 | 2029 { |
| 2030 int nch = NCH(tree); | |
| 2031 int res = (validate_ntype(tree, assert_stmt) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2032 && ((nch == 2) || (nch == 4)) |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
2033 && (validate_name(CHILD(tree, 0), "assert")) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2034 && validate_test(CHILD(tree, 1))); |
| 5236 | 2035 |
| 2036 if (!res && !PyErr_Occurred()) | |
| 15318 | 2037 err_string("illegal assert statement"); |
| 5236 | 2038 if (res && (nch > 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2039 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2040 && validate_test(CHILD(tree, 3))); |
| 5236 | 2041 |
| 2042 return (res); | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2043 } |
| 5236 | 2044 |
| 2045 | |
| 4084 | 2046 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2047 validate_while(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2048 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2049 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2050 int res = (validate_ntype(tree, while_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2051 && ((nch == 4) || (nch == 7)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2052 && validate_name(CHILD(tree, 0), "while") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2053 && validate_test(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2054 && validate_colon(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2055 && validate_suite(CHILD(tree, 3))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2056 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2057 if (res && (nch == 7)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2058 res = (validate_name(CHILD(tree, 4), "else") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2059 && validate_colon(CHILD(tree, 5)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2060 && validate_suite(CHILD(tree, 6))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2061 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2062 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2063 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2064 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2065 |
| 4084 | 2066 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2067 validate_for(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2068 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2069 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2070 int res = (validate_ntype(tree, for_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2071 && ((nch == 6) || (nch == 9)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2072 && validate_name(CHILD(tree, 0), "for") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2073 && validate_exprlist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2074 && validate_name(CHILD(tree, 2), "in") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2075 && validate_testlist(CHILD(tree, 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2076 && validate_colon(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2077 && validate_suite(CHILD(tree, 5))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2078 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2079 if (res && (nch == 9)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2080 res = (validate_name(CHILD(tree, 6), "else") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2081 && validate_colon(CHILD(tree, 7)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2082 && validate_suite(CHILD(tree, 8))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2083 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2084 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2085 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2086 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2087 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2088 /* try_stmt: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2089 * 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] |
|
50065
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2090 ['finally' ':' suite] |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2091 * | 'try' ':' suite 'finally' ':' suite |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2092 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2093 */ |
| 4084 | 2094 static int |
| 13503 | 2095 validate_try(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2096 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2097 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2098 int pos = 3; |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2099 int res = (validate_ntype(tree, try_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2100 && (nch >= 6) && ((nch % 3) == 0)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2101 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2102 if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2103 res = (validate_name(CHILD(tree, 0), "try") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2104 && validate_colon(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2105 && validate_suite(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2106 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2107 && validate_suite(CHILD(tree, nch - 1))); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
2108 else if (!PyErr_Occurred()) { |
|
13325
7bac10a9bb61
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
2109 const char* name = "except"; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2110 if (TYPE(CHILD(tree, nch - 3)) != except_clause) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2111 name = STR(CHILD(tree, nch - 3)); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
2112 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
2113 PyErr_Format(parser_error, |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
2114 "Illegal number of children for try/%s node.", name); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2115 } |
|
50065
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2116 /* Handle try/finally statement */ |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2117 if (res && (TYPE(CHILD(tree, pos)) == NAME) && |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2118 (strcmp(STR(CHILD(tree, pos)), "finally") == 0)) { |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2119 res = (validate_numnodes(tree, 6, "try/finally") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2120 && validate_colon(CHILD(tree, 4)) |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2121 && validate_suite(CHILD(tree, 5))); |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2122 return (res); |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2123 } |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2124 /* try/except statement: skip past except_clause sections */ |
|
61712
7f15a6006162
Merged revisions 72645 via svnmerge from
Georg Brandl <georg@python.org>
parents:
61465
diff
changeset
|
2125 while (res && pos < nch && (TYPE(CHILD(tree, pos)) == except_clause)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2126 res = (validate_except_clause(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2127 && validate_colon(CHILD(tree, pos + 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2128 && validate_suite(CHILD(tree, pos + 2))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2129 pos += 3; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2130 } |
|
50065
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2131 /* skip else clause */ |
|
61712
7f15a6006162
Merged revisions 72645 via svnmerge from
Georg Brandl <georg@python.org>
parents:
61465
diff
changeset
|
2132 if (res && pos < nch && (TYPE(CHILD(tree, pos)) == NAME) && |
|
50065
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2133 (strcmp(STR(CHILD(tree, pos)), "else") == 0)) { |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2134 res = (validate_colon(CHILD(tree, pos + 1)) |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2135 && validate_suite(CHILD(tree, pos + 2))); |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2136 pos += 3; |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2137 } |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2138 if (res && pos < nch) { |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2139 /* last clause must be a finally */ |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2140 res = (validate_name(CHILD(tree, pos), "finally") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2141 && validate_numnodes(tree, pos + 3, "try/except/finally") |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2142 && validate_colon(CHILD(tree, pos + 1)) |
|
ae98681058b2
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49836
diff
changeset
|
2143 && validate_suite(CHILD(tree, pos + 2))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2144 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2145 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2146 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2147 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2148 |
| 4084 | 2149 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2150 validate_except_clause(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2151 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2152 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2153 int res = (validate_ntype(tree, except_clause) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2154 && ((nch == 1) || (nch == 2) || (nch == 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2155 && validate_name(CHILD(tree, 0), "except")); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2156 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2157 if (res && (nch > 1)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2158 res = validate_test(CHILD(tree, 1)); |
|
62655
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2159 if (res && (nch == 4)) { |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2160 if (TYPE(CHILD(tree, 2)) == NAME) |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2161 res = validate_name(CHILD(tree, 2), "as"); |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2162 else |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2163 res = validate_comma(CHILD(tree, 2)); |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2164 res = res && validate_test(CHILD(tree, 3)); |
|
9f5430e47770
Merged revisions 82400 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
61712
diff
changeset
|
2165 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2166 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2167 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2168 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2169 |
| 4084 | 2170 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2171 validate_test(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2172 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2173 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2174 int res = validate_ntype(tree, test) && is_odd(nch); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2175 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2176 if (res && (TYPE(CHILD(tree, 0)) == lambdef)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2177 res = ((nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2178 && validate_lambdef(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2179 else if (res) { |
|
36673
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2180 res = validate_or_test(CHILD(tree, 0)); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2181 res = (res && (nch == 1 || (nch == 5 && |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2182 validate_name(CHILD(tree, 1), "if") && |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2183 validate_or_test(CHILD(tree, 2)) && |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2184 validate_name(CHILD(tree, 3), "else") && |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2185 validate_test(CHILD(tree, 4))))); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2186 } |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2187 return (res); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2188 } |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2189 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2190 static int |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2191 validate_old_test(node *tree) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2192 { |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2193 int nch = NCH(tree); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2194 int res = validate_ntype(tree, old_test) && (nch == 1); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2195 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2196 if (res && (TYPE(CHILD(tree, 0)) == old_lambdef)) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2197 res = (validate_old_lambdef(CHILD(tree, 0))); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2198 else if (res) { |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2199 res = (validate_or_test(CHILD(tree, 0))); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2200 } |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2201 return (res); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2202 } |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2203 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2204 static int |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2205 validate_or_test(node *tree) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2206 { |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2207 int nch = NCH(tree); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2208 int res = validate_ntype(tree, or_test) && is_odd(nch); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2209 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2210 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2211 int pos; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2212 res = validate_and_test(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2213 for (pos = 1; res && (pos < nch); pos += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2214 res = (validate_name(CHILD(tree, pos), "or") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2215 && validate_and_test(CHILD(tree, pos + 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2216 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2217 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2218 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2219 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2220 |
| 4084 | 2221 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2222 validate_and_test(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2223 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2224 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2225 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2226 int res = (validate_ntype(tree, and_test) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2227 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2228 && validate_not_test(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2229 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2230 for (pos = 1; res && (pos < nch); pos += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2231 res = (validate_name(CHILD(tree, pos), "and") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2232 && validate_not_test(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2233 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2234 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2235 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2236 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2237 |
| 4084 | 2238 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2239 validate_not_test(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2240 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2241 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2242 int res = validate_ntype(tree, not_test) && ((nch == 1) || (nch == 2)); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2243 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2244 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2245 if (nch == 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2246 res = (validate_name(CHILD(tree, 0), "not") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2247 && validate_not_test(CHILD(tree, 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2248 else if (nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2249 res = validate_comparison(CHILD(tree, 0)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2250 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2251 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2252 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2253 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2254 |
| 4084 | 2255 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2256 validate_comparison(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2257 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2258 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2259 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2260 int res = (validate_ntype(tree, comparison) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2261 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2262 && validate_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2263 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2264 for (pos = 1; res && (pos < nch); pos += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2265 res = (validate_comp_op(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2266 && validate_expr(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2267 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2268 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2269 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2270 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2271 |
| 4084 | 2272 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2273 validate_comp_op(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2274 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2275 int res = 0; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2276 int nch = NCH(tree); |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2277 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2278 if (!validate_ntype(tree, comp_op)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2279 return (0); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2280 if (nch == 1) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2281 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2282 * Only child will be a terminal with a well-defined symbolic name |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2283 * or a NAME with a string of either 'is' or 'in' |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2284 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2285 tree = CHILD(tree, 0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2286 switch (TYPE(tree)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2287 case LESS: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2288 case GREATER: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2289 case EQEQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2290 case EQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2291 case LESSEQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2292 case GREATEREQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2293 case NOTEQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2294 res = 1; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2295 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2296 case NAME: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2297 res = ((strcmp(STR(tree), "in") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2298 || (strcmp(STR(tree), "is") == 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2299 if (!res) { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
2300 PyErr_Format(parser_error, |
| 15318 | 2301 "illegal operator '%s'", STR(tree)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2302 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2303 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2304 default: |
| 15318 | 2305 err_string("illegal comparison operator type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2306 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2307 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2308 } |
| 4600 | 2309 else if ((res = validate_numnodes(tree, 2, "comp_op")) != 0) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2310 res = (validate_ntype(CHILD(tree, 0), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2311 && validate_ntype(CHILD(tree, 1), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2312 && (((strcmp(STR(CHILD(tree, 0)), "is") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2313 && (strcmp(STR(CHILD(tree, 1)), "not") == 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2314 || ((strcmp(STR(CHILD(tree, 0)), "not") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2315 && (strcmp(STR(CHILD(tree, 1)), "in") == 0)))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2316 if (!res && !PyErr_Occurred()) |
| 15318 | 2317 err_string("unknown comparison operator"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2318 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2319 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2320 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2321 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2322 |
| 4084 | 2323 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2324 validate_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2325 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2326 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2327 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2328 int res = (validate_ntype(tree, expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2329 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2330 && validate_xor_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2331 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2332 for (j = 2; res && (j < nch); j += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2333 res = (validate_xor_expr(CHILD(tree, j)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2334 && validate_vbar(CHILD(tree, j - 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2335 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2336 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2337 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2338 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2339 |
| 4084 | 2340 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2341 validate_xor_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2342 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2343 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2344 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2345 int res = (validate_ntype(tree, xor_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2346 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2347 && validate_and_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2348 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2349 for (j = 2; res && (j < nch); j += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2350 res = (validate_circumflex(CHILD(tree, j - 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2351 && validate_and_expr(CHILD(tree, j))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2352 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2353 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2354 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2355 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2356 |
| 4084 | 2357 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2358 validate_and_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2359 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2360 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2361 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2362 int res = (validate_ntype(tree, and_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2363 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2364 && validate_shift_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2365 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2366 for (pos = 1; res && (pos < nch); pos += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2367 res = (validate_ampersand(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2368 && validate_shift_expr(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2369 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2370 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2371 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2372 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2373 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2374 static int |
| 13503 | 2375 validate_chain_two_ops(node *tree, int (*termvalid)(node *), int op1, int op2) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2376 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2377 int pos = 1; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2378 int nch = NCH(tree); |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2379 int res = (is_odd(nch) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2380 && (*termvalid)(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2381 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2382 for ( ; res && (pos < nch); pos += 2) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2383 if (TYPE(CHILD(tree, pos)) != op1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2384 res = validate_ntype(CHILD(tree, pos), op2); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2385 if (res) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2386 res = (*termvalid)(CHILD(tree, pos + 1)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2387 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2388 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2389 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2390 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2391 |
| 4084 | 2392 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2393 validate_shift_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2394 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2395 return (validate_ntype(tree, shift_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2396 && validate_chain_two_ops(tree, validate_arith_expr, |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2397 LEFTSHIFT, RIGHTSHIFT)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2398 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2399 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2400 |
| 4084 | 2401 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2402 validate_arith_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2403 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2404 return (validate_ntype(tree, arith_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2405 && validate_chain_two_ops(tree, validate_term, PLUS, MINUS)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2406 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2407 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2408 |
| 4084 | 2409 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2410 validate_term(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2411 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2412 int pos = 1; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2413 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2414 int res = (validate_ntype(tree, term) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2415 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2416 && validate_factor(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2417 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2418 for ( ; res && (pos < nch); pos += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2419 res = (((TYPE(CHILD(tree, pos)) == STAR) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2420 || (TYPE(CHILD(tree, pos)) == SLASH) |
|
27517
51abb5e86226
Teach the parsermodule about floor division. Fixes
Michael W. Hudson <mwh@python.net>
parents:
26979
diff
changeset
|
2421 || (TYPE(CHILD(tree, pos)) == DOUBLESLASH) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2422 || (TYPE(CHILD(tree, pos)) == PERCENT)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2423 && validate_factor(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2424 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2425 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2426 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2427 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2428 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2429 /* factor: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2430 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2431 * factor: ('+'|'-'|'~') factor | power |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2432 */ |
| 4084 | 2433 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2434 validate_factor(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2435 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2436 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2437 int res = (validate_ntype(tree, factor) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2438 && (((nch == 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2439 && ((TYPE(CHILD(tree, 0)) == PLUS) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2440 || (TYPE(CHILD(tree, 0)) == MINUS) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2441 || (TYPE(CHILD(tree, 0)) == TILDE)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2442 && validate_factor(CHILD(tree, 1))) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2443 || ((nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2444 && validate_power(CHILD(tree, 0))))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2445 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2446 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2447 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2448 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2449 /* power: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2450 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2451 * power: atom trailer* ('**' factor)* |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2452 */ |
| 4084 | 2453 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2454 validate_power(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2455 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2456 int pos = 1; |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2457 int nch = NCH(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2458 int res = (validate_ntype(tree, power) && (nch >= 1) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2459 && validate_atom(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2460 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2461 while (res && (pos < nch) && (TYPE(CHILD(tree, pos)) == trailer)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2462 res = validate_trailer(CHILD(tree, pos++)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2463 if (res && (pos < nch)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2464 if (!is_even(nch - pos)) { |
| 15318 | 2465 err_string("illegal number of nodes for 'power'"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2466 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2467 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2468 for ( ; res && (pos < (nch - 1)); pos += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2469 res = (validate_doublestar(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2470 && validate_factor(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2471 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2472 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2473 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2474 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2475 |
| 4084 | 2476 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2477 validate_atom(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2478 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2479 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2480 int nch = NCH(tree); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2481 int res = validate_ntype(tree, atom); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2482 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2483 if (res && nch < 1) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2484 res = validate_numnodes(tree, nch+1, "atom"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2485 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2486 switch (TYPE(CHILD(tree, 0))) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2487 case LPAR: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2488 res = ((nch <= 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2489 && (validate_rparen(CHILD(tree, nch - 1)))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2490 |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
2491 if (res && (nch == 3)) { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2492 if (TYPE(CHILD(tree, 1))==yield_expr) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2493 res = validate_yield_expr(CHILD(tree, 1)); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2494 else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58250
diff
changeset
|
2495 res = validate_testlist_comp(CHILD(tree, 1)); |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2496 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2497 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2498 case LSQB: |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2499 if (nch == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2500 res = validate_ntype(CHILD(tree, 1), RSQB); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2501 else if (nch == 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2502 res = (validate_listmaker(CHILD(tree, 1)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2503 && validate_ntype(CHILD(tree, 2), RSQB)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2504 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2505 res = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2506 err_string("illegal list display atom"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2507 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2508 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2509 case LBRACE: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2510 res = ((nch <= 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2511 && validate_ntype(CHILD(tree, nch - 1), RBRACE)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2512 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2513 if (res && (nch == 3)) |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
2514 res = validate_dictorsetmaker(CHILD(tree, 1)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2515 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2516 case BACKQUOTE: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2517 res = ((nch == 3) |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
2518 && validate_testlist1(CHILD(tree, 1)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2519 && validate_ntype(CHILD(tree, 2), BACKQUOTE)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2520 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2521 case NAME: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2522 case NUMBER: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2523 res = (nch == 1); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2524 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2525 case STRING: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2526 for (pos = 1; res && (pos < nch); ++pos) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2527 res = validate_ntype(CHILD(tree, pos), STRING); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2528 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2529 default: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2530 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2531 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2532 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2533 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2534 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2535 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2536 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2537 |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2538 /* listmaker: |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2539 * test ( list_for | (',' test)* [','] ) |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2540 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2541 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2542 validate_listmaker(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2543 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2544 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2545 int ok = nch; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2546 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2547 if (nch == 0) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2548 err_string("missing child nodes of listmaker"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2549 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2550 ok = validate_test(CHILD(tree, 0)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2551 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2552 /* |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2553 * list_for | (',' test)* [','] |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2554 */ |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2555 if (nch == 2 && TYPE(CHILD(tree, 1)) == list_for) |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2556 ok = validate_list_for(CHILD(tree, 1)); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2557 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2558 /* (',' test)* [','] */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2559 int i = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2560 while (ok && nch - i >= 2) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2561 ok = (validate_comma(CHILD(tree, i)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2562 && validate_test(CHILD(tree, i+1))); |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2563 i += 2; |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2564 } |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2565 if (ok && i == nch-1) |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2566 ok = validate_comma(CHILD(tree, i)); |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2567 else if (i != nch) { |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2568 ok = 0; |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2569 err_string("illegal trailing nodes for listmaker"); |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2570 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2571 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2572 return ok; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2573 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2574 |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2575 /* testlist_comp: |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2576 * test ( comp_for | (',' test)* [','] ) |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2577 */ |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2578 static int |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2579 validate_testlist_comp(node *tree) |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2580 { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2581 int nch = NCH(tree); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2582 int ok = nch; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2583 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2584 if (nch == 0) |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2585 err_string("missing child nodes of testlist_comp"); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2586 else { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2587 ok = validate_test(CHILD(tree, 0)); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2588 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2589 |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2590 /* |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2591 * comp_for | (',' test)* [','] |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2592 */ |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2593 if (nch == 2 && TYPE(CHILD(tree, 1)) == comp_for) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2594 ok = validate_comp_for(CHILD(tree, 1)); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2595 else { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2596 /* (',' test)* [','] */ |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2597 int i = 1; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2598 while (ok && nch - i >= 2) { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2599 ok = (validate_comma(CHILD(tree, i)) |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2600 && validate_test(CHILD(tree, i+1))); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2601 i += 2; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2602 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2603 if (ok && i == nch-1) |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2604 ok = validate_comma(CHILD(tree, i)); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2605 else if (i != nch) { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2606 ok = 0; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2607 err_string("illegal trailing nodes for testlist_comp"); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2608 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2609 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2610 return ok; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2611 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2612 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2613 /* decorator: |
|
33166
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2614 * '@' dotted_name [ '(' [arglist] ')' ] NEWLINE |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2615 */ |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2616 static int |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2617 validate_decorator(node *tree) |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2618 { |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2619 int ok; |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2620 int nch = NCH(tree); |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2621 ok = (validate_ntype(tree, decorator) && |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2622 (nch == 3 || nch == 5 || nch == 6) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2623 validate_at(CHILD(tree, 0)) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2624 validate_dotted_name(CHILD(tree, 1)) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2625 validate_newline(RCHILD(tree, -1))); |
|
33166
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2626 |
|
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2627 if (ok && nch != 3) { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2628 ok = (validate_lparen(CHILD(tree, 2)) && |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2629 validate_rparen(RCHILD(tree, -2))); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2630 |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2631 if (ok && nch == 6) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2632 ok = validate_arglist(CHILD(tree, 3)); |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2633 } |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2634 |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2635 return ok; |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2636 } |
|
33166
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2637 |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2638 /* decorators: |
|
33166
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2639 * decorator+ |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2640 */ |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2641 static int |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2642 validate_decorators(node *tree) |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2643 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2644 int i, nch, ok; |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2645 nch = NCH(tree); |
|
33166
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2646 ok = validate_ntype(tree, decorators) && nch >= 1; |
|
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2647 |
|
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2648 for (i = 0; ok && i < nch; ++i) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2649 ok = validate_decorator(CHILD(tree, i)); |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2650 |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2651 return ok; |
|
33166
2e8d2bdd33de
This is Mark Russell's patch:
Michael W. Hudson <mwh@python.net>
parents:
32888
diff
changeset
|
2652 } |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2653 |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2654 /* with_item: |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2655 * test ['as' expr] |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2656 */ |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2657 static int |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2658 validate_with_item(node *tree) |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2659 { |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2660 int nch = NCH(tree); |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2661 int ok = (validate_ntype(tree, with_item) |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2662 && (nch == 1 || nch == 3) |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2663 && validate_test(CHILD(tree, 0))); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58250
diff
changeset
|
2664 if (ok && nch == 3) |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2665 ok = (validate_name(CHILD(tree, 1), "as") |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2666 && validate_expr(CHILD(tree, 2))); |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2667 return ok; |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2668 } |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2669 |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2670 /* with_stmt: |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2671 * 0 1 ... -2 -1 |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2672 * 'with' with_item (',' with_item)* ':' suite |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2673 */ |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2674 static int |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2675 validate_with_stmt(node *tree) |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2676 { |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2677 int i; |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2678 int nch = NCH(tree); |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2679 int ok = (validate_ntype(tree, with_stmt) |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2680 && (nch % 2 == 0) |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2681 && validate_name(CHILD(tree, 0), "with") |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2682 && validate_colon(RCHILD(tree, -2)) |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2683 && validate_suite(RCHILD(tree, -1))); |
|
54337
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2684 for (i = 1; ok && i < nch - 2; i += 2) |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2685 ok = validate_with_item(CHILD(tree, i)); |
|
16759f62eb22
Allow multiple context managers in one with statement, as proposed
Georg Brandl <georg@python.org>
parents:
54080
diff
changeset
|
2686 return ok; |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2687 } |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
2688 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2689 /* funcdef: |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2690 * |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2691 * -5 -4 -3 -2 -1 |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2692 * 'def' NAME parameters ':' suite |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2693 */ |
| 4084 | 2694 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2695 validate_funcdef(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2696 { |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2697 int nch = NCH(tree); |
|
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2698 int ok = (validate_ntype(tree, funcdef) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2699 && (nch == 5) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2700 && validate_name(RCHILD(tree, -5), "def") |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2701 && validate_ntype(RCHILD(tree, -4), NAME) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2702 && validate_colon(RCHILD(tree, -2)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2703 && validate_parameters(RCHILD(tree, -3)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
2704 && validate_suite(RCHILD(tree, -1))); |
|
32888
c7e03cf8333e
PEP-0318, @decorator-style. In Guido's words:
Anthony Baxter <anthonybaxter@gmail.com>
parents:
32121
diff
changeset
|
2705 return ok; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2706 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2707 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2708 |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2709 /* decorated |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2710 * decorators (classdef | funcdef) |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2711 */ |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2712 static int |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2713 validate_decorated(node *tree) |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2714 { |
|
62769
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2715 int nch = NCH(tree); |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2716 int ok = (validate_ntype(tree, decorated) |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2717 && (nch == 2) |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2718 && validate_decorators(RCHILD(tree, -2))); |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2719 if (TYPE(RCHILD(tree, -1)) == funcdef) |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2720 ok = ok && validate_funcdef(RCHILD(tree, -1)); |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2721 else |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2722 ok = ok && validate_class(RCHILD(tree, -1)); |
|
124a76ae7a70
Issue #9128: Fix validation of class decorators in parser module.
Mark Dickinson <dickinsm@gmail.com>
parents:
62655
diff
changeset
|
2723 return ok; |
|
45447
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2724 } |
|
393822f2ef90
Patch #1759: Backport of PEP 3129 class decorators
Christian Heimes <christian@cheimes.de>
parents:
44439
diff
changeset
|
2725 |
| 4084 | 2726 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2727 validate_lambdef(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2728 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2729 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2730 int res = (validate_ntype(tree, lambdef) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2731 && ((nch == 3) || (nch == 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2732 && validate_name(CHILD(tree, 0), "lambda") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2733 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2734 && validate_test(CHILD(tree, nch - 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2735 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2736 if (res && (nch == 4)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2737 res = validate_varargslist(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2738 else if (!res && !PyErr_Occurred()) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2739 (void) validate_numnodes(tree, 3, "lambdef"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2740 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2741 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2742 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2743 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2744 |
|
36673
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2745 static int |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2746 validate_old_lambdef(node *tree) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2747 { |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2748 int nch = NCH(tree); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2749 int res = (validate_ntype(tree, old_lambdef) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2750 && ((nch == 3) || (nch == 4)) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2751 && validate_name(CHILD(tree, 0), "lambda") |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2752 && validate_colon(CHILD(tree, nch - 2)) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2753 && validate_test(CHILD(tree, nch - 1))); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2754 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2755 if (res && (nch == 4)) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2756 res = validate_varargslist(CHILD(tree, 1)); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2757 else if (!res && !PyErr_Occurred()) |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2758 (void) validate_numnodes(tree, 3, "old_lambdef"); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2759 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2760 return (res); |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2761 } |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2762 |
|
2ddea5535f08
Update for PEP 308 patch.
Thomas Wouters <thomas@python.org>
parents:
36518
diff
changeset
|
2763 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2764 /* arglist: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2765 * |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2766 * (argument ',')* (argument [','] | '*' test [',' '**' test] | '**' test) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2767 */ |
| 4084 | 2768 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2769 validate_arglist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2770 { |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2771 int nch = NCH(tree); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2772 int i = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2773 int ok = 1; |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2774 |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2775 if (nch <= 0) |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2776 /* raise the right error from having an invalid number of children */ |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2777 return validate_numnodes(tree, nch + 1, "arglist"); |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2778 |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2779 if (nch > 1) { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2780 for (i=0; i<nch; i++) { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2781 if (TYPE(CHILD(tree, i)) == argument) { |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2782 node *ch = CHILD(tree, i); |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2783 if (NCH(ch) == 2 && TYPE(CHILD(ch, 1)) == comp_for) { |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2784 err_string("need '(', ')' for generator expression"); |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2785 return 0; |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2786 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2787 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2788 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2789 } |
|
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2790 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2791 while (ok && nch-i >= 2) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2792 /* skip leading (argument ',') */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2793 ok = (validate_argument(CHILD(tree, i)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2794 && validate_comma(CHILD(tree, i+1))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2795 if (ok) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2796 i += 2; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2797 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2798 PyErr_Clear(); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2799 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2800 ok = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2801 if (nch-i > 0) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2802 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2803 * argument | '*' test [',' '**' test] | '**' test |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2804 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2805 int sym = TYPE(CHILD(tree, i)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2806 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2807 if (sym == argument) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2808 ok = validate_argument(CHILD(tree, i)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2809 if (ok && i+1 != nch) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2810 err_string("illegal arglist specification" |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2811 " (extra stuff on end)"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2812 ok = 0; |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2813 } |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2814 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2815 else if (sym == STAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2816 ok = validate_star(CHILD(tree, i)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2817 if (ok && (nch-i == 2)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2818 ok = validate_test(CHILD(tree, i+1)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2819 else if (ok && (nch-i == 5)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2820 ok = (validate_test(CHILD(tree, i+1)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2821 && validate_comma(CHILD(tree, i+2)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2822 && validate_doublestar(CHILD(tree, i+3)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2823 && validate_test(CHILD(tree, i+4))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2824 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2825 err_string("illegal use of '*' in arglist"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2826 ok = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2827 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2828 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2829 else if (sym == DOUBLESTAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2830 if (nch-i == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2831 ok = (validate_doublestar(CHILD(tree, i)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2832 && validate_test(CHILD(tree, i+1))); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2833 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2834 err_string("illegal use of '**' in arglist"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2835 ok = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2836 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2837 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2838 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2839 err_string("illegal arglist specification"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2840 ok = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2841 } |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2842 } |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2843 return (ok); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2844 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2845 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2846 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2847 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2848 /* argument: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2849 * |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2850 * [test '='] test [comp_for] |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2851 */ |
| 4084 | 2852 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2853 validate_argument(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2854 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2855 int nch = NCH(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2856 int res = (validate_ntype(tree, argument) |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2857 && ((nch == 1) || (nch == 2) || (nch == 3)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2858 && validate_test(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2859 |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2860 if (res && (nch == 2)) |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
2861 res = validate_comp_for(CHILD(tree, 1)); |
|
32121
302d399cfd37
SF patch #872326: Generator expression implementation
Raymond Hettinger <python@rcn.com>
parents:
30979
diff
changeset
|
2862 else if (res && (nch == 3)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2863 res = (validate_equal(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2864 && validate_test(CHILD(tree, 2))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2865 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2866 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2867 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2868 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2869 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2870 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2871 /* trailer: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2872 * |
| 4084 | 2873 * '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2874 */ |
| 4084 | 2875 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2876 validate_trailer(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2877 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2878 int nch = NCH(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2879 int res = validate_ntype(tree, trailer) && ((nch == 2) || (nch == 3)); |
|
1406
474823e5f7dc
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2880 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2881 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2882 switch (TYPE(CHILD(tree, 0))) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2883 case LPAR: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2884 res = validate_rparen(CHILD(tree, nch - 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2885 if (res && (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2886 res = validate_arglist(CHILD(tree, 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2887 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2888 case LSQB: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2889 res = (validate_numnodes(tree, 3, "trailer") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2890 && validate_subscriptlist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2891 && validate_ntype(CHILD(tree, 2), RSQB)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2892 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2893 case DOT: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2894 res = (validate_numnodes(tree, 2, "trailer") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2895 && validate_ntype(CHILD(tree, 1), NAME)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2896 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2897 default: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2898 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2899 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2900 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2901 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2902 else { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2903 (void) validate_numnodes(tree, 2, "trailer"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2904 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2905 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2906 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2907 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2908 |
| 4084 | 2909 /* subscriptlist: |
| 2910 * | |
| 2911 * subscript (',' subscript)* [','] | |
| 2912 */ | |
| 2913 static int | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2914 validate_subscriptlist(node *tree) |
| 4084 | 2915 { |
| 2916 return (validate_repeating_list(tree, subscriptlist, | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2917 validate_subscript, "subscriptlist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2918 } |
| 4084 | 2919 |
| 2920 | |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2921 /* subscript: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2922 * |
| 4084 | 2923 * '.' '.' '.' | test | [test] ':' [test] [sliceop] |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2924 */ |
| 4084 | 2925 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2926 validate_subscript(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2927 { |
| 4084 | 2928 int offset = 0; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2929 int nch = NCH(tree); |
| 4084 | 2930 int res = validate_ntype(tree, subscript) && (nch >= 1) && (nch <= 4); |
| 2931 | |
| 2932 if (!res) { | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2933 if (!PyErr_Occurred()) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2934 err_string("invalid number of arguments for subscript node"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2935 return (0); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2936 } |
| 4084 | 2937 if (TYPE(CHILD(tree, 0)) == DOT) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2938 /* take care of ('.' '.' '.') possibility */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2939 return (validate_numnodes(tree, 3, "subscript") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2940 && validate_dot(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2941 && validate_dot(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2942 && validate_dot(CHILD(tree, 2))); |
| 4084 | 2943 if (nch == 1) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2944 if (TYPE(CHILD(tree, 0)) == test) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2945 res = validate_test(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2946 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2947 res = validate_colon(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2948 return (res); |
| 4084 | 2949 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2950 /* Must be [test] ':' [test] [sliceop], |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2951 * but at least one of the optional components will |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2952 * be present, but we don't know which yet. |
| 4084 | 2953 */ |
| 2954 if ((TYPE(CHILD(tree, 0)) != COLON) || (nch == 4)) { | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2955 res = validate_test(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2956 offset = 1; |
| 4084 | 2957 } |
| 2958 if (res) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2959 res = validate_colon(CHILD(tree, offset)); |
| 4084 | 2960 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2961 int rem = nch - ++offset; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2962 if (rem) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2963 if (TYPE(CHILD(tree, offset)) == test) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2964 res = validate_test(CHILD(tree, offset)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2965 ++offset; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2966 --rem; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2967 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2968 if (res && rem) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2969 res = validate_sliceop(CHILD(tree, offset)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2970 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2971 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2972 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2973 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2974 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2975 |
| 4084 | 2976 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2977 validate_sliceop(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2978 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2979 int nch = NCH(tree); |
| 4084 | 2980 int res = ((nch == 1) || validate_numnodes(tree, 2, "sliceop")) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2981 && validate_ntype(tree, sliceop); |
| 4084 | 2982 if (!res && !PyErr_Occurred()) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2983 res = validate_numnodes(tree, 1, "sliceop"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2984 } |
| 4084 | 2985 if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2986 res = validate_colon(CHILD(tree, 0)); |
| 4084 | 2987 if (res && (nch == 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2988 res = validate_test(CHILD(tree, 1)); |
| 4084 | 2989 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2990 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2991 } |
| 4084 | 2992 |
| 2993 | |
| 2994 static int | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2995 validate_exprlist(node *tree) |
| 4084 | 2996 { |
| 2997 return (validate_repeating_list(tree, exprlist, | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2998 validate_expr, "exprlist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2999 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3000 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3001 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58250
diff
changeset
|
3002 /* |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58250
diff
changeset
|
3003 * dictorsetmaker: |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3004 * |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3005 * (test ':' test (comp_for | (',' test ':' test)* [','])) | |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3006 * (test (comp_for | (',' test)* [','])) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3007 */ |
| 4084 | 3008 static int |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3009 validate_dictorsetmaker(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3010 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3011 int nch = NCH(tree); |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3012 int ok = validate_ntype(tree, dictorsetmaker); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3013 int i = 0; |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3014 int check_trailing_comma = 0; |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3015 |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3016 assert(nch > 0); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3017 |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3018 if (ok && (nch == 1 || TYPE(CHILD(tree, 1)) == COMMA)) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3019 /* We got a set: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58250
diff
changeset
|
3020 * test (',' test)* [','] |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3021 */ |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3022 ok = validate_test(CHILD(tree, i++)); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3023 while (ok && nch - i >= 2) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3024 ok = (validate_comma(CHILD(tree, i)) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3025 && validate_test(CHILD(tree, i+1))); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3026 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3027 } |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3028 check_trailing_comma = 1; |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3029 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3030 else if (ok && TYPE(CHILD(tree, 1)) == comp_for) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3031 /* We got a set comprehension: |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3032 * test comp_for |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3033 */ |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3034 ok = (validate_test(CHILD(tree, 0)) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3035 && validate_comp_for(CHILD(tree, 1))); |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3036 } |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3037 else if (ok && NCH(tree) > 3 && TYPE(CHILD(tree, 3)) == comp_for) { |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3038 /* We got a dict comprehension: |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3039 * test ':' test comp_for |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3040 */ |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3041 ok = (validate_test(CHILD(tree, 0)) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3042 && validate_colon(CHILD(tree, 1)) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3043 && validate_test(CHILD(tree, 2)) |
|
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3044 && validate_comp_for(CHILD(tree, 3))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3045 } |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3046 else if (ok) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3047 /* We got a dict: |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3048 * test ':' test (',' test ':' test)* [','] |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3049 */ |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3050 if (nch >= 3) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3051 ok = (validate_test(CHILD(tree, i)) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3052 && validate_colon(CHILD(tree, i+1)) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3053 && validate_test(CHILD(tree, i+2))); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3054 i += 3; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3055 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3056 else { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3057 ok = 0; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3058 err_string("illegal number of nodes for dictorsetmaker"); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3059 } |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3060 |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3061 while (ok && nch - i >= 4) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3062 ok = (validate_comma(CHILD(tree, i)) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3063 && validate_test(CHILD(tree, i+1)) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3064 && validate_colon(CHILD(tree, i+2)) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3065 && validate_test(CHILD(tree, i+3))); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3066 i += 4; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3067 } |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3068 check_trailing_comma = 1; |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3069 } |
|
58250
edfed0e32ced
Issue #2333: Backport set and dict comprehensions syntax.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
58229
diff
changeset
|
3070 if (ok && check_trailing_comma) { |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3071 if (i == nch-1) |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3072 ok = validate_comma(CHILD(tree, i)); |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3073 else if (i != nch) { |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3074 ok = 0; |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3075 err_string("illegal trailing nodes for dictorsetmaker"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3076 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3077 } |
|
58229
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3078 |
|
c2fdf25329ff
Issue #2335: Backport set literals syntax from Python 3.x.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
54337
diff
changeset
|
3079 return ok; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3080 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3081 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3082 |
| 4084 | 3083 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3084 validate_eval_input(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3085 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3086 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3087 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3088 int res = (validate_ntype(tree, eval_input) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3089 && (nch >= 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3090 && validate_testlist(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3091 && validate_ntype(CHILD(tree, nch - 1), ENDMARKER)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3092 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3093 for (pos = 1; res && (pos < (nch - 1)); ++pos) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3094 res = validate_ntype(CHILD(tree, pos), NEWLINE); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3095 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3096 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3097 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3098 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3099 |
| 4084 | 3100 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3101 validate_node(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3102 { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3103 int nch = 0; /* num. children on current node */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3104 int res = 1; /* result value */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3105 node* next = 0; /* node to process after this one */ |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3106 |
|
18247
e3cf3348feca
Properly use &&. Closes bug #434989.
Martin v. Löwis <martin@v.loewis.de>
parents:
15751
diff
changeset
|
3107 while (res && (tree != 0)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3108 nch = NCH(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3109 next = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3110 switch (TYPE(tree)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3111 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3112 * Definition nodes. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3113 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3114 case funcdef: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3115 res = validate_funcdef(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3116 break; |
|
49836
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
3117 case with_stmt: |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
3118 res = validate_with_stmt(tree); |
|
99598a61cc35
Merged revisions 67365 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49628
diff
changeset
|
3119 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3120 case classdef: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3121 res = validate_class(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3122 break; |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3123 case decorated: |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3124 res = validate_decorated(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3125 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3126 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3127 * "Trivial" parse tree nodes. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3128 * (Why did I call these trivial?) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3129 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3130 case stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3131 res = validate_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3132 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3133 case small_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3134 /* |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
3135 * expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3136 * | import_stmt | global_stmt | exec_stmt | assert_stmt |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3137 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3138 res = validate_small_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3139 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3140 case flow_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3141 res = (validate_numnodes(tree, 1, "flow_stmt") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3142 && ((TYPE(CHILD(tree, 0)) == break_stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3143 || (TYPE(CHILD(tree, 0)) == continue_stmt) |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
3144 || (TYPE(CHILD(tree, 0)) == yield_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3145 || (TYPE(CHILD(tree, 0)) == return_stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3146 || (TYPE(CHILD(tree, 0)) == raise_stmt))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3147 if (res) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3148 next = CHILD(tree, 0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3149 else if (nch == 1) |
| 15318 | 3150 err_string("illegal flow_stmt type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3151 break; |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
3152 case yield_stmt: |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
3153 res = validate_yield_stmt(tree); |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
3154 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3155 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3156 * Compound statements. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3157 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3158 case simple_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3159 res = validate_simple_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3160 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3161 case compound_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3162 res = validate_compound_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3163 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3164 /* |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
3165 * Fundamental statements. |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3166 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3167 case expr_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3168 res = validate_expr_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3169 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3170 case print_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3171 res = validate_print_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3172 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3173 case del_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3174 res = validate_del_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3175 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3176 case pass_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3177 res = (validate_numnodes(tree, 1, "pass") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3178 && validate_name(CHILD(tree, 0), "pass")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3179 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3180 case break_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3181 res = (validate_numnodes(tree, 1, "break") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3182 && validate_name(CHILD(tree, 0), "break")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3183 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3184 case continue_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3185 res = (validate_numnodes(tree, 1, "continue") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3186 && validate_name(CHILD(tree, 0), "continue")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3187 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3188 case return_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3189 res = validate_return_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3190 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3191 case raise_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3192 res = validate_raise_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3193 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3194 case import_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3195 res = validate_import_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3196 break; |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3197 case import_name: |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3198 res = validate_import_name(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3199 break; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3200 case import_from: |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3201 res = validate_import_from(tree); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3202 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3203 case global_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3204 res = validate_global_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3205 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3206 case exec_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3207 res = validate_exec_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3208 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3209 case assert_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3210 res = validate_assert_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3211 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3212 case if_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3213 res = validate_if(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3214 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3215 case while_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3216 res = validate_while(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3217 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3218 case for_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3219 res = validate_for(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3220 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3221 case try_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3222 res = validate_try(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3223 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3224 case suite: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3225 res = validate_suite(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3226 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3227 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3228 * Expression nodes. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3229 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3230 case testlist: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3231 res = validate_testlist(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3232 break; |
|
35298
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
3233 case yield_expr: |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
3234 res = validate_yield_expr(tree); |
|
b2fe5f8fcfdd
PEP 342 implementation. Per Guido's comments, the generator throw()
Phillip J. Eby <pje@telecommunity.com>
parents:
34887
diff
changeset
|
3235 break; |
|
23538
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
3236 case testlist1: |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
3237 res = validate_testlist1(tree); |
|
9e67a0d5705f
Disambiguate the grammar for backtick.
Guido van Rossum <guido@python.org>
parents:
21313
diff
changeset
|
3238 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3239 case test: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3240 res = validate_test(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3241 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3242 case and_test: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3243 res = validate_and_test(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3244 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3245 case not_test: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3246 res = validate_not_test(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3247 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3248 case comparison: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3249 res = validate_comparison(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3250 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3251 case exprlist: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3252 res = validate_exprlist(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3253 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3254 case comp_op: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3255 res = validate_comp_op(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3256 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3257 case expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3258 res = validate_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3259 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3260 case xor_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3261 res = validate_xor_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3262 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3263 case and_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3264 res = validate_and_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3265 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3266 case shift_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3267 res = validate_shift_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3268 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3269 case arith_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3270 res = validate_arith_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3271 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3272 case term: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3273 res = validate_term(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3274 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3275 case factor: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3276 res = validate_factor(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3277 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3278 case power: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3279 res = validate_power(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3280 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3281 case atom: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3282 res = validate_atom(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3283 break; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3284 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3285 default: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3286 /* Hopefully never reached! */ |
| 15318 | 3287 err_string("unrecognized node type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3288 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3289 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3290 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3291 tree = next; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3292 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3293 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3294 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3295 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3296 |
| 4084 | 3297 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3298 validate_expr_tree(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3299 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3300 int res = validate_eval_input(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3301 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3302 if (!res && !PyErr_Occurred()) |
| 15318 | 3303 err_string("could not validate expression tuple"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3304 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3305 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3306 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3307 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3308 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3309 /* file_input: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3310 * (NEWLINE | stmt)* ENDMARKER |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3311 */ |
| 4084 | 3312 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3313 validate_file_input(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3314 { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3315 int j; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3316 int nch = NCH(tree) - 1; |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3317 int res = ((nch >= 0) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3318 && validate_ntype(CHILD(tree, nch), ENDMARKER)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3319 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3320 for (j = 0; res && (j < nch); ++j) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3321 if (TYPE(CHILD(tree, j)) == stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3322 res = validate_stmt(CHILD(tree, j)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3323 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3324 res = validate_newline(CHILD(tree, j)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3325 } |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13576
diff
changeset
|
3326 /* This stays in to prevent any internal failures from getting to the |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3327 * user. Hopefully, this won't be needed. If a user reports getting |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3328 * this, we have some debugging to do. |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3329 */ |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3330 if (!res && !PyErr_Occurred()) |
| 15318 | 3331 err_string("VALIDATION FAILURE: report this to the maintainer!"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3332 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3333 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3334 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3335 |
|
27767
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3336 static int |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3337 validate_encoding_decl(node *tree) |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3338 { |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3339 int nch = NCH(tree); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3340 int res = ((nch == 1) |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3341 && validate_file_input(CHILD(tree, 0))); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3342 |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3343 if (!res && !PyErr_Occurred()) |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3344 err_string("Error Parsing encoding_decl"); |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3345 |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3346 return res; |
|
82cbf1178e4f
Apply logistix's patch from
Michael W. Hudson <mwh@python.net>
parents:
27517
diff
changeset
|
3347 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3348 |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3349 static PyObject* |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3350 pickle_constructor = NULL; |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3351 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3352 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3353 static PyObject* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3354 parser__pickler(PyObject *self, PyObject *args) |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3355 { |
| 8196 | 3356 NOTE(ARGUNUSED(self)) |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3357 PyObject *result = NULL; |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3358 PyObject *st = NULL; |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
3359 PyObject *empty_dict = NULL; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3360 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3361 if (PyArg_ParseTuple(args, "O!:_pickler", &PyST_Type, &st)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3362 PyObject *newargs; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3363 PyObject *tuple; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3364 |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
3365 if ((empty_dict = PyDict_New()) == NULL) |
|
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
3366 goto finally; |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3367 if ((newargs = Py_BuildValue("Oi", st, 1)) == NULL) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3368 goto finally; |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3369 tuple = parser_st2tuple((PyST_Object*)NULL, newargs, empty_dict); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3370 if (tuple != NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3371 result = Py_BuildValue("O(O)", pickle_constructor, tuple); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3372 Py_DECREF(tuple); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3373 } |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
3374 Py_DECREF(empty_dict); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3375 Py_DECREF(newargs); |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3376 } |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3377 finally: |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
3378 Py_XDECREF(empty_dict); |
|
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
3379 |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3380 return (result); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3381 } |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3382 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3383 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3384 /* Functions exported by this module. Most of this should probably |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3385 * be converted into an ST object with methods, but that is better |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3386 * done directly in Python, allowing subclasses to be created directly. |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3387 * We'd really have to write a wrapper around it all anyway to allow |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
3388 * inheritance. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3389 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3390 static PyMethodDef parser_functions[] = { |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
3391 {"ast2tuple", (PyCFunction)parser_ast2tuple, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3392 PyDoc_STR("Creates a tuple-tree representation of an ST.")}, |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
3393 {"ast2list", (PyCFunction)parser_ast2list, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3394 PyDoc_STR("Creates a list-tree representation of an ST.")}, |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
3395 {"compileast", (PyCFunction)parser_compileast,PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3396 PyDoc_STR("Compiles an ST object into a code object.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3397 {"compilest", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3398 PyDoc_STR("Compiles an ST object into a code object.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3399 {"expr", (PyCFunction)parser_expr, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3400 PyDoc_STR("Creates an ST object from an expression.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3401 {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3402 PyDoc_STR("Determines if an ST object was created from an expression.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3403 {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3404 PyDoc_STR("Determines if an ST object was created from a suite.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3405 {"suite", (PyCFunction)parser_suite, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3406 PyDoc_STR("Creates an ST object from a suite.")}, |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
3407 {"sequence2ast", (PyCFunction)parser_tuple2ast, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3408 PyDoc_STR("Creates an ST object from a tree representation.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3409 {"sequence2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3410 PyDoc_STR("Creates an ST object from a tree representation.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3411 {"st2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3412 PyDoc_STR("Creates a tuple-tree representation of an ST.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3413 {"st2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3414 PyDoc_STR("Creates a list-tree representation of an ST.")}, |
|
48056
0441d30d672b
3k-warn about parser's "ast" aliases.
Georg Brandl <georg@python.org>
parents:
47527
diff
changeset
|
3415 {"tuple2ast", (PyCFunction)parser_tuple2ast, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3416 PyDoc_STR("Creates an ST object from a tree representation.")}, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3417 {"tuple2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3418 PyDoc_STR("Creates an ST object from a tree representation.")}, |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3419 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3420 /* private stuff: support pickle module */ |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3421 {"_pickler", (PyCFunction)parser__pickler, METH_VARARGS, |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24363
diff
changeset
|
3422 PyDoc_STR("Returns the pickle magic to allow ST objects to be pickled.")}, |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3423 |
| 8196 | 3424 {NULL, NULL, 0, NULL} |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3425 }; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3426 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3427 |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
3428 PyMODINIT_FUNC initparser(void); /* supply a prototype */ |
|
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
3429 |
|
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
3430 PyMODINIT_FUNC |
| 13692 | 3431 initparser(void) |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
3432 { |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3433 PyObject *module, *copyreg; |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3434 |
|
44350
26384b8180c7
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents:
42333
diff
changeset
|
3435 Py_TYPE(&PyST_Type) = &PyType_Type; |
|
5039
38032267968c
Initialize the ob_type field of PyAST_Type dynamically (in
Guido van Rossum <guido@python.org>
parents:
4600
diff
changeset
|
3436 module = Py_InitModule("parser", parser_functions); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35999
diff
changeset
|
3437 if (module == NULL) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50065
diff
changeset
|
3438 return; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3439 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
3440 if (parser_error == 0) |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
3441 parser_error = PyErr_NewException("parser.ParserError", NULL, NULL); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3442 |
|
29952
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3443 if (parser_error == 0) |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3444 /* caller will check PyErr_Occurred() */ |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3445 return; |
|
29952
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3446 /* CAUTION: The code next used to skip bumping the refcount on |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3447 * parser_error. That's a disaster if initparser() gets called more |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3448 * than once. By incref'ing, we ensure that each module dict that |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3449 * gets created owns its reference to the shared parser_error object, |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3450 * and the file static parser_error vrbl owns a reference too. |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3451 */ |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3452 Py_INCREF(parser_error); |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3453 if (PyModule_AddObject(module, "ParserError", parser_error) != 0) |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3454 return; |
|
1cbc6b7836dc
Merge 23c1-branch back into the head. Barry will send email about the
Tim Peters <tim.peters@gmail.com>
parents:
28551
diff
changeset
|
3455 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3456 Py_INCREF(&PyST_Type); |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3457 PyModule_AddObject(module, "ASTType", (PyObject*)&PyST_Type); |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
3458 Py_INCREF(&PyST_Type); |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3459 PyModule_AddObject(module, "STType", (PyObject*)&PyST_Type); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3460 |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3461 PyModule_AddStringConstant(module, "__copyright__", |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3462 parser_copyright_string); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3463 PyModule_AddStringConstant(module, "__doc__", |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3464 parser_doc_string); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3465 PyModule_AddStringConstant(module, "__version__", |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3466 parser_version_string); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
3467 |
| 18748 | 3468 /* Register to support pickling. |
| 3469 * If this fails, the import of this module will fail because an | |
| 3470 * exception will be raised here; should we clear the exception? | |
| 3471 */ | |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
46865
diff
changeset
|
3472 copyreg = PyImport_ImportModuleNoBlock("copy_reg"); |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3473 if (copyreg != NULL) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3474 PyObject *func, *pickler; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3475 |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3476 func = PyObject_GetAttrString(copyreg, "pickle"); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3477 pickle_constructor = PyObject_GetAttrString(module, "sequence2st"); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3478 pickler = PyObject_GetAttrString(module, "_pickler"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3479 Py_XINCREF(pickle_constructor); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3480 if ((func != NULL) && (pickle_constructor != NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3481 && (pickler != NULL)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3482 PyObject *res; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3483 |
|
38314
1fdf29a88f0e
Replace PyObject_CallFunction calls with only object args
Georg Brandl <georg@python.org>
parents:
37622
diff
changeset
|
3484 res = PyObject_CallFunctionObjArgs(func, &PyST_Type, pickler, |
|
1fdf29a88f0e
Replace PyObject_CallFunction calls with only object args
Georg Brandl <georg@python.org>
parents:
37622
diff
changeset
|
3485 pickle_constructor, NULL); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3486 Py_XDECREF(res); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3487 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3488 Py_XDECREF(func); |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3489 Py_XDECREF(pickle_constructor); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3490 Py_XDECREF(pickler); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
3491 Py_DECREF(copyreg); |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
3492 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
3493 } |
