1 | n/a | |
---|
2 | n/a | /* List a node on a file */ |
---|
3 | n/a | |
---|
4 | n/a | #include "pgenheaders.h" |
---|
5 | n/a | #include "token.h" |
---|
6 | n/a | #include "node.h" |
---|
7 | n/a | |
---|
8 | n/a | /* Forward */ |
---|
9 | n/a | static void list1node(FILE *, node *); |
---|
10 | n/a | static void listnode(FILE *, node *); |
---|
11 | n/a | |
---|
12 | n/a | void |
---|
13 | n/a | PyNode_ListTree(node *n) |
---|
14 | n/a | { |
---|
15 | n/a | listnode(stdout, n); |
---|
16 | n/a | } |
---|
17 | n/a | |
---|
18 | n/a | static int level, atbol; |
---|
19 | n/a | |
---|
20 | n/a | static void |
---|
21 | n/a | listnode(FILE *fp, node *n) |
---|
22 | n/a | { |
---|
23 | n/a | level = 0; |
---|
24 | n/a | atbol = 1; |
---|
25 | n/a | list1node(fp, n); |
---|
26 | n/a | } |
---|
27 | n/a | |
---|
28 | n/a | static void |
---|
29 | n/a | list1node(FILE *fp, node *n) |
---|
30 | n/a | { |
---|
31 | n/a | if (n == 0) |
---|
32 | n/a | return; |
---|
33 | n/a | if (ISNONTERMINAL(TYPE(n))) { |
---|
34 | n/a | int i; |
---|
35 | n/a | for (i = 0; i < NCH(n); i++) |
---|
36 | n/a | list1node(fp, CHILD(n, i)); |
---|
37 | n/a | } |
---|
38 | n/a | else if (ISTERMINAL(TYPE(n))) { |
---|
39 | n/a | switch (TYPE(n)) { |
---|
40 | n/a | case INDENT: |
---|
41 | n/a | ++level; |
---|
42 | n/a | break; |
---|
43 | n/a | case DEDENT: |
---|
44 | n/a | --level; |
---|
45 | n/a | break; |
---|
46 | n/a | default: |
---|
47 | n/a | if (atbol) { |
---|
48 | n/a | int i; |
---|
49 | n/a | for (i = 0; i < level; ++i) |
---|
50 | n/a | fprintf(fp, "\t"); |
---|
51 | n/a | atbol = 0; |
---|
52 | n/a | } |
---|
53 | n/a | if (TYPE(n) == NEWLINE) { |
---|
54 | n/a | if (STR(n) != NULL) |
---|
55 | n/a | fprintf(fp, "%s", STR(n)); |
---|
56 | n/a | fprintf(fp, "\n"); |
---|
57 | n/a | atbol = 1; |
---|
58 | n/a | } |
---|
59 | n/a | else |
---|
60 | n/a | fprintf(fp, "%s ", STR(n)); |
---|
61 | n/a | break; |
---|
62 | n/a | } |
---|
63 | n/a | } |
---|
64 | n/a | else |
---|
65 | n/a | fprintf(fp, "? "); |
---|
66 | n/a | } |
---|