parse.py

changeset 17
327da5d00360
parent 8
303c51137cb2
child 19
9169bad392c4
equal deleted inserted replaced
16:09cc89622262 17:327da5d00360
7 pass 7 pass
8 8
9 def parse_ldraw_code(line): 9 def parse_ldraw_code(line):
10 line = line.strip() 10 line = line.strip()
11 if not line: 11 if not line:
12 return linetypes.EmptyLine() 12 object = linetypes.EmptyLine()
13 elif line == '0': 13 elif line == '0':
14 return linetypes.Comment('') 14 object = linetypes.Comment('')
15 elif line.startswith('0 '): 15 elif line.startswith('0 '):
16 return linetypes.Comment(line[2:].strip()) 16 object = linetypes.Comment(line[2:].strip())
17 elif line.startswith('1 '): 17 elif line.startswith('1 '):
18 return parse_ldraw_subfile_reference(line) 18 object = parse_ldraw_subfile_reference(line)
19 elif line.startswith('2 '): 19 elif line.startswith('2 '):
20 return parse_ldraw_line(line) 20 object = parse_ldraw_line(line)
21 elif line.startswith('3 '): 21 elif line.startswith('3 '):
22 return parse_ldraw_triangle(line) 22 object = parse_ldraw_triangle(line)
23 elif line.startswith('4 '): 23 elif line.startswith('4 '):
24 return parse_ldraw_quadrilateral(line) 24 object = parse_ldraw_quadrilateral(line)
25 elif line.startswith('5 '): 25 elif line.startswith('5 '):
26 return parse_ldraw_contour(line) 26 object = parse_ldraw_contour(line)
27 else: 27 else:
28 raise BadLdrawLine('unknown line type') 28 raise BadLdrawLine('unknown line type')
29 object.original_code = line
30 return object
29 31
30 def parse_ldraw_subfile_reference(line): 32 def parse_ldraw_subfile_reference(line):
31 pattern = r'^1\s+([^ ]+)' + r'\s+([^ ]+)' * (3 + 9 + 1) + r'\s*$' 33 pattern = r'^1\s+([^ ]+)' + r'\s+([^ ]+)' * (3 + 9 + 1) + r'\s*$'
32 match = re.search(pattern, line) 34 match = re.search(pattern, line)
33 if not match: 35 if not match:

mercurial