diff --git a/vsg/vhdlFile/extract/__init__.py b/vsg/vhdlFile/extract/__init__.py new file mode 100644 index 00000000..4824be08 --- /dev/null +++ b/vsg/vhdlFile/extract/__init__.py @@ -0,0 +1,4 @@ + +from .get_sequence_of_tokens_matching import get_sequence_of_tokens_matching +from .get_sequence_of_tokens_matching_bounded_by_tokens import get_sequence_of_tokens_matching_bounded_by_tokens +from .get_tokens_matching import get_tokens_matching diff --git a/vsg/vhdlFile/extract/get_sequence_of_tokens_matching.py b/vsg/vhdlFile/extract/get_sequence_of_tokens_matching.py new file mode 100644 index 00000000..f379a27f --- /dev/null +++ b/vsg/vhdlFile/extract/get_sequence_of_tokens_matching.py @@ -0,0 +1,31 @@ + +from vsg import parser +from vsg.vhdlFile import vhdlFile as utils + + +def get_sequence_of_tokens_matching(lTokens, lAllTokens): + iLine = 1 + lTemp = [] + lReturn = [] + iMatchCount = 0 + iMatchLength = len(lTokens) + iStart = 0 + for iIndex in range(0, len(lAllTokens)): + + if isinstance(lAllTokens[iIndex], lTokens[iMatchCount]): + if iMatchCount == 0: + iStart = iIndex + lTemp.append(lAllTokens[iIndex]) + iMatchCount +=1 + if iMatchCount == iMatchLength: + lReturn.append(utils.Tokens(iStart, iLine, lTemp)) + lTemp = [] + iMatchCount = 0 + elif iMatchCount > 0: + lTemp = [] + iMatchCount = 0 + + if isinstance(lAllTokens[iIndex], parser.carriage_return): + iLine +=1 + + return lReturn diff --git a/vsg/vhdlFile/extract/get_sequence_of_tokens_matching_bounded_by_tokens.py b/vsg/vhdlFile/extract/get_sequence_of_tokens_matching_bounded_by_tokens.py new file mode 100644 index 00000000..2e9f71a6 --- /dev/null +++ b/vsg/vhdlFile/extract/get_sequence_of_tokens_matching_bounded_by_tokens.py @@ -0,0 +1,43 @@ + +from vsg import parser + +from vsg.vhdlFile import vhdlFile as utils + + +def get_sequence_of_tokens_matching_bounded_by_tokens(lTokens, oStart, oEnd, lAllTokens): + iLine = 1 + lTemp = [] + lReturn = [] + iMatchCount = 0 + iMatchLength = len(lTokens) + iStart = 0 + bCheck = False + for iIndex in range(0, len(lAllTokens)): + + if isinstance(lAllTokens[iIndex], oStart): + bCheck = True + lTemp = [] + iMatchCount = 0 + if isinstance(lAllTokens[iIndex], oEnd): + bCheck = False + lTemp = [] + iMatchCount = 0 + + if bCheck: + if isinstance(lAllTokens[iIndex], lTokens[iMatchCount]): + if iMatchCount == 0: + iStart = iIndex + lTemp.append(lAllTokens[iIndex]) + iMatchCount +=1 + if iMatchCount == iMatchLength: + lReturn.append(utils.Tokens(iStart, iLine, lTemp)) + lTemp = [] + iMatchCount = 0 + elif iMatchCount > 0: + lTemp = [] + iMatchCount = 0 + + if isinstance(lAllTokens[iIndex], parser.carriage_return): + iLine +=1 + + return lReturn diff --git a/vsg/vhdlFile/extract/get_tokens_matching.py b/vsg/vhdlFile/extract/get_tokens_matching.py new file mode 100644 index 00000000..aca4f702 --- /dev/null +++ b/vsg/vhdlFile/extract/get_tokens_matching.py @@ -0,0 +1,18 @@ + +from vsg import parser + +from vsg.vhdlFile import vhdlFile as utils + + +def get_tokens_matching(lTokens, lAllTokens): + iLine = 1 + lReturn = [] + for iIndex in range(0, len(lAllTokens)): + for oToken in lTokens: + if isinstance(lAllTokens[iIndex], oToken): + lReturn.append(utils.Tokens(iIndex, iLine, [lAllTokens[iIndex]])) + + if isinstance(lAllTokens[iIndex], parser.carriage_return): + iLine +=1 + + return lReturn diff --git a/vsg/vhdlFile/vhdlFile.py b/vsg/vhdlFile/vhdlFile.py index e2bc20c1..23629ac9 100644 --- a/vsg/vhdlFile/vhdlFile.py +++ b/vsg/vhdlFile/vhdlFile.py @@ -4,7 +4,7 @@ from vsg import parser from vsg import token from vsg.vhdlFile import classify - +from vsg.vhdlFile import extract from vsg.vhdlFile import update from vsg.vhdlFile import utils @@ -33,6 +33,7 @@ from vsg.vhdlFile.indent import variable_assignment_statement from vsg.vhdlFile.indent import wait_statement + class vhdlFile(): ''' Holds contents of a VHDL file. @@ -469,82 +470,13 @@ class vhdlFile(): def get_sequence_of_tokens_matching(self, lTokens): - iLine = 1 - lTemp = [] - lReturn = [] - iMatchCount = 0 - iMatchLength = len(lTokens) - iStart = 0 - for iIndex in range(0, len(self.lAllObjects)): - - if isinstance(self.lAllObjects[iIndex], lTokens[iMatchCount]): - if iMatchCount == 0: - iStart = iIndex - lTemp.append(self.lAllObjects[iIndex]) - iMatchCount +=1 - if iMatchCount == iMatchLength: - lReturn.append(Tokens(iStart, iLine, lTemp)) - lTemp = [] - iMatchCount = 0 - elif iMatchCount > 0: - lTemp = [] - iMatchCount = 0 - - if isinstance(self.lAllObjects[iIndex], parser.carriage_return): - iLine +=1 - - return lReturn + return extract.get_sequence_of_tokens_matching(lTokens, self.lAllObjects) def get_sequence_of_tokens_matching_bounded_by_tokens(self, lTokens, oStart, oEnd): - iLine = 1 - lTemp = [] - lReturn = [] - iMatchCount = 0 - iMatchLength = len(lTokens) - iStart = 0 - bCheck = False - for iIndex in range(0, len(self.lAllObjects)): - - if isinstance(self.lAllObjects[iIndex], oStart): - bCheck = True - lTemp = [] - iMatchCount = 0 - if isinstance(self.lAllObjects[iIndex], oEnd): - bCheck = False - lTemp = [] - iMatchCount = 0 - - if bCheck: - if isinstance(self.lAllObjects[iIndex], lTokens[iMatchCount]): - if iMatchCount == 0: - iStart = iIndex - lTemp.append(self.lAllObjects[iIndex]) - iMatchCount +=1 - if iMatchCount == iMatchLength: - lReturn.append(Tokens(iStart, iLine, lTemp)) - lTemp = [] - iMatchCount = 0 - elif iMatchCount > 0: - lTemp = [] - iMatchCount = 0 - - if isinstance(self.lAllObjects[iIndex], parser.carriage_return): - iLine +=1 - - return lReturn + return extract.get_sequence_of_tokens_matching_bounded_by_tokens(lTokens, oStart, oEnd, self.lAllObjects) def get_tokens_matching(self, lTokens): - iLine = 1 - lReturn = [] - for iIndex in range(0, len(self.lAllObjects)): - for oToken in lTokens: - if isinstance(self.lAllObjects[iIndex], oToken): - lReturn.append(Tokens(iIndex, iLine, [self.lAllObjects[iIndex]])) - - if isinstance(self.lAllObjects[iIndex], parser.carriage_return): - iLine +=1 - - return lReturn + return extract.get_tokens_matching(lTokens, self.lAllObjects) def get_tokens_matching_in_range_bounded_by_tokens(self, lTokens, oStart, oEnd): iLine = 1