Mercurial > cpython-lru_cache-weakref
annotate Tools/parser/unparse.py @ 69778:07613ea46dbc
Merge: I was right, hardconding the localhost IP doesn't work in linux-vserver.
| author | R David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Mon, 02 May 2011 08:48:00 -0400 |
| parents | 87e6bdb373d1 |
| children | c80576303892 |
| rev | line source |
|---|---|
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
1 "Usage: unparse.py <path to source file>" |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
2 import sys |
|
62623
fe44828ea7ed
More unparse.py fixes:
Mark Dickinson <dickinsm@gmail.com>
parents:
62622
diff
changeset
|
3 import math |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
4 import ast |
|
62621
a4e1c56be532
unparse.py: respect coding cookie in input files
Mark Dickinson <dickinsm@gmail.com>
parents:
62614
diff
changeset
|
5 import tokenize |
|
42304
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
6 import io |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
7 import os |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
8 |
|
62651
043ef04f64d2
Unparse infinite imaginary literals correctly. Add some more numeric tests.
Mark Dickinson <dickinsm@gmail.com>
parents:
62650
diff
changeset
|
9 # Large float and imaginary literals get turned into infinities in the AST. |
|
043ef04f64d2
Unparse infinite imaginary literals correctly. Add some more numeric tests.
Mark Dickinson <dickinsm@gmail.com>
parents:
62650
diff
changeset
|
10 # We unparse those infinities to INFSTR. |
|
043ef04f64d2
Unparse infinite imaginary literals correctly. Add some more numeric tests.
Mark Dickinson <dickinsm@gmail.com>
parents:
62650
diff
changeset
|
11 INFSTR = "1e" + repr(sys.float_info.max_10_exp + 1) |
|
043ef04f64d2
Unparse infinite imaginary literals correctly. Add some more numeric tests.
Mark Dickinson <dickinsm@gmail.com>
parents:
62650
diff
changeset
|
12 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
13 def interleave(inter, f, seq): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
14 """Call f on each item in seq, calling inter() in between. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
15 """ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
16 seq = iter(seq) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
17 try: |
|
42304
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
18 f(next(seq)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
19 except StopIteration: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
20 pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
21 else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
22 for x in seq: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
23 inter() |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
24 f(x) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
25 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
26 class Unparser: |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
27 """Methods in this class recursively traverse an AST and |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
28 output source code for the abstract syntax; original formatting |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
29 is disregarded. """ |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
30 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
31 def __init__(self, tree, file = sys.stdout): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
32 """Unparser(tree, file=sys.stdout) -> None. |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
33 Print the source for tree to file.""" |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
34 self.f = file |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
35 self._indent = 0 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
36 self.dispatch(tree) |
|
42304
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
37 print("", file=self.f) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
38 self.f.flush() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
39 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
40 def fill(self, text = ""): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
41 "Indent a piece of text, according to the current indentation level" |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
42 self.f.write("\n"+" "*self._indent + text) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
43 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
44 def write(self, text): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
45 "Append a piece of text to the current line." |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
46 self.f.write(text) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
47 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
48 def enter(self): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
49 "Print ':', and increase the indentation." |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
50 self.write(":") |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
51 self._indent += 1 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
52 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
53 def leave(self): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
54 "Decrease the indentation level." |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
55 self._indent -= 1 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
56 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
57 def dispatch(self, tree): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
58 "Dispatcher function, dispatching tree type T to method _T." |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
59 if isinstance(tree, list): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
60 for t in tree: |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
61 self.dispatch(t) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
62 return |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
63 meth = getattr(self, "_"+tree.__class__.__name__) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
64 meth(tree) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
65 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
66 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
67 ############### Unparsing methods ###################### |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
68 # There should be one method per concrete grammar type # |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
69 # Constructors should be grouped by sum type. Ideally, # |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
70 # this would follow the order in the grammar, but # |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
71 # currently doesn't. # |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
72 ######################################################## |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
73 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
74 def _Module(self, tree): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
75 for stmt in tree.body: |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
76 self.dispatch(stmt) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
77 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
78 # stmt |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
79 def _Expr(self, tree): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
80 self.fill() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
81 self.dispatch(tree.value) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
82 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
83 def _Import(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
84 self.fill("import ") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
85 interleave(lambda: self.write(", "), self.dispatch, t.names) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
86 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
87 def _ImportFrom(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
88 self.fill("from ") |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
89 self.write("." * t.level) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
90 if t.module: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
91 self.write(t.module) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
92 self.write(" import ") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
93 interleave(lambda: self.write(", "), self.dispatch, t.names) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
94 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
95 def _Assign(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
96 self.fill() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
97 for target in t.targets: |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
98 self.dispatch(target) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
99 self.write(" = ") |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
100 self.dispatch(t.value) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
101 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
102 def _AugAssign(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
103 self.fill() |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
104 self.dispatch(t.target) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
105 self.write(" "+self.binop[t.op.__class__.__name__]+"= ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
106 self.dispatch(t.value) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
107 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
108 def _Return(self, t): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
109 self.fill("return") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
110 if t.value: |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
111 self.write(" ") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
112 self.dispatch(t.value) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
113 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
114 def _Pass(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
115 self.fill("pass") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
116 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
117 def _Break(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
118 self.fill("break") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
119 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
120 def _Continue(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
121 self.fill("continue") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
122 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
123 def _Delete(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
124 self.fill("del ") |
|
62609
68b670f3614e
Merged revisions 82338,82340-82341 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48771
diff
changeset
|
125 interleave(lambda: self.write(", "), self.dispatch, t.targets) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
126 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
127 def _Assert(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
128 self.fill("assert ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
129 self.dispatch(t.test) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
130 if t.msg: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
131 self.write(", ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
132 self.dispatch(t.msg) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
133 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
134 def _Global(self, t): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
135 self.fill("global ") |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
136 interleave(lambda: self.write(", "), self.write, t.names) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
137 |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
138 def _Nonlocal(self, t): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
139 self.fill("nonlocal ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
140 interleave(lambda: self.write(", "), self.write, t.names) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
141 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
142 def _Yield(self, t): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
143 self.write("(") |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
144 self.write("yield") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
145 if t.value: |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
146 self.write(" ") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
147 self.dispatch(t.value) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
148 self.write(")") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
149 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
150 def _Raise(self, t): |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
151 self.fill("raise") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
152 if not t.exc: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
153 assert not t.cause |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
154 return |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
155 self.write(" ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
156 self.dispatch(t.exc) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
157 if t.cause: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
158 self.write(" from ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
159 self.dispatch(t.cause) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
160 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
161 def _TryExcept(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
162 self.fill("try") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
163 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
164 self.dispatch(t.body) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
165 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
166 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
167 for ex in t.handlers: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
168 self.dispatch(ex) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
169 if t.orelse: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
170 self.fill("else") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
171 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
172 self.dispatch(t.orelse) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
173 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
174 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
175 def _TryFinally(self, t): |
|
62644
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
176 if len(t.body) == 1 and isinstance(t.body[0], ast.TryExcept): |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
177 # try-except-finally |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
178 self.dispatch(t.body) |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
179 else: |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
180 self.fill("try") |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
181 self.enter() |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
182 self.dispatch(t.body) |
|
e6bb990ac9f6
Output try-except-finally statements where appropriate.
Mark Dickinson <dickinsm@gmail.com>
parents:
62643
diff
changeset
|
183 self.leave() |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
184 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
185 self.fill("finally") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
186 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
187 self.dispatch(t.finalbody) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
188 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
189 |
|
48771
ea3d13cd7c1e
Merged revisions 65780,65782,65785,65809,65812,65834,65846,65859,65861 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42304
diff
changeset
|
190 def _ExceptHandler(self, t): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
191 self.fill("except") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
192 if t.type: |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
193 self.write(" ") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
194 self.dispatch(t.type) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
195 if t.name: |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
196 self.write(" as ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
197 self.write(t.name) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
198 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
199 self.dispatch(t.body) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
200 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
201 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
202 def _ClassDef(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
203 self.write("\n") |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
204 for deco in t.decorator_list: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
205 self.fill("@") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
206 self.dispatch(deco) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
207 self.fill("class "+t.name) |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
208 self.write("(") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
209 comma = False |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
210 for e in t.bases: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
211 if comma: self.write(", ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
212 else: comma = True |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
213 self.dispatch(e) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
214 for e in t.keywords: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
215 if comma: self.write(", ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
216 else: comma = True |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
217 self.dispatch(e) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
218 if t.starargs: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
219 if comma: self.write(", ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
220 else: comma = True |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
221 self.write("*") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
222 self.dispatch(t.starargs) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
223 if t.kwargs: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
224 if comma: self.write(", ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
225 else: comma = True |
|
62637
158166ef6f06
Fix typo in unparsing of a class definition.
Mark Dickinson <dickinsm@gmail.com>
parents:
62623
diff
changeset
|
226 self.write("**") |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
227 self.dispatch(t.kwargs) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
228 self.write(")") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
229 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
230 self.enter() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
231 self.dispatch(t.body) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
232 self.leave() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
233 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
234 def _FunctionDef(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
235 self.write("\n") |
|
48771
ea3d13cd7c1e
Merged revisions 65780,65782,65785,65809,65812,65834,65846,65859,65861 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
42304
diff
changeset
|
236 for deco in t.decorator_list: |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39782
diff
changeset
|
237 self.fill("@") |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39782
diff
changeset
|
238 self.dispatch(deco) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
239 self.fill("def "+t.name + "(") |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
240 self.dispatch(t.args) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
241 self.write(")") |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
242 if t.returns: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
243 self.write(" -> ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
244 self.dispatch(t.returns) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
245 self.enter() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
246 self.dispatch(t.body) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
247 self.leave() |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
248 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
249 def _For(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
250 self.fill("for ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
251 self.dispatch(t.target) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
252 self.write(" in ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
253 self.dispatch(t.iter) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
254 self.enter() |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
255 self.dispatch(t.body) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
256 self.leave() |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
257 if t.orelse: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
258 self.fill("else") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
259 self.enter() |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
260 self.dispatch(t.orelse) |
|
62609
68b670f3614e
Merged revisions 82338,82340-82341 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48771
diff
changeset
|
261 self.leave() |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
262 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
263 def _If(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
264 self.fill("if ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
265 self.dispatch(t.test) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
266 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
267 self.dispatch(t.body) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
268 self.leave() |
|
62643
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
269 # collapse nested ifs into equivalent elifs. |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
270 while (t.orelse and len(t.orelse) == 1 and |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
271 isinstance(t.orelse[0], ast.If)): |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
272 t = t.orelse[0] |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
273 self.fill("elif ") |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
274 self.dispatch(t.test) |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
275 self.enter() |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
276 self.dispatch(t.body) |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
277 self.leave() |
|
25fbf023102d
Collapse else: if: ... into elif:
Mark Dickinson <dickinsm@gmail.com>
parents:
62637
diff
changeset
|
278 # final else |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
279 if t.orelse: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
280 self.fill("else") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
281 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
282 self.dispatch(t.orelse) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
283 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
284 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
285 def _While(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
286 self.fill("while ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
287 self.dispatch(t.test) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
288 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
289 self.dispatch(t.body) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
290 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
291 if t.orelse: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
292 self.fill("else") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
293 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
294 self.dispatch(t.orelse) |
|
62609
68b670f3614e
Merged revisions 82338,82340-82341 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48771
diff
changeset
|
295 self.leave() |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
296 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
297 def _With(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
298 self.fill("with ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
299 self.dispatch(t.context_expr) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
300 if t.optional_vars: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
301 self.write(" as ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
302 self.dispatch(t.optional_vars) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
303 self.enter() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
304 self.dispatch(t.body) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
305 self.leave() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
306 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
307 # expr |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
308 def _Bytes(self, t): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
309 self.write(repr(t.s)) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
310 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
311 def _Str(self, tree): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
312 self.write(repr(tree.s)) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
313 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
314 def _Name(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
315 self.write(t.id) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
316 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
317 def _Num(self, t): |
|
62651
043ef04f64d2
Unparse infinite imaginary literals correctly. Add some more numeric tests.
Mark Dickinson <dickinsm@gmail.com>
parents:
62650
diff
changeset
|
318 # Substitute overflowing decimal literal for AST infinities. |
|
043ef04f64d2
Unparse infinite imaginary literals correctly. Add some more numeric tests.
Mark Dickinson <dickinsm@gmail.com>
parents:
62650
diff
changeset
|
319 self.write(repr(t.n).replace("inf", INFSTR)) |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
320 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
321 def _List(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
322 self.write("[") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
323 interleave(lambda: self.write(", "), self.dispatch, t.elts) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
324 self.write("]") |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
325 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
326 def _ListComp(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
327 self.write("[") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
328 self.dispatch(t.elt) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
329 for gen in t.generators: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
330 self.dispatch(gen) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
331 self.write("]") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
332 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
333 def _GeneratorExp(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
334 self.write("(") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
335 self.dispatch(t.elt) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
336 for gen in t.generators: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
337 self.dispatch(gen) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
338 self.write(")") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
339 |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
340 def _SetComp(self, t): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
341 self.write("{") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
342 self.dispatch(t.elt) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
343 for gen in t.generators: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
344 self.dispatch(gen) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
345 self.write("}") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
346 |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
347 def _DictComp(self, t): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
348 self.write("{") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
349 self.dispatch(t.key) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
350 self.write(": ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
351 self.dispatch(t.value) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
352 for gen in t.generators: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
353 self.dispatch(gen) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
354 self.write("}") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
355 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
356 def _comprehension(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
357 self.write(" for ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
358 self.dispatch(t.target) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
359 self.write(" in ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
360 self.dispatch(t.iter) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
361 for if_clause in t.ifs: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
362 self.write(" if ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
363 self.dispatch(if_clause) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
364 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
365 def _IfExp(self, t): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
366 self.write("(") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
367 self.dispatch(t.body) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
368 self.write(" if ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
369 self.dispatch(t.test) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
370 self.write(" else ") |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
371 self.dispatch(t.orelse) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
372 self.write(")") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
373 |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
374 def _Set(self, t): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
375 assert(t.elts) # should be at least one element |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
376 self.write("{") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
377 interleave(lambda: self.write(", "), self.dispatch, t.elts) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
378 self.write("}") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
379 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
380 def _Dict(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
381 self.write("{") |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
382 def write_pair(pair): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
383 (k, v) = pair |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
384 self.dispatch(k) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
385 self.write(": ") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
386 self.dispatch(v) |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
387 interleave(lambda: self.write(", "), write_pair, zip(t.keys, t.values)) |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
388 self.write("}") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
389 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
390 def _Tuple(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
391 self.write("(") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
392 if len(t.elts) == 1: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
393 (elt,) = t.elts |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
394 self.dispatch(elt) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
395 self.write(",") |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
396 else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
397 interleave(lambda: self.write(", "), self.dispatch, t.elts) |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
398 self.write(")") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
399 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
400 unop = {"Invert":"~", "Not": "not", "UAdd":"+", "USub":"-"} |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
401 def _UnaryOp(self, t): |
|
62609
68b670f3614e
Merged revisions 82338,82340-82341 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48771
diff
changeset
|
402 self.write("(") |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
403 self.write(self.unop[t.op.__class__.__name__]) |
|
62609
68b670f3614e
Merged revisions 82338,82340-82341 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48771
diff
changeset
|
404 self.write(" ") |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
405 self.dispatch(t.operand) |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
406 self.write(")") |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
407 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
408 binop = { "Add":"+", "Sub":"-", "Mult":"*", "Div":"/", "Mod":"%", |
|
62609
68b670f3614e
Merged revisions 82338,82340-82341 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48771
diff
changeset
|
409 "LShift":"<<", "RShift":">>", "BitOr":"|", "BitXor":"^", "BitAnd":"&", |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
410 "FloorDiv":"//", "Pow": "**"} |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
411 def _BinOp(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
412 self.write("(") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
413 self.dispatch(t.left) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
414 self.write(" " + self.binop[t.op.__class__.__name__] + " ") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
415 self.dispatch(t.right) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
416 self.write(")") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
417 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
418 cmpops = {"Eq":"==", "NotEq":"!=", "Lt":"<", "LtE":"<=", "Gt":">", "GtE":">=", |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
419 "Is":"is", "IsNot":"is not", "In":"in", "NotIn":"not in"} |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
420 def _Compare(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
421 self.write("(") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
422 self.dispatch(t.left) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
423 for o, e in zip(t.ops, t.comparators): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
424 self.write(" " + self.cmpops[o.__class__.__name__] + " ") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
425 self.dispatch(e) |
|
62612
69f6d2130281
Merged revisions 82345 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
62609
diff
changeset
|
426 self.write(")") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
427 |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
428 boolops = {ast.And: 'and', ast.Or: 'or'} |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
429 def _BoolOp(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
430 self.write("(") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
431 s = " %s " % self.boolops[t.op.__class__] |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
432 interleave(lambda: self.write(s), self.dispatch, t.values) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
433 self.write(")") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
434 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
435 def _Attribute(self,t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
436 self.dispatch(t.value) |
|
62645
4fce25abfdd8
Better solution for attribute access on integer literals.
Mark Dickinson <dickinsm@gmail.com>
parents:
62644
diff
changeset
|
437 # Special case: 3.__abs__() is a syntax error, so if t.value |
|
4fce25abfdd8
Better solution for attribute access on integer literals.
Mark Dickinson <dickinsm@gmail.com>
parents:
62644
diff
changeset
|
438 # is an integer literal then we need to either parenthesize |
|
4fce25abfdd8
Better solution for attribute access on integer literals.
Mark Dickinson <dickinsm@gmail.com>
parents:
62644
diff
changeset
|
439 # it or add an extra space to get 3 .__abs__(). |
|
4fce25abfdd8
Better solution for attribute access on integer literals.
Mark Dickinson <dickinsm@gmail.com>
parents:
62644
diff
changeset
|
440 if isinstance(t.value, ast.Num) and isinstance(t.value.n, int): |
|
4fce25abfdd8
Better solution for attribute access on integer literals.
Mark Dickinson <dickinsm@gmail.com>
parents:
62644
diff
changeset
|
441 self.write(" ") |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
442 self.write(".") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
443 self.write(t.attr) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
444 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
445 def _Call(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
446 self.dispatch(t.func) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
447 self.write("(") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
448 comma = False |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
449 for e in t.args: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
450 if comma: self.write(", ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
451 else: comma = True |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
452 self.dispatch(e) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
453 for e in t.keywords: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
454 if comma: self.write(", ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
455 else: comma = True |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
456 self.dispatch(e) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
457 if t.starargs: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
458 if comma: self.write(", ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
459 else: comma = True |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
460 self.write("*") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
461 self.dispatch(t.starargs) |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
462 if t.kwargs: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
463 if comma: self.write(", ") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
464 else: comma = True |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
465 self.write("**") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
466 self.dispatch(t.kwargs) |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
467 self.write(")") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
468 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
469 def _Subscript(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
470 self.dispatch(t.value) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
471 self.write("[") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
472 self.dispatch(t.slice) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
473 self.write("]") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
474 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
475 # slice |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
476 def _Ellipsis(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
477 self.write("...") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
478 |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
479 def _Index(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
480 self.dispatch(t.value) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
481 |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
482 def _Slice(self, t): |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
483 if t.lower: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
484 self.dispatch(t.lower) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
485 self.write(":") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
486 if t.upper: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
487 self.dispatch(t.upper) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
488 if t.step: |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
489 self.write(":") |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
490 self.dispatch(t.step) |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
491 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
492 def _ExtSlice(self, t): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
493 interleave(lambda: self.write(', '), self.dispatch, t.dims) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
494 |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
495 # argument |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
496 def _arg(self, t): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
497 self.write(t.arg) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
498 if t.annotation: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
499 self.write(": ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
500 self.dispatch(t.annotation) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
501 |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
502 # others |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
503 def _arguments(self, t): |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
504 first = True |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
505 # normal arguments |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
506 defaults = [None] * (len(t.args) - len(t.defaults)) + t.defaults |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
507 for a, d in zip(t.args, defaults): |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
508 if first:first = False |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
509 else: self.write(", ") |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
510 self.dispatch(a) |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
511 if d: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
512 self.write("=") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
513 self.dispatch(d) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
514 |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
515 # varargs, or bare '*' if no varargs but keyword-only arguments present |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
516 if t.vararg or t.kwonlyargs: |
|
36736
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
517 if first:first = False |
|
bbce8ec2ff81
unparse.py can now unparse itself.
Martin v. Löwis <martin@v.loewis.de>
parents:
36723
diff
changeset
|
518 else: self.write(", ") |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
519 self.write("*") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
520 if t.vararg: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
521 self.write(t.vararg) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
522 if t.varargannotation: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
523 self.write(": ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
524 self.dispatch(t.varargannotation) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
525 |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
526 # keyword-only arguments |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
527 if t.kwonlyargs: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
528 for a, d in zip(t.kwonlyargs, t.kw_defaults): |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
529 if first:first = False |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
530 else: self.write(", ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
531 self.dispatch(a), |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
532 if d: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
533 self.write("=") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
534 self.dispatch(d) |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
535 |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
536 # kwargs |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
537 if t.kwarg: |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
538 if first:first = False |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
539 else: self.write(", ") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
540 self.write("**"+t.kwarg) |
|
62613
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
541 if t.kwargannotation: |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
542 self.write(": ") |
|
b817e716516e
Update Demo/parser/unparse.py to current Python 3.x syntax. Additions:
Mark Dickinson <dickinsm@gmail.com>
parents:
62612
diff
changeset
|
543 self.dispatch(t.kwargannotation) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
544 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
545 def _keyword(self, t): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
546 self.write(t.arg) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
547 self.write("=") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
548 self.dispatch(t.value) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
549 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
550 def _Lambda(self, t): |
|
62623
fe44828ea7ed
More unparse.py fixes:
Mark Dickinson <dickinsm@gmail.com>
parents:
62622
diff
changeset
|
551 self.write("(") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
552 self.write("lambda ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
553 self.dispatch(t.args) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
554 self.write(": ") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
555 self.dispatch(t.body) |
|
62623
fe44828ea7ed
More unparse.py fixes:
Mark Dickinson <dickinsm@gmail.com>
parents:
62622
diff
changeset
|
556 self.write(")") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
557 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
558 def _alias(self, t): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
559 self.write(t.name) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
560 if t.asname: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
561 self.write(" as "+t.asname) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
562 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
563 def roundtrip(filename, output=sys.stdout): |
|
62621
a4e1c56be532
unparse.py: respect coding cookie in input files
Mark Dickinson <dickinsm@gmail.com>
parents:
62614
diff
changeset
|
564 with open(filename, "rb") as pyfile: |
|
a4e1c56be532
unparse.py: respect coding cookie in input files
Mark Dickinson <dickinsm@gmail.com>
parents:
62614
diff
changeset
|
565 encoding = tokenize.detect_encoding(pyfile.readline)[0] |
|
a4e1c56be532
unparse.py: respect coding cookie in input files
Mark Dickinson <dickinsm@gmail.com>
parents:
62614
diff
changeset
|
566 with open(filename, "r", encoding=encoding) as pyfile: |
|
a4e1c56be532
unparse.py: respect coding cookie in input files
Mark Dickinson <dickinsm@gmail.com>
parents:
62614
diff
changeset
|
567 source = pyfile.read() |
|
62614
95f8b25e53ce
unparse.py: Typo fix.
Mark Dickinson <dickinsm@gmail.com>
parents:
62613
diff
changeset
|
568 tree = compile(source, filename, "exec", ast.PyCF_ONLY_AST) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
569 Unparser(tree, output) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
570 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
571 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
572 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
573 def testdir(a): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
574 try: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
575 names = [n for n in os.listdir(a) if n.endswith('.py')] |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
576 except OSError: |
|
42304
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
577 print("Directory not readable: %s" % a, file=sys.stderr) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
578 else: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
579 for n in names: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
580 fullname = os.path.join(a, n) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
581 if os.path.isfile(fullname): |
|
42304
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
582 output = io.StringIO() |
|
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
583 print('Testing %s' % fullname) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
584 try: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
585 roundtrip(fullname, output) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
586 except Exception as e: |
|
42304
7d16b42fcdbd
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Collin Winter <collinw@gmail.com>
parents:
41554
diff
changeset
|
587 print(' Failed to compile, exception is %s' % repr(e)) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
588 elif os.path.isdir(fullname): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
589 testdir(fullname) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
590 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
591 def main(args): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
592 if args[0] == '--testdir': |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
593 for a in args[1:]: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
594 testdir(a) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
595 else: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
596 for a in args: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
597 roundtrip(a) |
|
36723
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
598 |
|
e580c8b0dcea
Set EOL style to native.
Tim Peters <tim.peters@gmail.com>
parents:
36721
diff
changeset
|
599 if __name__=='__main__': |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36736
diff
changeset
|
600 main(sys.argv[1:]) |
