diff -r 7ed2e831acd4 -r 865cd526e8b6 parse.py --- a/parse.py Fri May 24 14:18:28 2019 +0200 +++ b/parse.py Fri May 24 14:18:31 2019 +0200 @@ -15,7 +15,7 @@ elif line == '0': return linetypes.Comment('') elif line.startswith('0 '): - return linetypes.Comment(line[2:].strip()) + return linetypes.Comment(line[2:]) elif line.startswith('1 '): return parse_ldraw_subfile_reference(line) elif line.startswith('2 '): @@ -25,7 +25,7 @@ elif line.startswith('4 '): return parse_ldraw_quadrilateral(line) elif line.startswith('5 '): - return parse_ldraw_contour(line) + return parse_ldraw_conditional_line(line) else: raise BadLdrawLine('unknown line type') @@ -55,11 +55,11 @@ ) def generic_parse_polygon(line, *, type_code, vertex_count): - pattern = r'^' \ - + str(type_code) \ - + '\s+([^ ]+)' \ - + r'\s+([^ ]+)' * (vertex_count * 3) \ - + r'\s*$' + pattern = r'^' # matches the start of line + pattern += str(type_code) # matches the type code + pattern += '\s+([^ ]+)' # matches the colour + pattern += r'\s+([^ ]+)' * (vertex_count * 3) # matches the vertices + pattern += r'\s*$' # matches any trailing space match = re.search(pattern, line) if not match: raise BadLdrawLine(str.format('cannot parse type-{} line', type_code)) @@ -100,9 +100,9 @@ geometry = Polygon(parse_result['vertices']), ) -def parse_ldraw_contour(line): +def parse_ldraw_conditional_line(line): parse_result = generic_parse_polygon(line, type_code = 5, vertex_count = 4) - return linetypes.Contour( + return linetypes.ConditionalLine( colour = parse_result['colour'], geometry = LineSegment(*parse_result['vertices'][0:2]), control_points = parse_result['vertices'][2:],