Mercurial > cpython-lru_cache-weakref
annotate Parser/listnode.c @ 13778:f6e4a9dd67cd legacy-trunk
Rename the "parser" package to "parsers" to be compatible with the PyXML
project.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Mon, 31 Jul 2000 23:59:54 +0000 |
| parents | e78153e179fb |
| children | 6f6f965c5e2d |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
2 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
5 All rights reserved. |
| 145 | 6 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
7 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 145 | 9 ******************************************************************/ |
| 10 | |
| 6 | 11 /* List a node on a file */ |
| 12 | |
| 86 | 13 #include "pgenheaders.h" |
| 6 | 14 #include "token.h" |
| 15 #include "node.h" | |
| 16 | |
| 86 | 17 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
18 static void list1node(FILE *, node *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
19 static void listnode(FILE *, node *); |
| 86 | 20 |
| 21 void | |
| 13659 | 22 PyNode_ListTree(node *n) |
| 86 | 23 { |
| 24 listnode(stdout, n); | |
| 25 } | |
| 26 | |
| 6 | 27 static int level, atbol; |
| 28 | |
|
1318
92e6a8cf14be
* pythonmain.c: -k option, usage message, more environment flags.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
29 static void |
| 13659 | 30 listnode(FILE *fp, node *n) |
| 86 | 31 { |
| 32 level = 0; | |
| 33 atbol = 1; | |
| 34 list1node(fp, n); | |
| 35 } | |
| 36 | |
| 6 | 37 static void |
| 13659 | 38 list1node(FILE *fp, node *n) |
| 6 | 39 { |
| 40 if (n == 0) | |
| 41 return; | |
| 42 if (ISNONTERMINAL(TYPE(n))) { | |
| 43 int i; | |
| 44 for (i = 0; i < NCH(n); i++) | |
| 45 list1node(fp, CHILD(n, i)); | |
| 46 } | |
| 47 else if (ISTERMINAL(TYPE(n))) { | |
| 48 switch (TYPE(n)) { | |
| 49 case INDENT: | |
| 50 ++level; | |
| 51 break; | |
| 52 case DEDENT: | |
| 53 --level; | |
| 54 break; | |
| 55 default: | |
| 56 if (atbol) { | |
| 57 int i; | |
| 58 for (i = 0; i < level; ++i) | |
| 59 fprintf(fp, "\t"); | |
| 60 atbol = 0; | |
| 61 } | |
| 62 if (TYPE(n) == NEWLINE) { | |
| 63 if (STR(n) != NULL) | |
| 64 fprintf(fp, "%s", STR(n)); | |
| 65 fprintf(fp, "\n"); | |
| 66 atbol = 1; | |
| 67 } | |
| 68 else | |
| 69 fprintf(fp, "%s ", STR(n)); | |
| 70 break; | |
| 71 } | |
| 72 } | |
| 73 else | |
| 74 fprintf(fp, "? "); | |
| 75 } |
