def Pop(self, n=1, tokenMarker=None): top = None for i in range(n): top = self._stack.pop() LineTerminal().WriteDebug("popped: " + str(top[0])) self.NextState = top[0] self.Counter = top[1] self._tokenMarker = tokenMarker
def Print(self, indent=0): indentation = " " * indent print( "{indent}{DARK_CYAN}CONSTANT {GREEN}{name}{NOCOLOR} : {GREEN}{type}{NOCOLOR} := xxx;" .format(indent=indentation, name=self._name, type="", **LineTerminal().Foreground))
def TokenMarker(self) -> Token: if ((self.NewToken is not None) and (self._tokenMarker is self.Token)): LineTerminal().WriteDebug( " {DARK_GREEN}@TokenMarker: {0!s} => {GREEN}{1!s}{NOCOLOR}". format(self._tokenMarker, self.NewToken, **LineTerminal.Foreground)) self._tokenMarker = self.NewToken return self._tokenMarker
def GetGenerator(self) -> Generator['Block', Token, None]: from pyVHDLParser.Token import EndOfDocumentToken from pyVHDLParser.Blocks import BlockParserException, EndOfDocumentBlock from pyVHDLParser.Blocks.Common import LinebreakBlock, EmptyLineBlock for token in self._iterator: # set parserState.Token to current token self.Token = token # overwrite an existing token and connect the next token with the new one if (self.NewToken is not None): # print("{MAGENTA}NewToken: {token}{NOCOLOR}".format(token=self.NewToken, **Console.Foreground)) # update topmost TokenMarker if (self._tokenMarker is token.PreviousToken): # XXX: LineTerminal().WriteDebug(" update token marker: {0!s} -> {1!s}".format(self._tokenMarker, self.NewToken)) self._tokenMarker = self.NewToken token.PreviousToken = self.NewToken self.NewToken = None # an empty marker means: fill on next yield run if (self._tokenMarker is None): LineTerminal().WriteDebug( " new token marker: None -> {0!s}".format(token)) self._tokenMarker = token # a new block is assembled while (self.NewBlock is not None): if (isinstance(self.NewBlock, LinebreakBlock) and isinstance(self.LastBlock, (LinebreakBlock, EmptyLineBlock))): self.LastBlock = EmptyLineBlock(self.LastBlock, self.NewBlock.StartToken) self.LastBlock.NextBlock = self.NewBlock.NextBlock else: self.LastBlock = self.NewBlock self.NewBlock = self.NewBlock.NextBlock yield self.LastBlock # if self.debug: print("{MAGENTA}------ iteration end ------{NOCOLOR}".format(**Console.Foreground)) # XXX: LineTerminal().WriteDebug(" {DARK_GRAY}state={state!s: <50} token={token!s: <40}{NOCOLOR} ".format(state=self, token=token, **LineTerminal.Foreground)) # execute a state self.NextState(self) else: if (isinstance(self.Token, EndOfDocumentToken) and isinstance(self.NewBlock, EndOfDocumentBlock)): yield self.NewBlock else: raise BlockParserException("Unexpected end of document.", self.Token)
def Print(self, indent=0): indentation = " "*indent for lib in self._libraries: print("{indent}{DARK_CYAN}LIBRARY{NOCOLOR} {GREEN}{lib}{NOCOLOR};".format(indent=indentation, lib=lib, **LineTerminal().Foreground)) for use in self._uses: print("{indent}{DARK_CYAN}USE {GREEN}{lib}{NOCOLOR}.{GREEN}{pack}{NOCOLOR}.{GREEN}{item}{NOCOLOR};".format(indent=indentation, lib=use._configuration, pack=use._function, item=use._item, **LineTerminal().Foreground)) print() print("{indent}{DARK_CYAN}FUNCTION{NOCOLOR} {YELLOW}{name}{NOCOLOR} {DARK_CYAN}IS{NOCOLOR}".format(indent=indentation, name=self._name, **LineTerminal().Foreground)) if (len(self._genericItems) > 0): print("{indent} {DARK_CYAN}GENERIC{NOCOLOR} (".format(indent=indentation, **LineTerminal().Foreground)) for generic in self._genericItems: print("{indent} {YELLOW}{name}{NOCOLOR} : {GREEN}{type}{NOCOLOR}".format(indent=indentation, name=generic, type="", **LineTerminal().Foreground)) print("{indent} );".format(indent=indentation)) if (len(self._declaredItems) > 0): for item in self._declaredItems: item.Print(indent+1) print("{indent}{DARK_CYAN}END FUNCTION{NOCOLOR};".format(indent=indentation, name=self._name, **LineTerminal().Foreground))
def GetGenerator(self): # XXX: return type from pyVHDLParser.Groups import GroupParserException # yield StartOfDocumentGroup self.LastGroup = self.NextGroup yield self.LastGroup for block in self._iterator: # an empty marker means: set on next yield run if (self._blockMarker is None): # if self.debug: print(" new block marker: None -> {0!s}".format(block)) self._blockMarker = block # if self.debug: print("{MAGENTA}------ iteration end ------{NOCOLOR}".format(**Console.Foreground)) # execute a state and reissue execution if needed self.ReIssue = True while self.ReIssue: self.ReIssue = False LineTerminal().WriteDryRun( "{DARK_GRAY}reissue state={state!s: <50} block={block!s: <40} {NOCOLOR}" .format(state=self, block=self.Block, **LineTerminal.Foreground)) self.NextState(self) # yield a new group if (self.NewGroup is not None): yield self.NewGroup self.LastGroup = self.NewGroup self.NewGroup = None if (isinstance(self.Block, EndOfDocumentBlock) and isinstance(self.LastGroup, EndOfDocumentGroup)): return else: raise GroupParserException("Unexpected end of document.", self.Block)
def __str__(self): return "{GREEN}{0}{NOCOLOR} : {YELLOW}{1}{NOCOLOR}".format( self._name, self._subType, **LineTerminal().Foreground)
def AddConstant(self, constant): if DEBUG: print("{DARK_CYAN}Adding constant to function {GREEN}{0}{NOCOLOR}:\n {1!s}".format(self._name, constant, **LineTerminal().Foreground)) self._declaredItems.append(constant)
def AddGeneric(self, generic): if DEBUG: print("{DARK_CYAN}Adding generic to function {GREEN}{0}{NOCOLOR}:\n {YELLOW}{1}{NOCOLOR} : {2}".format(self._name, generic, "", **LineTerminal().Foreground)) self._genericItems.append(generic)
def AddUses(self, uses: List[PackageReference]): if ((DEBUG is True) and (len(uses) > 0)): print("{DARK_CYAN}Adding uses to function {GREEN}{0}{NOCOLOR}:".format(self._name, **LineTerminal().Foreground)) for use in uses: if DEBUG: print(" {GREEN}{0!s}{NOCOLOR}".format(use, **LineTerminal().Foreground)) self._uses.append(use)
def AddLibraries(self, libraries: List[LibraryClause]): if ((DEBUG is True) and (len(libraries) > 0)): print("{DARK_CYAN}Adding libraries to function {GREEN}{0}{NOCOLOR}:".format(self._name, **LineTerminal().Foreground)) for library in libraries: if DEBUG: print(" {GREEN}{0!s}{NOCOLOR}".format(library, **LineTerminal().Foreground)) self._libraries.append(library._library)
def PushState(self, value): self._stack.append((self.NextState, self.Counter)) LineTerminal().WriteDebug(" pushed: " + str(self.NextState)) self.NextState = value self._tokenMarker = None