linetypes.py

changeset 38
66c9591b733d
parent 35
865cd526e8b6
child 65
f2dc17b830e0
child 91
c71a7d863c2e
equal deleted inserted replaced
37:e46fa477007b 38:66c9591b733d
14 def textual_representation(self): 14 def textual_representation(self):
15 return '' 15 return ''
16 def typename(self): 16 def typename(self):
17 return 'empty line' 17 return 'empty line'
18 18
19 class MetaCommand:
20 def __init__(self, text, style = 'old'):
21 self.text = text
22 def __repr__(self):
23 return str.format('linetypes.MetaCommand({text!r})',
24 text = self.text,
25 )
26 def textual_representation(self):
27 return ('0 ' + self.text).strip()
28 def typename(self):
29 return 'metacommand'
30
19 class Comment: 31 class Comment:
20 def __init__(self, text, style = 'old'): 32 def __init__(self, text, style = 'old'):
21 if style == 'old' and text.startswith('//'): 33 self.text = text
22 self.text = text[2:].strip()
23 self.style = 'new'
24 else:
25 self.text = text
26 self.style = style
27 def __repr__(self): 34 def __repr__(self):
28 return str.format('linetypes.Comment({text!r}, {style!r})', 35 return str.format('linetypes.Comment({text!r})',
29 text = self.text, 36 text = self.text,
30 style = self.style,
31 ) 37 )
32 def textual_representation(self): 38 def textual_representation(self):
33 if self.style == 'old': 39 return '0 //' + self.text
34 return '0 ' + self.text
35 else:
36 return '0 // ' + self.text
37 def typename(self): 40 def typename(self):
38 return 'comment' 41 return 'comment'
39 42
40 class SubfileReference: 43 class SubfileReference:
41 def __init__(self, *, colour, subfile_path, anchor, matrix): 44 def __init__(self, *, colour, subfile_path, anchor, matrix):
111 result += ' ' 114 result += ' '
112 result += ' '.join(strings) 115 result += ' '.join(strings)
113 return result 116 return result
114 def typename(self): 117 def typename(self):
115 return 'contour line segment' 118 return 'contour line segment'
119
120 class Error:
121 def __init__(self, line, reason):
122 self.line = line
123 self.reason = reason
124 def __repr__(self):
125 return str.format(
126 'linetypes.Error(line = {line!r}, reason = {reason!r})',
127 line = self.line,
128 reason = self.reason,
129 )
130 def textual_representation(self):
131 return self.line

mercurial