improved header extent scanning

Sun, 23 Jun 2019 12:09:20 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 23 Jun 2019 12:09:20 +0300
changeset 77
d98502ae1f33
parent 76
c73432653fd9
child 78
1970afe52da4

improved header extent scanning

header.py file | annotate | diff | comparison | revisions
ldcheck.py file | annotate | diff | comparison | revisions
--- a/header.py	Sun Jun 23 00:55:21 2019 +0300
+++ b/header.py	Sun Jun 23 12:09:20 2019 +0300
@@ -42,13 +42,6 @@
     def valid(self):
         return False
 
-geometrical_types = [
-    linetypes.LineSegment,
-    linetypes.Triangle,
-    linetypes.Quadrilateral,
-    linetypes.ConditionalLine,
-]
-
 def is_invertnext(entry):
     return isinstance(entry, linetypes.MetaCommand) \
         and entry.text == "BFC INVERTNEXT"
@@ -60,7 +53,11 @@
     return not any(
         isinstance(entry, linetype)
         for linetype in [
-            *geometrical_types,
+            linetypes.SubfileReference,
+            linetypes.LineSegment,
+            linetypes.Triangle,
+            linetypes.Quadrilateral,
+            linetypes.ConditionalLine,
             linetypes.Comment,
             linetypes.Error,
         ]
@@ -166,7 +163,8 @@
                 'cmdline'):
                 result.cmdline = self.groups[0]
             else:
-                self.parse_error("couldn't understand header syntax: " + repr(header_entry.text))
+                self.cursor -= 1
+                break
         if not result.filetype:
             self.parse_error('LDRAW_ORG line is missing')
         return {
@@ -176,15 +174,16 @@
     def parse_error(self, message):
         raise HeaderError(index = self.cursor, reason = message)
     def get_more_header_stuff(self):
-        while True:
-            self.cursor += 1
-            if self.cursor >= len(self.model_body):
-                break
-            entry = self.model_body[self.cursor]
+        self.cursor += 1
+        new_cursor = self.cursor
+        while new_cursor < len(self.model_body):
+            entry = self.model_body[new_cursor]
             if not is_suitable_header_object(entry):
                 break
             if isinstance(entry, linetypes.MetaCommand):
+                self.cursor = new_cursor
                 yield entry
+            new_cursor += 1
     def skip_to_next(self, *, spaces_expected = 0):
         while True:
             if self.cursor + 1 >= len(self.model_body):
--- a/ldcheck.py	Sun Jun 23 00:55:21 2019 +0300
+++ b/ldcheck.py	Sun Jun 23 12:09:20 2019 +0300
@@ -88,7 +88,7 @@
         action = ListTestSuiteAction,
         help = 'Lists all possible checks and exit',
     )
-    parser.add_argument('--dump-structure', action = 'store_true')
+    parser.add_argument('--dump', action = 'store_true')
     parser.add_argument('--rebuild', action = 'store_true')
     parser.add_argument('--flatness', action = 'store_true')
     args = parser.parse_args()
@@ -119,12 +119,14 @@
                 file,
                 name = basename(args.filename),
                 ldraw_directories = config['libraries'])
-            if args.dump_structure:
+            if args.dump:
                 print('header: ' + type(model.header).__name__)
                 for key in sorted(dir(model.header)):
                     if not key.startswith('__'):
                         print('\t' + key + ': ' + repr(getattr(model.header, key)))
-                for entry in model.body:
+                for i, entry in enumerate(model.body):
+                    if model.header.valid and i == model.header_size:
+                        print('--------- End of header')
                     print(entry)
             elif args.rebuild:
                 for entry in model.body:

mercurial