annotate python/ppci/common.py @ 293:6aa721e7b10b

Try to improve build sequence
author Windel Bouwman
date Thu, 28 Nov 2013 20:39:37 +0100
parents 534b94b40aa8
children 2c9768114877
rev   line source
153
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
1 from collections import namedtuple
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
2
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
3
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents: 163
diff changeset
4 # Token is used in the lexical analyzer:
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
5 class Token:
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
6 def __init__(self, typ, val, loc=None):
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
7 self.typ = typ
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
8 self.val = val
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
9 if loc is None:
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
10 loc = SourceLocation('', 0, 0, 0)
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
11 assert type(loc) is SourceLocation
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
12 self.loc = loc
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 287
diff changeset
13
194
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
14 def __repr__(self):
b01429a5d695 Fixed test
Windel Bouwman
parents: 191
diff changeset
15 return 'Token({0}, {1})'.format(self.typ, self.val)
191
6b2bec5653f1 Added assembler testset
Windel Bouwman
parents: 163
diff changeset
16
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
17
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
18 class SourceLocation:
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
19 def __init__(self, filename, row, col, ln):
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
20 self.filename = filename
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
21 self.row = row
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
22 self.col = col
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
23 self.length = ln
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
24
e41e4109addd Added current position arrow
Windel Bouwman
parents: 194
diff changeset
25 def __repr__(self):
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
26 return '{}, {}, {}'.format(self.filename, self.row, self.col)
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 153
diff changeset
27
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 249
diff changeset
28
153
e05b2b216bfc Added common
Windel Bouwman
parents:
diff changeset
29 SourceRange = namedtuple('SourceRange', ['p1', 'p2'])