--- a/parse.py Sun Dec 10 15:46:47 2017 +0200 +++ b/parse.py Mon Dec 11 00:46:35 2017 +0200 @@ -1,6 +1,7 @@ import linetypes import re from geometry import * +from ldraw import Color class BadLdrawLine(Exception): pass @@ -27,19 +28,19 @@ raise BadLdrawLine('unknown line type') def parse_ldraw_subfile_reference(line): - pattern = r'^1\s+(\d+)' + r'\s+([^ ]+)' * (3 + 9 + 1) + r'\s*$' + pattern = r'^1\s+([^ ]+)' + r'\s+([^ ]+)' * (3 + 9 + 1) + r'\s*$' match = re.search(pattern, line) if not match: raise BadLdrawLine('unable to parse') groups = list(match.groups()) indices = { - 'color': 0, + 'color_index': 0, 'anchor': slice(1, 4), 'matrix': slice(4, 13), 'subfile_path': 13 } try: - color = int(groups[indices['color']]) + color = Color(groups[indices['color_index']]) vertex_values = [float(x) for x in groups[indices['anchor']]] matrix_values = [float(x) for x in groups[indices['matrix']]] except ValueError: @@ -54,7 +55,7 @@ def generic_parse_polygon(line, *, type_code, vertex_count): pattern = r'^' \ + str(type_code) \ - + '\s+(\d+)' \ + + '\s+([^ ]+)' \ + r'\s+([^ ]+)' * (vertex_count * 3) \ + r'\s*$' match = re.search(pattern, line) @@ -72,7 +73,7 @@ raise BadLdrawLine('bad numeric values') vertices.append(Vertex(*coordinates)) return { - 'color': int(match.group(1)), + 'color': Color(match.group(1)), 'vertices': vertices, }