diff --git a/gds/library.py b/gds/library.py index 88ab6ca..2889fda 100644 --- a/gds/library.py +++ b/gds/library.py @@ -37,7 +37,6 @@ class Library(object): count = Progress(self) for key, value in self.structures.items(): - for element in value.references: if isinstance(element.structure, str): # try to resolve link diff --git a/gds/parser.py b/gds/parser.py index 9c1ff18..c3f0179 100644 --- a/gds/parser.py +++ b/gds/parser.py @@ -122,6 +122,7 @@ class Parser(Reader): def parse_structure(self): self.structure = Structure() + print(self.structure.references) if self.token.ident != Records.BGNSTR: return False @@ -166,16 +167,18 @@ class Parser(Reader): element.plex = self.read_int() self.next_token(True) - def parse_boundary(self): - element = Boundary() - if not self.next_token(): + def parse_layer(self, element): + if self.token.ident != Records.LAYER: raise ParserError(errors.EXPECTED_LAYER) - self.parse_element(element) + element.layer = self.read_ushort() + + def parse_boundary(self): + element = Boundary() + self.next_token(True) + self.parse_element(element) + self.parse_layer(element) - if self.token.ident == Records.LAYER: - element.layer = self.read_short() - if not self.next_token() or self.token.ident != Records.DATATYPE: raise ParserError(errors.EXPECTED_DATATYPE) @@ -193,15 +196,9 @@ class Parser(Reader): def parse_path(self): element = Path() - if not self.next_token(): - raise ParserError(errors.EXPECTED_LAYER) - + self.next_token(True) self.parse_element(element) - - if self.token.ident != Records.LAYER: - raise ParserError(errors.EXPECTED_LAYER) - - element.layer = self.read_short() + self.parse_layer(element) if not self.next_token() or self.token.ident != Records.DATATYPE: raise ParserError(errors.EXPECTED_DATATYPE) @@ -246,15 +243,9 @@ class Parser(Reader): def parse_text(self): element = Text() - if not self.next_token(): - raise ParserError(errors.EXPECTED_LAYER) - + self.next_token(True) self.parse_element(element) - - if not self.token.ident == Records.LAYER: - raise ParserError(errors.EXPECTED_LAYER) - - element.layer = self.read_short() + self.parse_layer(element) if not self.next_token() or self.token.ident != Records.TEXTTYPE: raise ParserError(errors.EXPECTED_TEXTTYPE) @@ -298,12 +289,13 @@ class Parser(Reader): raise ParserError(errors.EXPECTED_ENDEL) self.structure.elements.append(element) + def parse_strans(self, trans:Transformation): if self.token.ident != Records.STRANS: return - flags = self.read_short() + flags = self.read_ushort() if flags & 0x01: trans.mirror_x = True @@ -325,15 +317,9 @@ class Parser(Reader): def parse_box(self): element = Box() - if not self.next_token(): - raise ParserError(errors.EXPECTED_LAYER) - + self.next_token(True) self.parse_element(element) - - if self.token.ident != Records.LAYER: - raise ParserError(errors.EXPECTED_LAYER) - - element.layer = self.read_short() + self.parse_layer(element) if not self.next_token() or self.token.ident != Records.BOXTYPE: raise ParserError(errors.EXPECTED_BOXTYPE) @@ -393,6 +379,7 @@ class Parser(Reader): element.structure = self.read_ascii(self.token.len) self.next_token(True) + self.parse_strans(element.transformation) if self.token.ident != Records.COLROW: diff --git a/gds/structure.py b/gds/structure.py index f79cf1a..c6b0a0c 100644 --- a/gds/structure.py +++ b/gds/structure.py @@ -8,5 +8,6 @@ class Structure(object): # contains all the low level elements elements = [] + # contains all sref and aref elements - references = [] \ No newline at end of file + references = [] \ No newline at end of file