Mercurial > cpython-lru_cache-weakref
annotate Modules/parsermodule.c @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | 56141b86a7f2 |
| children | 42d0819546d6 |
| 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 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
29 #include "graminit.h" /* symbols defined in the grammar */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
30 #include "node.h" /* internal parser structure */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
31 #include "token.h" /* token definitions */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
32 /* ISTERMINAL() / ISNONTERMINAL() */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
33 #include "compile.h" /* PyNode_Compile() */ |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
34 |
| 8196 | 35 #ifdef lint |
| 36 #include <note.h> | |
| 37 #else | |
| 38 #define NOTE(x) | |
| 39 #endif | |
| 40 | |
|
8184
142165ed84d8
Add a declaration for strdup() for the Mac.
Guido van Rossum <guido@python.org>
parents:
8112
diff
changeset
|
41 #ifdef macintosh |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
42 char *strdup(char *); |
|
8184
142165ed84d8
Add a declaration for strdup() for the Mac.
Guido van Rossum <guido@python.org>
parents:
8112
diff
changeset
|
43 #endif |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
44 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
45 /* String constants used to initialize module attributes. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
46 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
47 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
48 static char* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
49 parser_copyright_string |
|
4099
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
50 = "Copyright 1995-1996 by Virginia Polytechnic Institute & State\n\ |
|
3a3b36716689
Patches to make it compile with K&R C
Guido van Rossum <guido@python.org>
parents:
4092
diff
changeset
|
51 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
|
52 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
|
53 Centrum, Amsterdam, The Netherlands."; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
54 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
55 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
56 static char* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
57 parser_doc_string |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
58 = "This is an interface to Python's internal parser."; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
59 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
60 static char* |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
61 parser_version_string = "0.5"; |
| 4084 | 62 |
| 63 | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
64 typedef PyObject* (*SeqMaker) (int length); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
65 typedef int (*SeqInserter) (PyObject* sequence, |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
66 int index, |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
67 PyObject* element); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
68 |
|
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
|
69 /* 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
|
70 * 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
|
71 * 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
|
72 * 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
|
73 * 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
|
74 * 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
|
75 * 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
|
76 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
77 |
|
1406
474823e5f7dc
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
79 static PyObject* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
80 node2tuple(node *n, /* node to convert */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
81 SeqMaker mkseq, /* create sequence */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
82 SeqInserter addelem, /* func. to add elem. in seq. */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
83 int lineno) /* include line numbers? */ |
| 4084 | 84 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
85 if (n == NULL) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
86 Py_INCREF(Py_None); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
87 return (Py_None); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
88 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
89 if (ISNONTERMINAL(TYPE(n))) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
90 int i; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
91 PyObject *v; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
92 PyObject *w; |
| 8196 | 93 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
94 v = mkseq(1 + NCH(n)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
95 if (v == NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
96 return (v); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
97 w = PyInt_FromLong(TYPE(n)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
98 if (w == NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
99 Py_DECREF(v); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
100 return ((PyObject*) NULL); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
101 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
102 (void) addelem(v, 0, w); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
103 for (i = 0; i < NCH(n); i++) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
104 w = node2tuple(CHILD(n, i), mkseq, addelem, lineno); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
105 if (w == NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
106 Py_DECREF(v); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
107 return ((PyObject*) NULL); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
108 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
109 (void) addelem(v, i+1, w); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
110 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
111 return (v); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
112 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
113 else if (ISTERMINAL(TYPE(n))) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
114 PyObject *result = mkseq(2 + lineno); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
115 if (result != NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
116 (void) addelem(result, 0, PyInt_FromLong(TYPE(n))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
117 (void) addelem(result, 1, PyString_FromString(STR(n))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
118 if (lineno == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
119 (void) addelem(result, 2, PyInt_FromLong(n->n_lineno)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
120 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
121 return (result); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
122 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
123 else { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
124 PyErr_SetString(PyExc_SystemError, |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
125 "unrecognized parse tree node type"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
126 return ((PyObject*) NULL); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
127 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
128 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
129 /* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
130 * 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
|
131 */ |
|
1406
474823e5f7dc
* parsermodule.c, Makefile, config.c: rudimentary interface to the Python
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
133 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
134 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
135 /* 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
|
136 * '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
|
137 * 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
|
138 * 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
|
139 * 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
|
140 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
141 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
142 #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
|
143 #define PyST_SUITE 2 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
144 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
145 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
146 /* 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
|
147 * 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
|
148 * 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
|
149 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
150 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
151 static PyObject* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
152 parser_error = 0; |
|
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 |
|
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 typedef struct { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
156 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
|
157 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
|
158 int st_type; /* EXPR or SUITE ? */ |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
159 } PyST_Object; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
160 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
161 |
| 8196 | 162 staticforward 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
|
163 parser_free(PyST_Object *st); |
| 8196 | 164 |
| 165 staticforward 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
|
166 parser_compare(PyST_Object *left, PyST_Object *right); |
| 8196 | 167 |
| 168 staticforward PyObject * | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
169 parser_getattr(PyObject *self, char *name); |
| 8196 | 170 |
| 171 | |
| 172 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
|
173 PyTypeObject PyST_Type = { |
|
8450
61912d4ad52f
Sorry, the initializer for ob_type must really be NULL,
Guido van Rossum <guido@python.org>
parents:
8290
diff
changeset
|
174 PyObject_HEAD_INIT(NULL) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
175 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
|
176 "st", /* tp_name */ |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
177 (int) sizeof(PyST_Object), /* tp_basicsize */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
178 0, /* tp_itemsize */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
179 (destructor)parser_free, /* tp_dealloc */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
180 0, /* tp_print */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
181 parser_getattr, /* tp_getattr */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
182 0, /* tp_setattr */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
183 (cmpfunc)parser_compare, /* tp_compare */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
184 0, /* tp_repr */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
185 0, /* tp_as_number */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
186 0, /* tp_as_sequence */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
187 0, /* tp_as_mapping */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
188 0, /* tp_hash */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
189 0, /* tp_call */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
190 0, /* tp_str */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
191 0, /* tp_getattro */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
192 0, /* tp_setattro */ |
|
5613
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
193 |
|
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
194 /* 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
|
195 0, /* tp_as_buffer */ |
|
5613
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
196 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
197 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
5613
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
198 |
|
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
199 /* __doc__ */ |
|
190e35bbc15a
Add doc string to type object.
Fred Drake <fdrake@acm.org>
parents:
5236
diff
changeset
|
200 "Intermediate representation of a Python parse 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
|
201 }; /* PyST_Type */ |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
202 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
203 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
204 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
205 parser_compare_nodes(node *left, node *right) |
| 4084 | 206 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
207 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
208 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
209 if (TYPE(left) < TYPE(right)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
210 return (-1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
211 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
212 if (TYPE(right) < TYPE(left)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
213 return (1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
214 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
215 if (ISTERMINAL(TYPE(left))) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
216 return (strcmp(STR(left), STR(right))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
217 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
218 if (NCH(left) < NCH(right)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
219 return (-1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
220 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
221 if (NCH(right) < NCH(left)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
222 return (1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
223 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
224 for (j = 0; j < NCH(left); ++j) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
225 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
|
226 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
227 if (v != 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
228 return (v); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
229 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
230 return (0); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
231 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
232 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
233 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
234 /* 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
|
235 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
236 * Comparison function used by the Python operators ==, !=, <, >, <=, >= |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
237 * 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
|
238 * checks and protection code. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
239 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
240 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
241 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
|
242 parser_compare(PyST_Object *left, PyST_Object *right) |
| 4084 | 243 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
244 if (left == right) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
245 return (0); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
246 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
247 if ((left == 0) || (right == 0)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
248 return (-1); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
249 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
250 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
|
251 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
252 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
253 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
254 /* parser_newstobject(node* st) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
255 * |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
256 * 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
|
257 * '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
|
258 * Python code. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
259 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
260 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
261 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
|
262 parser_newstobject(node *st, int type) |
| 4084 | 263 { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
264 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
|
265 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
266 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
|
267 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
|
268 o->st_type = type; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
269 } |
| 8196 | 270 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
|
271 PyNode_Free(st); |
| 8196 | 272 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
273 return ((PyObject*)o); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
274 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
275 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
276 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
277 /* void parser_free(PyST_Object* st) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
278 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
279 * 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
|
280 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
281 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
282 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
|
283 parser_free(PyST_Object *st) |
| 4084 | 284 { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
285 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
|
286 PyObject_Del(st); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
287 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
288 |
|
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 /* 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
|
291 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
292 * 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
|
293 * 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
|
294 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
295 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
296 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
|
297 parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 298 { |
| 299 PyObject *line_option = 0; | |
| 300 PyObject *res = 0; | |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
301 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
302 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
303 static char *keywords[] = {"ast", "line_info", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
304 |
| 8196 | 305 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
|
306 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|O:st2tuple", keywords, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
307 &PyST_Type, &self, &line_option); |
| 8196 | 308 } |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
309 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
310 ok = PyArg_ParseTupleAndKeywords(args, kw, "|O:totuple", &keywords[1], |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
311 &line_option); |
| 8196 | 312 if (ok != 0) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
313 int lineno = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
314 if (line_option != NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
315 lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
316 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
317 /* |
|
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 * 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
|
319 * since it's known to work already. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
320 */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
321 res = node2tuple(((PyST_Object*)self)->st_node, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
322 PyTuple_New, PyTuple_SetItem, lineno); |
|
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 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
325 } |
|
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 |
|
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 /* parser_st2list(PyObject* self, PyObject* args, PyObject* kw) |
| 4084 | 329 * |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
330 * 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
|
331 * returned to the Python-level caller. The ST object is not modified. |
| 4084 | 332 * |
| 333 */ | |
| 334 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
|
335 parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 336 { |
| 337 PyObject *line_option = 0; | |
| 338 PyObject *res = 0; | |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
339 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
340 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
341 static char *keywords[] = {"ast", "line_info", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
342 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
343 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
|
344 ok = PyArg_ParseTupleAndKeywords(args, kw, "O!|O:st2list", keywords, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
345 &PyST_Type, &self, &line_option); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
346 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
347 ok = PyArg_ParseTupleAndKeywords(args, kw, "|O:tolist", &keywords[1], |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
348 &line_option); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
349 if (ok) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
350 int lineno = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
351 if (line_option != 0) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
352 lineno = PyObject_IsTrue(line_option) ? 1 : 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
353 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
354 /* |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
355 * 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
|
356 * since it's known to work already. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
357 */ |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
358 res = node2tuple(self->st_node, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
359 PyList_New, PyList_SetItem, lineno); |
| 4084 | 360 } |
| 361 return (res); | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
362 } |
| 4084 | 363 |
| 364 | |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
365 /* parser_compilest(PyObject* self, PyObject* args) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
366 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
367 * 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
|
368 * 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
|
369 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
370 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
371 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
|
372 parser_compilest(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 373 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
374 PyObject* res = 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
|
375 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
|
376 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
377 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
378 static char *keywords[] = {"ast", "filename", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
379 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
380 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
|
381 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
|
382 &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
|
383 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
384 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
|
385 &str); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
386 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
387 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
|
388 res = (PyObject *)PyNode_Compile(self->st_node, str); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
389 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
390 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
391 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
392 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
393 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
394 /* PyObject* parser_isexpr(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
395 * PyObject* parser_issuite(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
396 * |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
397 * 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
|
398 * 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
|
399 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
400 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
401 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
|
402 parser_isexpr(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 403 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
404 PyObject* res = 0; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
405 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
406 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
407 static char *keywords[] = {"ast", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
408 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
409 if (self == NULL) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
410 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
|
411 &PyST_Type, &self); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
412 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
413 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
|
414 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
415 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
|
416 /* 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
|
417 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
|
418 Py_INCREF(res); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
419 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
420 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
421 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
422 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
423 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
424 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
|
425 parser_issuite(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 426 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
427 PyObject* res = 0; |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
428 int ok; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
429 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
430 static char *keywords[] = {"ast", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
431 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
432 if (self == NULL) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
433 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
|
434 &PyST_Type, &self); |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
435 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
436 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
|
437 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
438 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
|
439 /* 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
|
440 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
|
441 Py_INCREF(res); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
442 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
443 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
444 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
445 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
446 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
447 #define PUBLIC_METHOD_TYPE (METH_VARARGS|METH_KEYWORDS) |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
448 |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
449 static PyMethodDef |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
450 parser_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
|
451 {"compile", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
452 "Compile this ST object into a code object."}, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
453 {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_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
|
454 "Determines if this ST object was created from an expression."}, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
455 {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_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
|
456 "Determines if this ST object was created from a suite."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
457 {"tolist", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
458 "Creates a list-tree representation of this ST."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
459 {"totuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
460 "Creates a tuple-tree representation of this ST."}, |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
461 |
| 8196 | 462 {NULL, NULL, 0, NULL} |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
463 }; |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
464 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
465 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
466 static PyObject* |
| 13503 | 467 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
|
468 { |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
469 return (Py_FindMethod(parser_methods, self, name)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
470 } |
|
8039
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
471 |
|
a38550613af3
The documentation threatened it would happen -- the functions that should
Fred Drake <fdrake@acm.org>
parents:
8034
diff
changeset
|
472 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
473 /* err_string(char* message) |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
474 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
475 * 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
|
476 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
477 */ |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
478 static void |
| 13503 | 479 err_string(char *message) |
| 4084 | 480 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
481 PyErr_SetString(parser_error, message); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
482 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
483 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
484 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
485 /* 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
|
486 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
487 * Internal function to actually execute the parse and return the result if |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
488 * successful, or set an exception if not. |
|
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 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
491 static PyObject* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
492 parser_do_parse(PyObject *args, PyObject *kw, char *argspec, int type) |
| 4084 | 493 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
494 char* string = 0; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
495 PyObject* res = 0; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
496 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
497 static char *keywords[] = {"source", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
498 |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
499 if (PyArg_ParseTupleAndKeywords(args, kw, argspec, keywords, &string)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
500 node* n = PyParser_SimpleParseString(string, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
501 (type == PyST_EXPR) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
502 ? eval_input : file_input); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
503 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
504 if (n != 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
|
505 res = parser_newstobject(n, type); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
506 else |
| 15318 | 507 err_string("could not parse string"); |
|
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 /* PyObject* parser_expr(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
514 * PyObject* parser_suite(PyObject* self, PyObject* args) |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
515 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
516 * 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
|
517 * 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
|
518 * 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
|
519 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
520 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
521 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
|
522 parser_expr(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 523 { |
| 8196 | 524 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
|
525 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
|
526 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
527 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
528 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
529 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
|
530 parser_suite(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 531 { |
| 8196 | 532 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
|
533 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
|
534 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
535 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
536 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
537 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
538 /* 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
|
539 * 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
|
540 * 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
|
541 * 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
|
542 * 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
|
543 * 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
|
544 * phase, returning an exception instead. |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
545 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
546 * 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
|
547 * 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
|
548 * 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
|
549 * 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
|
550 * 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
|
551 * 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
|
552 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
553 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
554 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
555 staticforward node* build_node_tree(PyObject *tuple); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
556 staticforward int validate_expr_tree(node *tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
557 staticforward int validate_file_input(node *tree); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
558 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
559 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
560 /* 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
|
561 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
562 * 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
|
563 * 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
|
564 * 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
|
565 * 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
|
566 * 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
|
567 * 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
|
568 * |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
569 * 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
|
570 * ST objects. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
571 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
572 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
573 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
|
574 parser_tuple2st(PyST_Object *self, PyObject *args, PyObject *kw) |
| 4084 | 575 { |
| 8196 | 576 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
|
577 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
|
578 PyObject *tuple; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
579 node *tree; |
| 4084 | 580 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
581 static char *keywords[] = {"sequence", NULL}; |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
582 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
583 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
|
584 &tuple)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
585 return (0); |
| 4084 | 586 if (!PySequence_Check(tuple)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
587 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
|
588 "sequence2st() requires a single sequence argument"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
589 return (0); |
| 4084 | 590 } |
| 591 /* | |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
592 * Convert the tree to the internal form before checking it. |
| 4084 | 593 */ |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 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
|
598 /* 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
|
599 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
|
600 st = parser_newstobject(tree, PyST_EXPR); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
601 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
602 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
|
603 /* 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
|
604 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
|
605 st = parser_newstobject(tree, PyST_SUITE); |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
606 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
607 else { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
608 /* 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
|
609 PyNode_Free(tree); |
| 15318 | 610 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
|
611 } |
| 4084 | 612 } |
| 613 /* Make sure we throw an exception on all errors. We should never | |
| 614 * get this, but we'd do well to be sure something is done. | |
| 615 */ | |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
616 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
|
617 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
|
618 |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
619 return st; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
620 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
621 |
|
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 /* node* build_node_children() |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
624 * |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
625 * 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
|
626 * 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
|
627 * 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
|
628 * and no memory will have been deallocated. |
|
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 static node* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
632 build_node_children(PyObject *tuple, node *root, int *line_num) |
| 4084 | 633 { |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13503
diff
changeset
|
634 int len = PyObject_Size(tuple); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
635 int i; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
636 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
637 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
|
638 /* 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
|
639 PyObject* elem = PySequence_GetItem(tuple, i); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
640 int ok = elem != NULL; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
641 long type = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
642 char *strn = 0; |
| 4084 | 643 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
644 if (ok) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
645 ok = PySequence_Check(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
646 if (ok) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
647 PyObject *temp = PySequence_GetItem(elem, 0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
648 if (temp == NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
649 ok = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
650 else { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
651 ok = PyInt_Check(temp); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
652 if (ok) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
653 type = PyInt_AS_LONG(temp); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
654 Py_DECREF(temp); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
655 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
656 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
657 if (!ok) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
658 PyErr_SetObject(parser_error, |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
659 Py_BuildValue("os", elem, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
660 "Illegal node construct.")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
661 Py_XDECREF(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
662 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
663 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
664 if (ISTERMINAL(type)) { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
665 int len = PyObject_Size(elem); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
666 PyObject *temp; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
667 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
668 if ((len != 2) && (len != 3)) { |
| 15318 | 669 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
|
670 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
671 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
672 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
|
673 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
|
674 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
675 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
|
676 PyErr_Format(parser_error, |
| 15318 | 677 "second item in terminal node must be a string," |
| 678 " found %s", | |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
679 ((PyTypeObject*)PyObject_Type(temp))->tp_name); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12487
diff
changeset
|
680 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
|
681 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
682 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
683 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
|
684 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
|
685 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
|
686 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
|
687 *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
|
688 else { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
689 PyErr_Format(parser_error, |
| 15318 | 690 "third item in terminal node must be an" |
| 691 " integer, found %s", | |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
692 ((PyTypeObject*)PyObject_Type(temp))->tp_name); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
693 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
|
694 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
|
695 return 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
696 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
697 Py_DECREF(o); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
698 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
699 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
700 len = PyString_GET_SIZE(temp) + 1; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
701 strn = (char *)PyMem_MALLOC(len); |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
702 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
|
703 (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
|
704 Py_DECREF(temp); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
705 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
706 else if (!ISNONTERMINAL(type)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
707 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
708 * It has to be one or the other; this is an error. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
709 * Throw an exception. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
710 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
711 PyErr_SetObject(parser_error, |
| 15318 | 712 Py_BuildValue("os", elem, "unknown node type.")); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
713 Py_XDECREF(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
714 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
715 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
716 PyNode_AddChild(root, type, strn, *line_num); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
717 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
718 if (ISNONTERMINAL(type)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
719 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
|
720 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
721 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
|
722 Py_XDECREF(elem); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
723 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
724 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
725 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
726 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
|
727 ++(*line_num); /* line number *after* the newline! */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
728 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
729 Py_XDECREF(elem); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
730 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
731 return (root); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
732 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
733 |
|
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 static node* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
736 build_node_tree(PyObject *tuple) |
| 4084 | 737 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
738 node* res = 0; |
| 4084 | 739 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
|
740 long num = -1; |
| 4084 | 741 |
| 742 if (temp != NULL) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
743 num = PyInt_AsLong(temp); |
| 4084 | 744 Py_XDECREF(temp); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
745 if (ISTERMINAL(num)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
746 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
747 * The tuple is simple, but it doesn't start with a start symbol. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
748 * Throw an exception now and be done with it. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
749 */ |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
750 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
|
751 "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
|
752 PyErr_SetObject(parser_error, tuple); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
753 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
754 else if (ISNONTERMINAL(num)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
755 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
756 * Not efficient, but that can be handled later. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
757 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
758 int line_num = 0; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
759 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
760 res = PyNode_New(num); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
761 if (res != build_node_children(tuple, res, &line_num)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
762 PyNode_Free(res); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
763 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
764 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
765 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
766 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
767 /* 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
|
768 * 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
|
769 * 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
|
770 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
771 PyErr_SetObject(parser_error, |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
772 Py_BuildValue("os", tuple, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
773 "Illegal component tuple.")); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
774 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
775 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
776 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
777 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
778 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
779 /* |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
780 * Validation routines used within the validation section: |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
781 */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
782 staticforward 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
|
783 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
784 #define validate_ampersand(ch) validate_terminal(ch, AMPER, "&") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
785 #define validate_circumflex(ch) validate_terminal(ch, CIRCUMFLEX, "^") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
786 #define validate_colon(ch) validate_terminal(ch, COLON, ":") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
787 #define validate_comma(ch) validate_terminal(ch, COMMA, ",") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
788 #define validate_dedent(ch) validate_terminal(ch, DEDENT, "") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
789 #define validate_equal(ch) validate_terminal(ch, EQUAL, "=") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
790 #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
|
791 #define validate_lparen(ch) validate_terminal(ch, LPAR, "(") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
792 #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
|
793 #define validate_rparen(ch) validate_terminal(ch, RPAR, ")") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
794 #define validate_semi(ch) validate_terminal(ch, SEMI, ";") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
795 #define validate_star(ch) validate_terminal(ch, STAR, "*") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
796 #define validate_vbar(ch) validate_terminal(ch, VBAR, "|") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
797 #define validate_doublestar(ch) validate_terminal(ch, DOUBLESTAR, "**") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
798 #define validate_dot(ch) validate_terminal(ch, DOT, ".") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
799 #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
|
800 |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
801 #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
|
802 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
803 VALIDATER(node); VALIDATER(small_stmt); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
804 VALIDATER(class); VALIDATER(node); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
805 VALIDATER(parameters); VALIDATER(suite); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
806 VALIDATER(testlist); VALIDATER(varargslist); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
807 VALIDATER(fpdef); VALIDATER(fplist); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
808 VALIDATER(stmt); VALIDATER(simple_stmt); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
809 VALIDATER(expr_stmt); VALIDATER(power); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
810 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
|
811 VALIDATER(return_stmt); VALIDATER(list_iter); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
812 VALIDATER(raise_stmt); VALIDATER(import_stmt); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
813 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
|
814 VALIDATER(assert_stmt); VALIDATER(list_for); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
815 VALIDATER(exec_stmt); VALIDATER(compound_stmt); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
816 VALIDATER(while); VALIDATER(for); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
817 VALIDATER(try); VALIDATER(except_clause); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
818 VALIDATER(test); VALIDATER(and_test); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
819 VALIDATER(not_test); VALIDATER(comparison); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
820 VALIDATER(comp_op); VALIDATER(expr); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
821 VALIDATER(xor_expr); VALIDATER(and_expr); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
822 VALIDATER(shift_expr); VALIDATER(arith_expr); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
823 VALIDATER(term); VALIDATER(factor); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
824 VALIDATER(atom); VALIDATER(lambdef); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
825 VALIDATER(trailer); VALIDATER(subscript); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
826 VALIDATER(subscriptlist); VALIDATER(sliceop); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
827 VALIDATER(exprlist); VALIDATER(dictmaker); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
828 VALIDATER(arglist); VALIDATER(argument); |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
829 VALIDATER(listmaker); VALIDATER(yield_stmt); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
830 |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
831 #undef VALIDATER |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
832 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
833 #define is_even(n) (((n) & 1) == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
834 #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
|
835 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
836 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
837 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
838 validate_ntype(node *n, int t) |
| 4084 | 839 { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
840 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
|
841 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
|
842 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
|
843 return 0; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
844 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
845 return 1; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
846 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
847 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
848 |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
849 /* 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
|
850 * 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
|
851 * 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
|
852 * "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
|
853 * 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
|
854 * in that fashion. |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
855 */ |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
856 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
857 validate_numnodes(node *n, int num, const char *const name) |
| 4084 | 858 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
859 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
|
860 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
|
861 "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
|
862 return 0; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
863 } |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
864 return 1; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
865 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
866 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
867 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
868 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
869 validate_terminal(node *terminal, int type, char *string) |
| 4084 | 870 { |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
871 int res = (validate_ntype(terminal, type) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
872 && ((string == 0) || (strcmp(string, STR(terminal)) == 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
873 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
874 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
|
875 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
|
876 "Illegal terminal: expected \"%s\"", string); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
877 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
878 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
879 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
880 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
881 |
| 4084 | 882 /* X (',' X) [','] |
| 883 */ | |
| 884 static int | |
|
13667
a6c7bfdd6777
Even more ANSIfication: fix as many function pointers and declarations as
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
885 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
|
886 const char *const name) |
| 4084 | 887 { |
| 888 int nch = NCH(tree); | |
| 889 int res = (nch && validate_ntype(tree, ntype) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
890 && vfunc(CHILD(tree, 0))); |
| 4084 | 891 |
| 892 if (!res && !PyErr_Occurred()) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
893 (void) validate_numnodes(tree, 1, name); |
| 4084 | 894 else { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
895 if (is_even(nch)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
896 res = validate_comma(CHILD(tree, --nch)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
897 if (res && nch > 1) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
898 int pos = 1; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
899 for ( ; res && pos < nch; pos += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
900 res = (validate_comma(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
901 && vfunc(CHILD(tree, pos + 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
902 } |
| 4084 | 903 } |
| 904 return (res); | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
905 } |
| 4084 | 906 |
| 907 | |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
908 /* validate_class() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
909 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
910 * classdef: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
911 * 'class' NAME ['(' testlist ')'] ':' suite |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
912 */ |
| 4084 | 913 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
914 validate_class(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
915 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
916 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
917 int res = validate_ntype(tree, classdef) && ((nch == 4) || (nch == 7)); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
918 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
919 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
920 res = (validate_name(CHILD(tree, 0), "class") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
921 && validate_ntype(CHILD(tree, 1), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
922 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
923 && validate_suite(CHILD(tree, nch - 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
924 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
925 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
926 (void) validate_numnodes(tree, 4, "class"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
927 if (res && (nch == 7)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
928 res = (validate_lparen(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
929 && validate_testlist(CHILD(tree, 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
930 && validate_rparen(CHILD(tree, 4))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
931 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
932 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
933 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
934 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
935 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
936 /* if_stmt: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
937 * '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
|
938 */ |
| 4084 | 939 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
940 validate_if(node *tree) |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
941 { |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
942 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
943 int res = (validate_ntype(tree, if_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
944 && (nch >= 4) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
945 && validate_name(CHILD(tree, 0), "if") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
946 && validate_test(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
947 && validate_colon(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
948 && validate_suite(CHILD(tree, 3))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
949 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
950 if (res && ((nch % 4) == 3)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
951 /* ... 'else' ':' suite */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
952 res = (validate_name(CHILD(tree, nch - 3), "else") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
953 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
954 && validate_suite(CHILD(tree, nch - 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
955 nch -= 3; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
956 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
957 else if (!res && !PyErr_Occurred()) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
958 (void) validate_numnodes(tree, 4, "if"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
959 if ((nch % 4) != 0) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
960 /* Will catch the case for nch < 4 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
961 res = validate_numnodes(tree, 0, "if"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
962 else if (res && (nch > 4)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
963 /* ... ('elif' test ':' suite)+ ... */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
964 int j = 4; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
965 while ((j < nch) && res) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
966 res = (validate_name(CHILD(tree, j), "elif") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
967 && validate_colon(CHILD(tree, j + 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
968 && validate_test(CHILD(tree, j + 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
969 && validate_suite(CHILD(tree, j + 3))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
970 j += 4; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
971 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
972 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
973 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
974 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
975 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
976 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
977 /* parameters: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
978 * '(' [varargslist] ')' |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
979 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
980 */ |
| 4084 | 981 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
982 validate_parameters(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
983 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
984 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
985 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
|
986 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
987 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
988 res = (validate_lparen(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
989 && validate_rparen(CHILD(tree, nch - 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
990 if (res && (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
991 res = validate_varargslist(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
992 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
993 else { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
994 (void) validate_numnodes(tree, 2, "parameters"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
995 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
996 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
997 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
998 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
999 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1000 /* validate_suite() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1001 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1002 * suite: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1003 * simple_stmt |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1004 * | NEWLINE INDENT stmt+ DEDENT |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1005 */ |
| 4084 | 1006 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1007 validate_suite(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1008 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1009 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1010 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
|
1011 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1012 if (res && (nch == 1)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1013 res = validate_simple_stmt(CHILD(tree, 0)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1014 else if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1015 /* NEWLINE INDENT stmt+ DEDENT */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1016 res = (validate_newline(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1017 && validate_indent(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1018 && validate_stmt(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1019 && validate_dedent(CHILD(tree, nch - 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1020 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1021 if (res && (nch > 4)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1022 int i = 3; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1023 --nch; /* forget the DEDENT */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1024 for ( ; res && (i < nch); ++i) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1025 res = validate_stmt(CHILD(tree, i)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1026 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1027 else if (nch < 4) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1028 res = validate_numnodes(tree, 4, "suite"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1029 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1030 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1031 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1032 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1033 |
| 4084 | 1034 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1035 validate_testlist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1036 { |
| 4084 | 1037 return (validate_repeating_list(tree, testlist, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1038 validate_test, "testlist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1039 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1040 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1041 |
|
20432
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1042 static int |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1043 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
|
1044 { |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1045 return (validate_repeating_list(tree, testlist_safe, |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1046 validate_test, "testlist_safe")); |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1047 } |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1048 |
|
56141b86a7f2
Very subtle syntax change: in a list comprehension, the testlist in
Guido van Rossum <guido@python.org>
parents:
19274
diff
changeset
|
1049 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1050 /* '*' NAME [',' '**' NAME] | '**' NAME |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1051 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1052 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1053 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
|
1054 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1055 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1056 int res = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1057 int sym; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1058 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1059 if (nch <= start) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1060 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
|
1061 return 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1062 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1063 sym = TYPE(CHILD(tree, start)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1064 if (sym == STAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1065 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1066 * ('*' NAME [',' '**' NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1067 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1068 if (nch-start == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1069 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
|
1070 else if (nch-start == 5) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1071 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
|
1072 && 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
|
1073 && 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
|
1074 && 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
|
1075 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1076 else if (sym == DOUBLESTAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1077 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1078 * '**' NAME |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1079 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1080 if (nch-start == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1081 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
|
1082 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1083 if (!res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1084 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
|
1085 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1086 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1087 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1088 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1089 /* validate_varargslist() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1090 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1091 * varargslist: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1092 * (fpdef ['=' test] ',')* |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1093 * ('*' NAME [',' '**' NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1094 * | '**' NAME) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1095 * | fpdef ['=' test] (',' fpdef ['=' test])* [','] |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1096 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1097 */ |
| 4084 | 1098 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1099 validate_varargslist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1100 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1101 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1102 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
|
1103 int sym; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1104 |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1105 if (!res) |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1106 return 0; |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1107 if (nch < 1) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1108 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
|
1109 return 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1110 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1111 sym = TYPE(CHILD(tree, 0)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1112 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
|
1113 /* whole thing matches: |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1114 * '*' NAME [',' '**' NAME] | '**' NAME |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1115 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1116 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
|
1117 else if (sym == fpdef) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1118 int i = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1119 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1120 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
|
1121 if (sym == NAME) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1122 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1123 * (fpdef ['=' test] ',')+ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1124 * ('*' NAME [',' '**' NAME] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1125 * | '**' NAME) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1126 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1127 /* skip over (fpdef ['=' test] ',')+ */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1128 while (res && (i+2 <= nch)) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1129 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
|
1130 ++i; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1131 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
|
1132 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
|
1133 && 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
|
1134 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1135 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1136 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1137 if (res && i < nch) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1138 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
|
1139 ++i; |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1140 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
|
1141 && (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
|
1142 || 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
|
1143 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1144 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1145 } |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1146 /* ... '*' NAME [',' '**' NAME] | '**' NAME |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1147 * i --^^^ |
|
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1148 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1149 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1150 res = validate_varargslist_trailer(tree, i); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1151 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1152 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1153 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1154 * fpdef ['=' test] (',' fpdef ['=' test])* [','] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1155 */ |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1156 /* strip trailing comma node */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1157 if (sym == COMMA) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1158 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
|
1159 if (!res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1160 return 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1161 --nch; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1162 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1163 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1164 * fpdef ['=' test] (',' fpdef ['=' test])* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1165 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1166 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
|
1167 ++i; |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1168 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
|
1169 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
|
1170 && 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
|
1171 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1172 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1173 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1174 * ... (',' fpdef ['=' test])* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1175 * i ---^^^ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1176 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1177 while (res && (nch - i) >= 2) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1178 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
|
1179 && 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
|
1180 i += 2; |
|
15506
ac830c9e9a83
validate_varargslist(): Fix two bugs in this function, one that affected
Fred Drake <fdrake@acm.org>
parents:
15318
diff
changeset
|
1181 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
|
1182 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
|
1183 && 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
|
1184 i += 2; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1185 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1186 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1187 if (res && nch - i != 0) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1188 res = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1189 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
|
1190 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1191 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1192 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1193 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1194 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1195 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1196 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1197 /* 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
|
1198 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1199 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1200 validate_list_iter(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1201 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1202 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
|
1203 && 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
|
1204 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
|
1205 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
|
1206 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1207 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
|
1208 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1209 return res; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1210 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1211 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1212 /* 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
|
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_list_for(node *tree) |
|
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; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1219 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1220 if (nch == 5) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1221 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
|
1222 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1223 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
|
1224 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1225 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1226 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
|
1227 && validate_exprlist(CHILD(tree, 1)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1228 && 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
|
1229 && 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
|
1230 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1231 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1232 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1233 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1234 /* list_if: 'if' test [list_iter] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1235 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1236 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1237 validate_list_if(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1238 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1239 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1240 int res; |
|
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 == 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1243 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
|
1244 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1245 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
|
1246 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1247 if (res) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1248 res = (validate_name(CHILD(tree, 0), "if") |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1249 && validate_test(CHILD(tree, 1))); |
|
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 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1252 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1253 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1254 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1255 /* validate_fpdef() |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1256 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1257 * fpdef: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1258 * NAME |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1259 * | '(' fplist ')' |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1260 */ |
| 4084 | 1261 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1262 validate_fpdef(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1263 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1264 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1265 int res = validate_ntype(tree, fpdef); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1266 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1267 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1268 if (nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1269 res = validate_ntype(CHILD(tree, 0), NAME); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1270 else if (nch == 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1271 res = (validate_lparen(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1272 && validate_fplist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1273 && validate_rparen(CHILD(tree, 2))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1274 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1275 res = validate_numnodes(tree, 1, "fpdef"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1276 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1277 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1278 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1279 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1280 |
| 4084 | 1281 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1282 validate_fplist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1283 { |
| 4084 | 1284 return (validate_repeating_list(tree, fplist, |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1285 validate_fpdef, "fplist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1286 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1287 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1288 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1289 /* simple_stmt | compound_stmt |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1290 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1291 */ |
| 4084 | 1292 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1293 validate_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1294 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1295 int res = (validate_ntype(tree, stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1296 && validate_numnodes(tree, 1, "stmt")); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1297 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1298 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1299 tree = CHILD(tree, 0); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1300 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1301 if (TYPE(tree) == simple_stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1302 res = validate_simple_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1303 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1304 res = validate_compound_stmt(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1305 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1306 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1307 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1308 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1309 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1310 /* small_stmt (';' small_stmt)* [';'] NEWLINE |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1311 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1312 */ |
| 4084 | 1313 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1314 validate_simple_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1315 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1316 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1317 int res = (validate_ntype(tree, simple_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1318 && (nch >= 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1319 && validate_small_stmt(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1320 && validate_newline(CHILD(tree, nch - 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1321 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1322 if (nch < 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1323 res = validate_numnodes(tree, 2, "simple_stmt"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1324 --nch; /* forget the NEWLINE */ |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1325 if (res && is_even(nch)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1326 res = validate_semi(CHILD(tree, --nch)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1327 if (res && (nch > 2)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1328 int i; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1329 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1330 for (i = 1; res && (i < nch); i += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1331 res = (validate_semi(CHILD(tree, i)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1332 && 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
|
1333 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1334 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1335 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1336 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1337 |
| 4084 | 1338 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1339 validate_small_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1340 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1341 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
|
1342 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
|
1343 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1344 if (res) { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1345 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
|
1346 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1347 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
|
1348 || (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
|
1349 || (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
|
1350 || (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
|
1351 || (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
|
1352 || (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
|
1353 || (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
|
1354 || (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
|
1355 || (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
|
1356 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
|
1357 else { |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1358 res = 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1359 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
|
1360 } |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1361 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1362 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
|
1363 res = 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1364 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
|
1365 "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
|
1366 TYPE(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1367 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1368 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1369 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1370 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1371 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1372 /* compound_stmt: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1373 * if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1374 */ |
| 4084 | 1375 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1376 validate_compound_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1377 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1378 int res = (validate_ntype(tree, compound_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1379 && 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
|
1380 int ntype; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1381 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1382 if (!res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1383 return (0); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1384 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1385 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
|
1386 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
|
1387 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
|
1388 || (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
|
1389 || (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
|
1390 || (ntype == try_stmt) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1391 || (ntype == funcdef) |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1392 || (ntype == classdef)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1393 res = validate_node(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1394 else { |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1395 res = 0; |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1396 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
|
1397 "Illegal compound statement type: %d.", TYPE(tree)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1398 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1399 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1400 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1401 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1402 |
| 4084 | 1403 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1404 validate_expr_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1405 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1406 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1407 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1408 int res = (validate_ntype(tree, expr_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1409 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1410 && validate_testlist(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1411 |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1412 if (res && nch == 3 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1413 && TYPE(CHILD(tree, 1)) == augassign) { |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1414 res = (validate_numnodes(CHILD(tree, 1), 1, "augassign") |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1415 && validate_testlist(CHILD(tree, 2))); |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1416 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1417 if (res) { |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1418 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
|
1419 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1420 res = (strcmp(s, "+=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1421 || strcmp(s, "-=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1422 || strcmp(s, "*=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1423 || strcmp(s, "/=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1424 || strcmp(s, "%=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1425 || strcmp(s, "&=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1426 || strcmp(s, "|=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1427 || strcmp(s, "^=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1428 || strcmp(s, "<<=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1429 || strcmp(s, ">>=") == 0 |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1430 || strcmp(s, "**=") == 0); |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1431 if (!res) |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1432 err_string("illegal augmmented assignment operator"); |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1433 } |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1434 } |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1435 else { |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1436 for (j = 1; res && (j < nch); j += 2) |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1437 res = (validate_equal(CHILD(tree, j)) |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1438 && validate_testlist(CHILD(tree, j + 1))); |
|
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
1439 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1440 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1441 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1442 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1443 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1444 /* print_stmt: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1445 * |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1446 * 'print' ( [ test (',' test)* [','] ] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1447 * | '>>' test [ (',' test)+ [','] ] ) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1448 */ |
| 4084 | 1449 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1450 validate_print_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1451 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1452 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1453 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
|
1454 && (nch > 0) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1455 && validate_name(CHILD(tree, 0), "print")); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1456 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1457 if (res && nch > 1) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1458 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
|
1459 int i = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1460 int allow_trailing_comma = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1461 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1462 if (sym == test) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1463 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
|
1464 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1465 if (nch < 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1466 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
|
1467 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1468 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
|
1469 && 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
|
1470 i += 2; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1471 allow_trailing_comma = 0; |
|
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 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1474 if (res) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1475 /* ... (',' test)* [','] */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1476 while (res && i+2 <= nch) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1477 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
|
1478 && 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
|
1479 allow_trailing_comma = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1480 i += 2; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1481 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1482 if (res && !allow_trailing_comma) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1483 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
|
1484 else if (res && i < nch) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1485 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
|
1486 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1487 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1488 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1489 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1490 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1491 |
| 4084 | 1492 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1493 validate_del_stmt(node *tree) |
|
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 (validate_numnodes(tree, 2, "del_stmt") |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1496 && validate_name(CHILD(tree, 0), "del") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1497 && validate_exprlist(CHILD(tree, 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1498 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1499 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1500 |
| 4084 | 1501 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1502 validate_return_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1503 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1504 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1505 int res = (validate_ntype(tree, return_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1506 && ((nch == 1) || (nch == 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1507 && validate_name(CHILD(tree, 0), "return")); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1508 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1509 if (res && (nch == 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1510 res = validate_testlist(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1511 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1512 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1513 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1514 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1515 |
| 4084 | 1516 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1517 validate_raise_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1518 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1519 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1520 int res = (validate_ntype(tree, raise_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1521 && ((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
|
1522 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1523 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1524 res = validate_name(CHILD(tree, 0), "raise"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1525 if (res && (nch >= 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1526 res = validate_test(CHILD(tree, 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1527 if (res && nch > 2) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1528 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1529 && validate_test(CHILD(tree, 3))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1530 if (res && (nch > 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1531 res = (validate_comma(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1532 && validate_test(CHILD(tree, 5))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1533 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1534 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1535 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1536 (void) validate_numnodes(tree, 2, "raise"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1537 if (res && (nch == 4)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1538 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1539 && validate_test(CHILD(tree, 3))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1540 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1541 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1542 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1543 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1544 |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1545 /* yield_stmt: 'yield' testlist |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1546 */ |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1547 static int |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1548 validate_yield_stmt(node *tree) |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1549 { |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1550 return (validate_ntype(tree, yield_stmt) |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1551 && validate_numnodes(tree, 2, "yield_stmt") |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1552 && validate_name(CHILD(tree, 0), "yield") |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1553 && validate_testlist(CHILD(tree, 1))); |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1554 } |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1555 |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
1556 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1557 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1558 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
|
1559 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1560 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1561 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
|
1562 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1563 if (ok) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1564 if (nch == 1) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1565 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
|
1566 else if (nch == 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1567 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
|
1568 && 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
|
1569 && 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
|
1570 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1571 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
|
1572 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1573 return ok; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1574 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1575 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1576 |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1577 /* dotted_name: NAME ("." NAME)* |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1578 */ |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1579 static int |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1580 validate_dotted_name(node *tree) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1581 { |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1582 int nch = NCH(tree); |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1583 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
|
1584 && is_odd(nch) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1585 && 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
|
1586 int i; |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1587 |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1588 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
|
1589 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
|
1590 && 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
|
1591 } |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1592 return res; |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1593 } |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1594 |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1595 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1596 /* 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
|
1597 */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1598 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1599 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
|
1600 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1601 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1602 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
|
1603 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1604 if (res) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1605 if (nch == 1) |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1606 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
|
1607 else if (nch == 3) |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1608 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
|
1609 && 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
|
1610 && 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
|
1611 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1612 res = 0; |
| 15318 | 1613 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
|
1614 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1615 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1616 return res; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1617 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1618 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1619 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1620 /* import_stmt: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1621 * |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1622 * 'import' dotted_as_name (',' dotted_as_name)* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1623 * | 'from' dotted_name 'import' ('*' | import_as_name (',' import_as_name)*) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1624 */ |
| 4084 | 1625 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1626 validate_import_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1627 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1628 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1629 int res = (validate_ntype(tree, import_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1630 && (nch >= 2) && is_even(nch) |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1631 && validate_ntype(CHILD(tree, 0), NAME)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1632 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1633 if (res && (strcmp(STR(CHILD(tree, 0)), "import") == 0)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1634 int j; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1635 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1636 res = validate_dotted_as_name(CHILD(tree, 1)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1637 for (j = 2; res && (j < nch); j += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1638 res = (validate_comma(CHILD(tree, j)) |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1639 && validate_dotted_as_name(CHILD(tree, j + 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1640 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1641 else if (res && (res = validate_name(CHILD(tree, 0), "from"))) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1642 res = ((nch >= 4) && is_even(nch) |
|
15751
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1643 && validate_dotted_name(CHILD(tree, 1)) |
|
939b8fffc452
Fix problems with validation of import statement parse trees.
Fred Drake <fdrake@acm.org>
parents:
15506
diff
changeset
|
1644 && validate_name(CHILD(tree, 2), "import")); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1645 if (nch == 4) { |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1646 if (TYPE(CHILD(tree, 3)) == import_as_name) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1647 res = validate_import_as_name(CHILD(tree, 3)); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1648 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1649 res = validate_star(CHILD(tree, 3)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1650 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1651 else { |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1652 /* 'from' dotted_name 'import' import_as_name |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1653 * (',' import_as_name)+ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1654 */ |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1655 int j; |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1656 res = validate_import_as_name(CHILD(tree, 3)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1657 for (j = 4; res && (j < nch); j += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1658 res = (validate_comma(CHILD(tree, j)) |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
1659 && validate_import_as_name(CHILD(tree, j + 1))); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1660 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1661 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1662 else |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1663 res = 0; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1664 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1665 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1666 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1667 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1668 |
| 4084 | 1669 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1670 validate_global_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1671 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1672 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1673 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1674 int res = (validate_ntype(tree, global_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1675 && is_even(nch) && (nch >= 2)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1676 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1677 if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1678 res = (validate_name(CHILD(tree, 0), "global") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1679 && validate_ntype(CHILD(tree, 1), NAME)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1680 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
|
1681 res = (validate_comma(CHILD(tree, j)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1682 && validate_ntype(CHILD(tree, j + 1), NAME)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1683 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1684 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1685 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1686 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1687 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1688 /* exec_stmt: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1689 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1690 * 'exec' expr ['in' test [',' test]] |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1691 */ |
| 4084 | 1692 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1693 validate_exec_stmt(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1694 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1695 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1696 int res = (validate_ntype(tree, exec_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1697 && ((nch == 2) || (nch == 4) || (nch == 6)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1698 && validate_name(CHILD(tree, 0), "exec") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1699 && validate_expr(CHILD(tree, 1))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1700 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1701 if (!res && !PyErr_Occurred()) |
| 15318 | 1702 err_string("illegal exec statement"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1703 if (res && (nch > 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1704 res = (validate_name(CHILD(tree, 2), "in") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1705 && validate_test(CHILD(tree, 3))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1706 if (res && (nch == 6)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1707 res = (validate_comma(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1708 && validate_test(CHILD(tree, 5))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1709 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1710 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1711 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1712 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1713 |
| 5236 | 1714 /* assert_stmt: |
| 1715 * | |
| 1716 * 'assert' test [',' test] | |
| 1717 */ | |
| 1718 static int | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1719 validate_assert_stmt(node *tree) |
| 5236 | 1720 { |
| 1721 int nch = NCH(tree); | |
| 1722 int res = (validate_ntype(tree, assert_stmt) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1723 && ((nch == 2) || (nch == 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1724 && (validate_name(CHILD(tree, 0), "__assert__") || |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1725 validate_name(CHILD(tree, 0), "assert")) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1726 && validate_test(CHILD(tree, 1))); |
| 5236 | 1727 |
| 1728 if (!res && !PyErr_Occurred()) | |
| 15318 | 1729 err_string("illegal assert statement"); |
| 5236 | 1730 if (res && (nch > 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1731 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1732 && validate_test(CHILD(tree, 3))); |
| 5236 | 1733 |
| 1734 return (res); | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1735 } |
| 5236 | 1736 |
| 1737 | |
| 4084 | 1738 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1739 validate_while(node *tree) |
|
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 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1742 int res = (validate_ntype(tree, while_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1743 && ((nch == 4) || (nch == 7)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1744 && validate_name(CHILD(tree, 0), "while") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1745 && validate_test(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1746 && validate_colon(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1747 && validate_suite(CHILD(tree, 3))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1748 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1749 if (res && (nch == 7)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1750 res = (validate_name(CHILD(tree, 4), "else") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1751 && validate_colon(CHILD(tree, 5)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1752 && validate_suite(CHILD(tree, 6))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1753 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1754 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1755 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1756 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1757 |
| 4084 | 1758 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1759 validate_for(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1760 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1761 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1762 int res = (validate_ntype(tree, for_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1763 && ((nch == 6) || (nch == 9)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1764 && validate_name(CHILD(tree, 0), "for") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1765 && validate_exprlist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1766 && validate_name(CHILD(tree, 2), "in") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1767 && validate_testlist(CHILD(tree, 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1768 && validate_colon(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1769 && validate_suite(CHILD(tree, 5))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1770 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1771 if (res && (nch == 9)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1772 res = (validate_name(CHILD(tree, 6), "else") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1773 && validate_colon(CHILD(tree, 7)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1774 && validate_suite(CHILD(tree, 8))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1775 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1776 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1777 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1778 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1779 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1780 /* try_stmt: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1781 * 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1782 * | 'try' ':' suite 'finally' ':' suite |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1783 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1784 */ |
| 4084 | 1785 static int |
| 13503 | 1786 validate_try(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1787 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1788 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1789 int pos = 3; |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1790 int res = (validate_ntype(tree, try_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1791 && (nch >= 6) && ((nch % 3) == 0)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1792 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1793 if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1794 res = (validate_name(CHILD(tree, 0), "try") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1795 && validate_colon(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1796 && validate_suite(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1797 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1798 && 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
|
1799 else if (!PyErr_Occurred()) { |
|
13325
7bac10a9bb61
Andrew Kuchling <akuchlin@mems-exchange.org>:
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
1800 const char* name = "except"; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1801 if (TYPE(CHILD(tree, nch - 3)) != except_clause) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1802 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
|
1803 |
|
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
1804 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
|
1805 "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
|
1806 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1807 /* Skip past except_clause sections: */ |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1808 while (res && (TYPE(CHILD(tree, pos)) == except_clause)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1809 res = (validate_except_clause(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1810 && validate_colon(CHILD(tree, pos + 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1811 && validate_suite(CHILD(tree, pos + 2))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1812 pos += 3; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1813 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1814 if (res && (pos < nch)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1815 res = validate_ntype(CHILD(tree, pos), NAME); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1816 if (res && (strcmp(STR(CHILD(tree, pos)), "finally") == 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1817 res = (validate_numnodes(tree, 6, "try/finally") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1818 && validate_colon(CHILD(tree, 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1819 && validate_suite(CHILD(tree, 5))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1820 else if (res) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1821 if (nch == (pos + 3)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1822 res = ((strcmp(STR(CHILD(tree, pos)), "except") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1823 || (strcmp(STR(CHILD(tree, pos)), "else") == 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1824 if (!res) |
| 15318 | 1825 err_string("illegal trailing triple in try statement"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1826 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1827 else if (nch == (pos + 6)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1828 res = (validate_name(CHILD(tree, pos), "except") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1829 && validate_colon(CHILD(tree, pos + 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1830 && validate_suite(CHILD(tree, pos + 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1831 && validate_name(CHILD(tree, pos + 3), "else")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1832 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1833 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1834 res = validate_numnodes(tree, pos + 3, "try/except"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1835 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1836 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1837 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1838 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1839 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1840 |
| 4084 | 1841 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1842 validate_except_clause(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1843 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1844 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1845 int res = (validate_ntype(tree, except_clause) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1846 && ((nch == 1) || (nch == 2) || (nch == 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1847 && validate_name(CHILD(tree, 0), "except")); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1848 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1849 if (res && (nch > 1)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1850 res = validate_test(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1851 if (res && (nch == 4)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1852 res = (validate_comma(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1853 && validate_test(CHILD(tree, 3))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1854 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1855 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1856 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1857 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1858 |
| 4084 | 1859 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1860 validate_test(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1861 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1862 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1863 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
|
1864 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1865 if (res && (TYPE(CHILD(tree, 0)) == lambdef)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1866 res = ((nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1867 && validate_lambdef(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1868 else if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1869 int pos; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1870 res = validate_and_test(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1871 for (pos = 1; res && (pos < nch); pos += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1872 res = (validate_name(CHILD(tree, pos), "or") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1873 && 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
|
1874 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1875 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1876 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1877 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1878 |
| 4084 | 1879 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1880 validate_and_test(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1881 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1882 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1883 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1884 int res = (validate_ntype(tree, and_test) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1885 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1886 && validate_not_test(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1887 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1888 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
|
1889 res = (validate_name(CHILD(tree, pos), "and") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1890 && validate_not_test(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1891 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1892 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1893 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1894 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1895 |
| 4084 | 1896 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1897 validate_not_test(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1898 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1899 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1900 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
|
1901 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1902 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1903 if (nch == 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1904 res = (validate_name(CHILD(tree, 0), "not") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1905 && validate_not_test(CHILD(tree, 1))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1906 else if (nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1907 res = validate_comparison(CHILD(tree, 0)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1908 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1909 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1910 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1911 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1912 |
| 4084 | 1913 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1914 validate_comparison(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1915 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1916 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1917 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1918 int res = (validate_ntype(tree, comparison) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1919 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1920 && validate_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1921 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1922 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
|
1923 res = (validate_comp_op(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1924 && validate_expr(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1925 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1926 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1927 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1928 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1929 |
| 4084 | 1930 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1931 validate_comp_op(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1932 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1933 int res = 0; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1934 int nch = NCH(tree); |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1935 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1936 if (!validate_ntype(tree, comp_op)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1937 return (0); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1938 if (nch == 1) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1939 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1940 * 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
|
1941 * 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
|
1942 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1943 tree = CHILD(tree, 0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1944 switch (TYPE(tree)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1945 case LESS: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1946 case GREATER: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1947 case EQEQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1948 case EQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1949 case LESSEQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1950 case GREATEREQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1951 case NOTEQUAL: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1952 res = 1; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1953 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1954 case NAME: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1955 res = ((strcmp(STR(tree), "in") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1956 || (strcmp(STR(tree), "is") == 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1957 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
|
1958 PyErr_Format(parser_error, |
| 15318 | 1959 "illegal operator '%s'", STR(tree)); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1960 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1961 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1962 default: |
| 15318 | 1963 err_string("illegal comparison operator type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1964 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1965 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1966 } |
| 4600 | 1967 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
|
1968 res = (validate_ntype(CHILD(tree, 0), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1969 && validate_ntype(CHILD(tree, 1), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1970 && (((strcmp(STR(CHILD(tree, 0)), "is") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1971 && (strcmp(STR(CHILD(tree, 1)), "not") == 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1972 || ((strcmp(STR(CHILD(tree, 0)), "not") == 0) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1973 && (strcmp(STR(CHILD(tree, 1)), "in") == 0)))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1974 if (!res && !PyErr_Occurred()) |
| 15318 | 1975 err_string("unknown comparison operator"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1976 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1977 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1978 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1979 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1980 |
| 4084 | 1981 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1982 validate_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1983 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1984 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1985 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1986 int res = (validate_ntype(tree, expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1987 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1988 && validate_xor_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1989 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1990 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
|
1991 res = (validate_xor_expr(CHILD(tree, j)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1992 && validate_vbar(CHILD(tree, j - 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
1993 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1994 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1995 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1996 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
1997 |
| 4084 | 1998 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
1999 validate_xor_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2000 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2001 int j; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2002 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2003 int res = (validate_ntype(tree, xor_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2004 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2005 && validate_and_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2006 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2007 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
|
2008 res = (validate_circumflex(CHILD(tree, j - 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2009 && validate_and_expr(CHILD(tree, j))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2010 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2011 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2012 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2013 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2014 |
| 4084 | 2015 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2016 validate_and_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2017 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2018 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2019 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2020 int res = (validate_ntype(tree, and_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2021 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2022 && validate_shift_expr(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2023 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2024 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
|
2025 res = (validate_ampersand(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2026 && validate_shift_expr(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2027 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2028 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2029 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2030 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2031 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2032 static int |
| 13503 | 2033 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
|
2034 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2035 int pos = 1; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2036 int nch = NCH(tree); |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2037 int res = (is_odd(nch) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2038 && (*termvalid)(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2039 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2040 for ( ; res && (pos < nch); pos += 2) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2041 if (TYPE(CHILD(tree, pos)) != op1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2042 res = validate_ntype(CHILD(tree, pos), op2); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2043 if (res) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2044 res = (*termvalid)(CHILD(tree, pos + 1)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2045 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2046 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2047 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2048 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2049 |
| 4084 | 2050 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2051 validate_shift_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2052 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2053 return (validate_ntype(tree, shift_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2054 && validate_chain_two_ops(tree, validate_arith_expr, |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2055 LEFTSHIFT, RIGHTSHIFT)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2056 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2057 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2058 |
| 4084 | 2059 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2060 validate_arith_expr(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2061 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2062 return (validate_ntype(tree, arith_expr) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2063 && 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
|
2064 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2065 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2066 |
| 4084 | 2067 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2068 validate_term(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2069 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2070 int pos = 1; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2071 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2072 int res = (validate_ntype(tree, term) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2073 && is_odd(nch) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2074 && validate_factor(CHILD(tree, 0))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2075 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2076 for ( ; res && (pos < nch); pos += 2) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2077 res = (((TYPE(CHILD(tree, pos)) == STAR) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2078 || (TYPE(CHILD(tree, pos)) == SLASH) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2079 || (TYPE(CHILD(tree, pos)) == PERCENT)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2080 && validate_factor(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2081 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2082 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2083 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2084 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2085 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2086 /* factor: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2087 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2088 * factor: ('+'|'-'|'~') factor | power |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2089 */ |
| 4084 | 2090 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2091 validate_factor(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2092 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2093 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2094 int res = (validate_ntype(tree, factor) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2095 && (((nch == 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2096 && ((TYPE(CHILD(tree, 0)) == PLUS) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2097 || (TYPE(CHILD(tree, 0)) == MINUS) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2098 || (TYPE(CHILD(tree, 0)) == TILDE)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2099 && validate_factor(CHILD(tree, 1))) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2100 || ((nch == 1) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2101 && validate_power(CHILD(tree, 0))))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2102 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2103 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2104 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2105 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2106 /* power: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2107 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2108 * power: atom trailer* ('**' factor)* |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2109 */ |
| 4084 | 2110 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2111 validate_power(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2112 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2113 int pos = 1; |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2114 int nch = NCH(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2115 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
|
2116 && validate_atom(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2117 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2118 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
|
2119 res = validate_trailer(CHILD(tree, pos++)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2120 if (res && (pos < nch)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2121 if (!is_even(nch - pos)) { |
| 15318 | 2122 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
|
2123 return (0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2124 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2125 for ( ; res && (pos < (nch - 1)); pos += 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2126 res = (validate_doublestar(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2127 && validate_factor(CHILD(tree, pos + 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2128 } |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2129 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2130 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2131 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2132 |
| 4084 | 2133 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2134 validate_atom(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2135 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2136 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2137 int nch = NCH(tree); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2138 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
|
2139 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2140 if (res && nch < 1) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2141 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
|
2142 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2143 switch (TYPE(CHILD(tree, 0))) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2144 case LPAR: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2145 res = ((nch <= 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2146 && (validate_rparen(CHILD(tree, nch - 1)))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2147 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2148 if (res && (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2149 res = validate_testlist(CHILD(tree, 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2150 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2151 case LSQB: |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2152 if (nch == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2153 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
|
2154 else if (nch == 3) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2155 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
|
2156 && 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
|
2157 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2158 res = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2159 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
|
2160 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2161 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2162 case LBRACE: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2163 res = ((nch <= 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2164 && 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
|
2165 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2166 if (res && (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2167 res = validate_dictmaker(CHILD(tree, 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2168 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2169 case BACKQUOTE: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2170 res = ((nch == 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2171 && validate_testlist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2172 && validate_ntype(CHILD(tree, 2), BACKQUOTE)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2173 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2174 case NAME: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2175 case NUMBER: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2176 res = (nch == 1); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2177 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2178 case STRING: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2179 for (pos = 1; res && (pos < nch); ++pos) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2180 res = validate_ntype(CHILD(tree, pos), STRING); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2181 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2182 default: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2183 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2184 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2185 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2186 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2187 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2188 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2189 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2190 |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2191 /* listmaker: |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2192 * 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
|
2193 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2194 static int |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2195 validate_listmaker(node *tree) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2196 { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2197 int nch = NCH(tree); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2198 int ok = nch; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2199 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2200 if (nch == 0) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2201 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
|
2202 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2203 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
|
2204 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2205 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2206 * list_iter | (',' test)* [','] |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2207 */ |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2208 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
|
2209 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
|
2210 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2211 /* (',' test)* [','] */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2212 int i = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2213 while (ok && nch - i >= 2) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2214 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
|
2215 && 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
|
2216 i += 2; |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2217 } |
|
14129
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2218 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
|
2219 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
|
2220 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
|
2221 ok = 0; |
|
2c2ae86dfe87
validate_listmaker(): Revise to match Skip's latest changes to the
Fred Drake <fdrake@acm.org>
parents:
14113
diff
changeset
|
2222 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
|
2223 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2224 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2225 return ok; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2226 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2227 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2228 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2229 /* funcdef: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2230 * 'def' NAME parameters ':' suite |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2231 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2232 */ |
| 4084 | 2233 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2234 validate_funcdef(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2235 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2236 return (validate_ntype(tree, funcdef) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2237 && validate_numnodes(tree, 5, "funcdef") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2238 && validate_name(CHILD(tree, 0), "def") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2239 && validate_ntype(CHILD(tree, 1), NAME) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2240 && validate_colon(CHILD(tree, 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2241 && validate_parameters(CHILD(tree, 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2242 && validate_suite(CHILD(tree, 4))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2243 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2244 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2245 |
| 4084 | 2246 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2247 validate_lambdef(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2248 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2249 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2250 int res = (validate_ntype(tree, lambdef) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2251 && ((nch == 3) || (nch == 4)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2252 && validate_name(CHILD(tree, 0), "lambda") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2253 && validate_colon(CHILD(tree, nch - 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2254 && validate_test(CHILD(tree, nch - 1))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2255 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2256 if (res && (nch == 4)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2257 res = validate_varargslist(CHILD(tree, 1)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2258 else if (!res && !PyErr_Occurred()) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2259 (void) validate_numnodes(tree, 3, "lambdef"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2260 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2261 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2262 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2263 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2264 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2265 /* arglist: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2266 * |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2267 * (argument ',')* (argument [','] | '*' test [',' '**' test] | '**' test) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2268 */ |
| 4084 | 2269 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2270 validate_arglist(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2271 { |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2272 int nch = NCH(tree); |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2273 int i = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2274 int ok = 1; |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2275 |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2276 if (nch <= 0) |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2277 /* 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
|
2278 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
|
2279 |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2280 while (ok && nch-i >= 2) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2281 /* skip leading (argument ',') */ |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2282 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
|
2283 && 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
|
2284 if (ok) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2285 i += 2; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2286 else |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2287 PyErr_Clear(); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2288 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2289 ok = 1; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2290 if (nch-i > 0) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2291 /* |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2292 * argument | '*' test [',' '**' test] | '**' test |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2293 */ |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2294 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
|
2295 |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2296 if (sym == argument) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2297 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
|
2298 if (ok && i+1 != nch) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2299 err_string("illegal arglist specification" |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2300 " (extra stuff on end)"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2301 ok = 0; |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2302 } |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2303 } |
|
14110
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2304 else if (sym == STAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2305 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
|
2306 if (ok && (nch-i == 2)) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2307 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
|
2308 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
|
2309 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
|
2310 && 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
|
2311 && 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
|
2312 && 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
|
2313 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2314 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
|
2315 ok = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2316 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2317 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2318 else if (sym == DOUBLESTAR) { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2319 if (nch-i == 2) |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2320 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
|
2321 && 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
|
2322 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2323 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
|
2324 ok = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2325 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2326 } |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2327 else { |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2328 err_string("illegal arglist specification"); |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2329 ok = 0; |
|
0abfca0035dc
Update to reflect recent grammar changes (list comprehensions, extended
Fred Drake <fdrake@acm.org>
parents:
13692
diff
changeset
|
2330 } |
|
12487
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2331 } |
|
f1e867ad7d85
validate_arglist(): Re-written to reflect extended call syntax.
Fred Drake <fdrake@acm.org>
parents:
12416
diff
changeset
|
2332 return (ok); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2333 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2334 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2335 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2336 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2337 /* argument: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2338 * |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2339 * [test '='] test |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2340 */ |
| 4084 | 2341 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2342 validate_argument(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2343 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2344 int nch = NCH(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2345 int res = (validate_ntype(tree, argument) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2346 && ((nch == 1) || (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2347 && validate_test(CHILD(tree, 0))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2348 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2349 if (res && (nch == 3)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2350 res = (validate_equal(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2351 && validate_test(CHILD(tree, 2))); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2352 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2353 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2354 } |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2355 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2356 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2357 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2358 /* trailer: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2359 * |
| 4084 | 2360 * '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2361 */ |
| 4084 | 2362 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2363 validate_trailer(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2364 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2365 int nch = NCH(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2366 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
|
2367 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2368 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2369 switch (TYPE(CHILD(tree, 0))) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2370 case LPAR: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2371 res = validate_rparen(CHILD(tree, nch - 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2372 if (res && (nch == 3)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2373 res = validate_arglist(CHILD(tree, 1)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2374 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2375 case LSQB: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2376 res = (validate_numnodes(tree, 3, "trailer") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2377 && validate_subscriptlist(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2378 && validate_ntype(CHILD(tree, 2), RSQB)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2379 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2380 case DOT: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2381 res = (validate_numnodes(tree, 2, "trailer") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2382 && validate_ntype(CHILD(tree, 1), NAME)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2383 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2384 default: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2385 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2386 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2387 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2388 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2389 else { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2390 (void) validate_numnodes(tree, 2, "trailer"); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2391 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2392 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2393 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2394 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2395 |
| 4084 | 2396 /* subscriptlist: |
| 2397 * | |
| 2398 * subscript (',' subscript)* [','] | |
| 2399 */ | |
| 2400 static int | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2401 validate_subscriptlist(node *tree) |
| 4084 | 2402 { |
| 2403 return (validate_repeating_list(tree, subscriptlist, | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2404 validate_subscript, "subscriptlist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2405 } |
| 4084 | 2406 |
| 2407 | |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2408 /* subscript: |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2409 * |
| 4084 | 2410 * '.' '.' '.' | test | [test] ':' [test] [sliceop] |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2411 */ |
| 4084 | 2412 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2413 validate_subscript(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2414 { |
| 4084 | 2415 int offset = 0; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2416 int nch = NCH(tree); |
| 4084 | 2417 int res = validate_ntype(tree, subscript) && (nch >= 1) && (nch <= 4); |
| 2418 | |
| 2419 if (!res) { | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2420 if (!PyErr_Occurred()) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2421 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
|
2422 return (0); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2423 } |
| 4084 | 2424 if (TYPE(CHILD(tree, 0)) == DOT) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2425 /* take care of ('.' '.' '.') possibility */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2426 return (validate_numnodes(tree, 3, "subscript") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2427 && validate_dot(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2428 && validate_dot(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2429 && validate_dot(CHILD(tree, 2))); |
| 4084 | 2430 if (nch == 1) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2431 if (TYPE(CHILD(tree, 0)) == test) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2432 res = validate_test(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2433 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2434 res = validate_colon(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2435 return (res); |
| 4084 | 2436 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2437 /* Must be [test] ':' [test] [sliceop], |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2438 * 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
|
2439 * be present, but we don't know which yet. |
| 4084 | 2440 */ |
| 2441 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
|
2442 res = validate_test(CHILD(tree, 0)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2443 offset = 1; |
| 4084 | 2444 } |
| 2445 if (res) | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2446 res = validate_colon(CHILD(tree, offset)); |
| 4084 | 2447 if (res) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2448 int rem = nch - ++offset; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2449 if (rem) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2450 if (TYPE(CHILD(tree, offset)) == test) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2451 res = validate_test(CHILD(tree, offset)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2452 ++offset; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2453 --rem; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2454 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2455 if (res && rem) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2456 res = validate_sliceop(CHILD(tree, offset)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2457 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2458 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2459 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2460 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2461 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2462 |
| 4084 | 2463 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2464 validate_sliceop(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2465 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2466 int nch = NCH(tree); |
| 4084 | 2467 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
|
2468 && validate_ntype(tree, sliceop); |
| 4084 | 2469 if (!res && !PyErr_Occurred()) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2470 res = validate_numnodes(tree, 1, "sliceop"); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2471 } |
| 4084 | 2472 if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2473 res = validate_colon(CHILD(tree, 0)); |
| 4084 | 2474 if (res && (nch == 2)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2475 res = validate_test(CHILD(tree, 1)); |
| 4084 | 2476 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2477 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2478 } |
| 4084 | 2479 |
| 2480 | |
| 2481 static int | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2482 validate_exprlist(node *tree) |
| 4084 | 2483 { |
| 2484 return (validate_repeating_list(tree, exprlist, | |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2485 validate_expr, "exprlist")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2486 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2487 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2488 |
| 4084 | 2489 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2490 validate_dictmaker(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2491 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2492 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2493 int res = (validate_ntype(tree, dictmaker) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2494 && (nch >= 3) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2495 && validate_test(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2496 && validate_colon(CHILD(tree, 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2497 && validate_test(CHILD(tree, 2))); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2498 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2499 if (res && ((nch % 4) == 0)) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2500 res = validate_comma(CHILD(tree, --nch)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2501 else if (res) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2502 res = ((nch % 4) == 3); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2503 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2504 if (res && (nch > 3)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2505 int pos = 3; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2506 /* ( ',' test ':' test )* */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2507 while (res && (pos < nch)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2508 res = (validate_comma(CHILD(tree, pos)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2509 && validate_test(CHILD(tree, pos + 1)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2510 && validate_colon(CHILD(tree, pos + 2)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2511 && validate_test(CHILD(tree, pos + 3))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2512 pos += 4; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2513 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2514 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2515 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2516 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2517 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2518 |
| 4084 | 2519 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2520 validate_eval_input(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2521 { |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2522 int pos; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2523 int nch = NCH(tree); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2524 int res = (validate_ntype(tree, eval_input) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2525 && (nch >= 2) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2526 && validate_testlist(CHILD(tree, 0)) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2527 && 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
|
2528 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2529 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
|
2530 res = validate_ntype(CHILD(tree, pos), NEWLINE); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2531 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2532 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2533 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2534 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2535 |
| 4084 | 2536 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2537 validate_node(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2538 { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2539 int nch = 0; /* num. children on current node */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2540 int res = 1; /* result value */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2541 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
|
2542 |
|
18247
e3cf3348feca
Properly use &&. Closes bug #434989.
Martin v. Löwis <martin@v.loewis.de>
parents:
15751
diff
changeset
|
2543 while (res && (tree != 0)) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2544 nch = NCH(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2545 next = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2546 switch (TYPE(tree)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2547 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2548 * Definition nodes. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2549 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2550 case funcdef: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2551 res = validate_funcdef(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2552 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2553 case classdef: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2554 res = validate_class(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2555 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2556 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2557 * "Trivial" parse tree nodes. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2558 * (Why did I call these trivial?) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2559 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2560 case stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2561 res = validate_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2562 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2563 case small_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2564 /* |
|
14533
635f69123349
Simplify some of the code. Use PyErr_Format() instead of sprintf(), etc.
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
2565 * 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
|
2566 * | import_stmt | global_stmt | exec_stmt | assert_stmt |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2567 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2568 res = validate_small_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2569 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2570 case flow_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2571 res = (validate_numnodes(tree, 1, "flow_stmt") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2572 && ((TYPE(CHILD(tree, 0)) == break_stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2573 || (TYPE(CHILD(tree, 0)) == continue_stmt) |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
2574 || (TYPE(CHILD(tree, 0)) == yield_stmt) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2575 || (TYPE(CHILD(tree, 0)) == return_stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2576 || (TYPE(CHILD(tree, 0)) == raise_stmt))); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2577 if (res) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2578 next = CHILD(tree, 0); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2579 else if (nch == 1) |
| 15318 | 2580 err_string("illegal flow_stmt type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2581 break; |
|
18646
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
2582 case yield_stmt: |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
2583 res = validate_yield_stmt(tree); |
|
c43fe213ee10
Add support for yield statements.
Fred Drake <fdrake@acm.org>
parents:
18247
diff
changeset
|
2584 break; |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2585 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2586 * Compound statements. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2587 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2588 case simple_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2589 res = validate_simple_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2590 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2591 case compound_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2592 res = validate_compound_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2593 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2594 /* |
|
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
|
2595 * Fundamental statements. |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2596 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2597 case expr_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2598 res = validate_expr_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2599 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2600 case print_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2601 res = validate_print_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2602 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2603 case del_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2604 res = validate_del_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2605 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2606 case pass_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2607 res = (validate_numnodes(tree, 1, "pass") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2608 && validate_name(CHILD(tree, 0), "pass")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2609 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2610 case break_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2611 res = (validate_numnodes(tree, 1, "break") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2612 && validate_name(CHILD(tree, 0), "break")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2613 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2614 case continue_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2615 res = (validate_numnodes(tree, 1, "continue") |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2616 && validate_name(CHILD(tree, 0), "continue")); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2617 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2618 case return_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2619 res = validate_return_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2620 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2621 case raise_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2622 res = validate_raise_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2623 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2624 case import_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2625 res = validate_import_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2626 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2627 case global_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2628 res = validate_global_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2629 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2630 case exec_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2631 res = validate_exec_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2632 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2633 case assert_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2634 res = validate_assert_stmt(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2635 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2636 case if_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2637 res = validate_if(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2638 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2639 case while_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2640 res = validate_while(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2641 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2642 case for_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2643 res = validate_for(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2644 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2645 case try_stmt: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2646 res = validate_try(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2647 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2648 case suite: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2649 res = validate_suite(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2650 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2651 /* |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2652 * Expression nodes. |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2653 */ |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2654 case testlist: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2655 res = validate_testlist(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2656 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2657 case test: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2658 res = validate_test(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2659 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2660 case and_test: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2661 res = validate_and_test(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2662 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2663 case not_test: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2664 res = validate_not_test(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2665 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2666 case comparison: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2667 res = validate_comparison(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2668 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2669 case exprlist: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2670 res = validate_exprlist(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2671 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2672 case comp_op: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2673 res = validate_comp_op(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2674 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2675 case expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2676 res = validate_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2677 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2678 case xor_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2679 res = validate_xor_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2680 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2681 case and_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2682 res = validate_and_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2683 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2684 case shift_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2685 res = validate_shift_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2686 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2687 case arith_expr: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2688 res = validate_arith_expr(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2689 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2690 case term: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2691 res = validate_term(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2692 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2693 case factor: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2694 res = validate_factor(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2695 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2696 case power: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2697 res = validate_power(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2698 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2699 case atom: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2700 res = validate_atom(tree); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2701 break; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2702 |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2703 default: |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2704 /* Hopefully never reached! */ |
| 15318 | 2705 err_string("unrecognized node type"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2706 res = 0; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2707 break; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2708 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2709 tree = next; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2710 } |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2711 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2712 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2713 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2714 |
| 4084 | 2715 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2716 validate_expr_tree(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2717 { |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2718 int res = validate_eval_input(tree); |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2719 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2720 if (!res && !PyErr_Occurred()) |
| 15318 | 2721 err_string("could not validate expression tuple"); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2722 |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2723 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2724 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2725 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2726 |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2727 /* file_input: |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2728 * (NEWLINE | stmt)* ENDMARKER |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2729 */ |
| 4084 | 2730 static int |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2731 validate_file_input(node *tree) |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2732 { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2733 int j; |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2734 int nch = NCH(tree) - 1; |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2735 int res = ((nch >= 0) |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2736 && validate_ntype(CHILD(tree, nch), ENDMARKER)); |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2737 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2738 for (j = 0; res && (j < nch); ++j) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2739 if (TYPE(CHILD(tree, j)) == stmt) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2740 res = validate_stmt(CHILD(tree, j)); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2741 else |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2742 res = validate_newline(CHILD(tree, j)); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2743 } |
|
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
|
2744 /* 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
|
2745 * 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
|
2746 * this, we have some debugging to do. |
|
3774
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2747 */ |
|
4c78d73c5667
New submission by Fred Drake.
Guido van Rossum <guido@python.org>
parents:
3336
diff
changeset
|
2748 if (!res && !PyErr_Occurred()) |
| 15318 | 2749 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
|
2750 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2751 return (res); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2752 } |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2753 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2754 |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2755 static PyObject* |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2756 pickle_constructor = NULL; |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2757 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2758 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2759 static PyObject* |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2760 parser__pickler(PyObject *self, PyObject *args) |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2761 { |
| 8196 | 2762 NOTE(ARGUNUSED(self)) |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2763 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
|
2764 PyObject *st = NULL; |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
2765 PyObject *empty_dict = NULL; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2766 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2767 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
|
2768 PyObject *newargs; |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2769 PyObject *tuple; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2770 |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
2771 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
|
2772 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
|
2773 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
|
2774 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
|
2775 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
|
2776 if (tuple != NULL) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2777 result = Py_BuildValue("O(O)", pickle_constructor, tuple); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2778 Py_DECREF(tuple); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2779 } |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
2780 Py_DECREF(empty_dict); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2781 Py_DECREF(newargs); |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2782 } |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2783 finally: |
|
11297
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
2784 Py_XDECREF(empty_dict); |
|
2560236ecedb
parser__pickler(): Don't drop the third argument to
Fred Drake <fdrake@acm.org>
parents:
11266
diff
changeset
|
2785 |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2786 return (result); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2787 } |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2788 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2789 |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2790 /* 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
|
2791 * 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
|
2792 * 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
|
2793 * 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
|
2794 * inheritance. |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2795 */ |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2796 static PyMethodDef parser_functions[] = { |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2797 {"ast2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2798 "Creates a tuple-tree representation of an ST."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2799 {"ast2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2800 "Creates a list-tree representation of an ST."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2801 {"compileast", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2802 "Compiles an ST object into a code object."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2803 {"compilest", (PyCFunction)parser_compilest, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2804 "Compiles an ST object into a code object."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2805 {"expr", (PyCFunction)parser_expr, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2806 "Creates an ST object from an expression."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2807 {"isexpr", (PyCFunction)parser_isexpr, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2808 "Determines if an ST object was created from an expression."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2809 {"issuite", (PyCFunction)parser_issuite, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2810 "Determines if an ST object was created from a suite."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2811 {"suite", (PyCFunction)parser_suite, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2812 "Creates an ST object from a suite."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2813 {"sequence2ast", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2814 "Creates an ST object from a tree representation."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2815 {"sequence2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2816 "Creates an ST object from a tree representation."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2817 {"st2tuple", (PyCFunction)parser_st2tuple, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2818 "Creates a tuple-tree representation of an ST."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2819 {"st2list", (PyCFunction)parser_st2list, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2820 "Creates a list-tree representation of an ST."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2821 {"tuple2ast", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2822 "Creates an ST object from a tree representation."}, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2823 {"tuple2st", (PyCFunction)parser_tuple2st, PUBLIC_METHOD_TYPE, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2824 "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
|
2825 |
|
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2826 /* 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
|
2827 {"_pickler", (PyCFunction)parser__pickler, METH_VARARGS, |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2828 "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
|
2829 |
| 8196 | 2830 {NULL, NULL, 0, NULL} |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2831 }; |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2832 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2833 |
|
14219
2c3283094311
Try to supply a prototype for the module init function but avoid
Tim Peters <tim.peters@gmail.com>
parents:
14214
diff
changeset
|
2834 DL_EXPORT(void) initparser(void); /* supply a prototype */ |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
2835 |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
8813
diff
changeset
|
2836 DL_EXPORT(void) |
| 13692 | 2837 initparser(void) |
|
14214
b5fb175ad528
Update the parser module to support augmented assignment.
Fred Drake <fdrake@acm.org>
parents:
14129
diff
changeset
|
2838 { |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2839 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
|
2840 |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2841 PyST_Type.ob_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
|
2842 module = Py_InitModule("parser", parser_functions); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2843 |
|
11266
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
2844 if (parser_error == 0) |
|
c0b86a44a120
Added keyword parameter support to all public interfaces; keyword
Fred Drake <fdrake@acm.org>
parents:
10215
diff
changeset
|
2845 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
|
2846 |
|
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2847 if ((parser_error == 0) |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2848 || (PyModule_AddObject(module, "ParserError", 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
|
2849 /* 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
|
2850 return; |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2851 } |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2852 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
|
2853 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
|
2854 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
|
2855 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
|
2856 |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2857 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
|
2858 parser_copyright_string); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2859 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
|
2860 parser_doc_string); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2861 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
|
2862 parser_version_string); |
|
3200
8f5ab1a6c914
Fred Drake's new parser module
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
2863 |
| 18748 | 2864 /* Register to support pickling. |
| 2865 * If this fails, the import of this module will fail because an | |
| 2866 * exception will be raised here; should we clear the exception? | |
| 2867 */ | |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2868 copyreg = PyImport_ImportModule("copy_reg"); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2869 if (copyreg != NULL) { |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2870 PyObject *func, *pickler; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2871 |
|
19274
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2872 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
|
2873 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
|
2874 pickler = PyObject_GetAttrString(module, "_pickler"); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2875 Py_XINCREF(pickle_constructor); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2876 if ((func != NULL) && (pickle_constructor != NULL) |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2877 && (pickler != NULL)) { |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2878 PyObject *res; |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2879 |
|
18669
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2880 res = PyObject_CallFunction(func, "OOO", &PyST_Type, pickler, |
|
6d4a530fe7c1
The syntax trees handled by this module are not "abstract," so take the
Fred Drake <fdrake@acm.org>
parents:
18646
diff
changeset
|
2881 pickle_constructor); |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2882 Py_XDECREF(res); |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2883 } |
|
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2884 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
|
2885 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
|
2886 Py_XDECREF(pickler); |
|
5501958edc36
Use the abstract object interfaces when digging around in module objects
Fred Drake <fdrake@acm.org>
parents:
18748
diff
changeset
|
2887 Py_DECREF(copyreg); |
|
8034
cd3092069f5a
Added support for pickling ast objects.
Fred Drake <fdrake@acm.org>
parents:
7982
diff
changeset
|
2888 } |
|
12416
95e296e67a12
ANSI-fy & de-tabify the source.
Fred Drake <fdrake@acm.org>
parents:
11828
diff
changeset
|
2889 } |
