linetypes.py

Sun, 10 Dec 2017 15:45:50 +0200

author
Santeri Piippo
date
Sun, 10 Dec 2017 15:45:50 +0200
changeset 1
5411a25cfca7
parent 0
55b4c97d44c5
child 3
1dc58f44d556
permissions
-rw-r--r--

Parsing function complete

0
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
1 class EmptyLine:
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
2 def __repr__(self):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
3 return 'linetypes.EmptyLine()'
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
4
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
5 class Comment:
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
6 def __init__(self, text, style = 'old'):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
7 if style == 'old' and text.startswith('//'):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
8 self.text = text[3:].strip()
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
9 self.style = 'new'
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
10 else:
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
11 self.text = text
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
12 self.style = style
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
13 def __repr__(self):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
14 return str.format('linetypes.Comment({text!r}, {style!r})',
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
15 text = self.text,
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
16 style = self.style,
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
17 )
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
18
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
19 class SubfileReference:
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
20 def __init__(self, *, color, subfile_path, anchor, matrix):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
21 self.color, self.subfile_path, = color, subfile_path
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
22 self.anchor, self.matrix = anchor, matrix
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
23 def __repr__(self):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
24 return str.format('linetypes.SubfileReference(' \
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
25 'color = {color!r}, ' \
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
26 'subfile_path = {subfile_path!r}, ' \
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
27 'anchor = {anchor!r}, ' \
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
28 'matrix = {matrix!r})', **self.__dict__)
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
29
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
30 class LineSegment:
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
31 def __init__(self, *, color, geometry):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
32 self.color, self.geometry = color, geometry
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
33 def __repr__(self):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
34 return str.format('linetypes.{typename}(' \
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
35 'color = {color!r}, ' \
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
36 'geometry = {geometry!r})',
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
37 typename = type(self).__name__,
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
38 color = self.color,
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
39 geometry = self.geometry,
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
40 )
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
41
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
42 class Triangle(LineSegment):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
43 pass
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
44
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
45 class Quadrilateral(LineSegment):
55b4c97d44c5 Initial commit with half-done parsing function
Santeri Piippo
parents:
diff changeset
46 pass
1
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
47
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
48 class Contour(LineSegment):
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
49 def __init__(self, *, color, geometry, control_points):
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
50 super().__init__(color = color, geometry = geometry)
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
51 self.control_points = control_points
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
52 assert(len(self.control_points) == 2)
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
53 def __repr__(self):
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
54 return str.format('linetypes.Contour(' \
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
55 'color = {color!r}, ' \
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
56 'geometry = {geometry!r}, ' \
5411a25cfca7 Parsing function complete
Santeri Piippo
parents: 0
diff changeset
57 'control_points = {control_points!r})', **self.__dict__)

mercurial