Refactoring extract method.
1) Moved method from vsg.vhdlFile to vsg.vhdlFile.extract 2) Refactored method to use token map
This commit is contained in:
parent
899f9b9f48
commit
02ef9dcb90
|
|
@ -29,3 +29,4 @@ from .get_sequence_of_tokens_not_matching import get_sequence_of_tokens_not_matc
|
|||
from .get_tokens_between_tokens_inclusive_while_storing_value_from_token import get_tokens_between_tokens_inclusive_while_storing_value_from_token
|
||||
from .get_tokens_from_line import get_tokens_from_line
|
||||
from .get_consecutive_lines_starting_with_token_and_stopping_when_token_starting_line_is_found import get_consecutive_lines_starting_with_token_and_stopping_when_token_starting_line_is_found
|
||||
from .get_tokens_where_line_starts_with_token_until_ending_token_is_found import get_tokens_where_line_starts_with_token_until_ending_token_is_found
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
from vsg.vhdlFile.extract import tokens
|
||||
from vsg.vhdlFile.extract import utils
|
||||
|
||||
|
||||
def get_tokens_where_line_starts_with_token_until_ending_token_is_found(start_token, stop_token, lAllTokens, oTokenMap):
|
||||
|
||||
lReturn = []
|
||||
|
||||
lStartIndexes = utils.filter_indexes_which_start_a_line(start_token, oTokenMap)
|
||||
|
||||
lStopIndexes = []
|
||||
for iStartIndex in lStartIndexes:
|
||||
lStopIndexes.append(oTokenMap.get_index_of_token_after_index(stop_token, iStartIndex))
|
||||
|
||||
for iStart, iStop in zip(lStartIndexes, lStopIndexes):
|
||||
iLine = oTokenMap.get_line_number_of_index(iStart)
|
||||
lTemp = lAllTokens[iStart:iStop + 1]
|
||||
lReturn.append(tokens.New(iStart, iLine, lTemp))
|
||||
|
||||
return lReturn
|
||||
|
|
@ -198,34 +198,7 @@ class vhdlFile():
|
|||
return extract.get_consecutive_lines_starting_with_token_and_stopping_when_token_starting_line_is_found(search_token, stop_token, self.lAllObjects, self.oTokenMap)
|
||||
|
||||
def get_tokens_where_line_starts_with_token_until_ending_token_is_found(self, start_token, stop_token):
|
||||
iLine = 1
|
||||
lTemp = []
|
||||
lReturn = []
|
||||
iStart = 0
|
||||
bStore = False
|
||||
iLineNumber = None
|
||||
for iIndex in range(0, len(self.lAllObjects)):
|
||||
|
||||
if bStore:
|
||||
lTemp.append(self.lAllObjects[iIndex])
|
||||
|
||||
if isinstance(self.lAllObjects[iIndex], stop_token):
|
||||
oTokens = Tokens(iStart, iLineNumber, lTemp)
|
||||
lReturn.append(oTokens)
|
||||
bStore = False
|
||||
lTemp = []
|
||||
|
||||
if isinstance(self.lAllObjects[iIndex], parser.carriage_return):
|
||||
iLine +=1
|
||||
if not bStore:
|
||||
if utils.are_next_consecutive_token_types([parser.whitespace, start_token], iIndex + 1, self.lAllObjects) or \
|
||||
utils.are_next_consecutive_token_types([start_token], iIndex + 1, self.lAllObjects):
|
||||
iStart = iIndex + 1
|
||||
bStore = True
|
||||
iLineNumber = iLine
|
||||
|
||||
return lReturn
|
||||
|
||||
return extract.get_tokens_where_line_starts_with_token_until_ending_token_is_found(start_token, stop_token, self.lAllObjects, self.oTokenMap)
|
||||
|
||||
def get_token_and_n_tokens_before_it(self, oToken, iTokens):
|
||||
return extract.get_token_and_n_tokens_before_it(oToken, iTokens, self.lAllObjects, self.oTokenMap)
|
||||
|
|
|
|||
Loading…
Reference in New Issue