added ability to get other header elements than just the first one

Tue, 25 Aug 2020 22:31:16 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 25 Aug 2020 22:31:16 +0300
changeset 101
745f2c3aec0a
parent 100
62759e5c4554
child 102
952e2a9a669b

added ability to get other header elements than just the first one

header.py file | annotate | diff | comparison | revisions
parse.py file | annotate | diff | comparison | revisions
--- a/header.py	Tue Aug 25 22:20:15 2020 +0300
+++ b/header.py	Tue Aug 25 22:31:16 2020 +0300
@@ -21,7 +21,8 @@
         self.keywords = ''
         self.cmdline = None
         self.history = []
-        self.first_occurrence = dict()
+        from collections import defaultdict
+        self.occurrences = defaultdict(list)
     @property
     def valid(self):
         return True
@@ -272,8 +273,7 @@
         match = re.search(pattern, self.current())
         if match:
             self.order.append(description)
-            if description not in self.result.first_occurrence:
-                self.result.first_occurrence[description] = self.cursor
+            list.append(self.result.occurrences[description], self.cursor)
             return match.groups()
         else:
             self.parse_error(str.format("couldn't parse {}", description))
--- a/parse.py	Tue Aug 25 22:20:15 2020 +0300
+++ b/parse.py	Tue Aug 25 22:31:16 2020 +0300
@@ -39,7 +39,9 @@
     def has_header(self):
         return self.header and not isinstance(self.header, header.BadHeader)
     def find_first_header_object(self, object_type):
-        return self.body[self.header.first_occurrence[object_type]]
+        return self.find_header_object(object_type, 0)
+    def find_header_object(self, object_type, n):
+        return self.body[self.header.occurrences[object_type][n]]
 
 def model_vertices(
     model,

mercurial