better handling of ldraw code

Mon, 22 Jan 2018 17:46:48 +0200

author
Santeri Piippo
date
Mon, 22 Jan 2018 17:46:48 +0200
changeset 19
9169bad392c4
parent 18
672ebc45685a
child 20
db2300032678

better handling of ldraw code

parse.py file | annotate | diff | comparison | revisions
testsuite.py file | annotate | diff | comparison | revisions
--- a/parse.py	Mon Jan 22 17:42:57 2018 +0200
+++ b/parse.py	Mon Jan 22 17:46:48 2018 +0200
@@ -9,25 +9,23 @@
 def parse_ldraw_code(line):
     line = line.strip()
     if not line:
-        object = linetypes.EmptyLine()
+        return linetypes.EmptyLine()
     elif line == '0':
-        object = linetypes.Comment('')
+        return linetypes.Comment('')
     elif line.startswith('0 '):
-        object = linetypes.Comment(line[2:].strip())
+        return linetypes.Comment(line[2:].strip())
     elif line.startswith('1 '):
-        object = parse_ldraw_subfile_reference(line)
+        return parse_ldraw_subfile_reference(line)
     elif line.startswith('2 '):
-        object = parse_ldraw_line(line)
+        return parse_ldraw_line(line)
     elif line.startswith('3 '):
-        object = parse_ldraw_triangle(line)
+        return parse_ldraw_triangle(line)
     elif line.startswith('4 '):
-        object = parse_ldraw_quadrilateral(line)
+        return parse_ldraw_quadrilateral(line)
     elif line.startswith('5 '):
-        object = parse_ldraw_contour(line)
+        return parse_ldraw_contour(line)
     else:
         raise BadLdrawLine('unknown line type')
-    object.original_code = line
-    return object
 
 def parse_ldraw_subfile_reference(line):
     pattern = r'^1\s+([^ ]+)' + r'\s+([^ ]+)' * (3 + 9 + 1) + r'\s*$'
--- a/testsuite.py	Mon Jan 22 17:42:57 2018 +0200
+++ b/testsuite.py	Mon Jan 22 17:46:48 2018 +0200
@@ -98,16 +98,17 @@
             text_colour = colorama.Fore.LIGHTYELLOW_EX
         else:
             text_colour = ''
+        ldraw_code = model.body[problem['body-index']].textual_representation()
         message = str.format(
             '{text_colour}{model_name}:{line_number}: {problem_type}: {message}'
-            '{colour_reset}\n\t{trouble_source}',
+            '{colour_reset}\n\t{ldraw_code}',
             text_colour = text_colour,
             model_name = model.name,
             line_number = problem['line-number'],
             problem_type = problem['type'],
             message = problem_text,
             colour_reset = colorama.Fore.RESET,
-            trouble_source = model.body[problem['body-index']].original_code,
+            ldraw_code = ldraw_code,
         )
         result.append((problem['line-number'], message))
     return '\n'.join(

mercurial