Refactoring extract.get_line_preceeding_line to use token map.
1) Had to change remove_excessive_blank_lines_above_line_starting_with_token base rule.
This commit is contained in:
parent
927d055653
commit
5e6dcd544d
|
|
@ -54,29 +54,19 @@ class remove_excessive_blank_lines_above_line_starting_with_token(rule.Rule):
|
|||
oViolation.set_action(dAction)
|
||||
self.add_violation(oViolation)
|
||||
|
||||
def fix(self, oFile):
|
||||
'''
|
||||
Applies fixes for any rule violations.
|
||||
'''
|
||||
if self.fixable:
|
||||
self.analyze(oFile)
|
||||
self._print_debug_message('Fixing rule: ' + self.name + '_' + self.identifier)
|
||||
self._fix_violation(oFile)
|
||||
self.violations = []
|
||||
|
||||
def _fix_violation(self, oFile):
|
||||
for oViolation in self.violations:
|
||||
lTokens = oViolation.get_tokens()
|
||||
dAction = oViolation.get_action()
|
||||
lNewTokens = lTokens[0:dAction['index']]
|
||||
oViolation.set_tokens(lNewTokens)
|
||||
oFile.update(self.violations)
|
||||
def _fix_violation(self, oViolation):
|
||||
lTokens = oViolation.get_tokens()
|
||||
dAction = oViolation.get_action()
|
||||
lNewTokens = lTokens[0:dAction['index']]
|
||||
oViolation.set_tokens(lNewTokens)
|
||||
|
||||
|
||||
def check_if_override_exists(oFile, iLine, lOverrides):
|
||||
oMyToi = oFile.get_line_preceeding_line(iLine)
|
||||
|
||||
oMyToi = oFile.get_line_preceeding_line(iLine - 1)
|
||||
try:
|
||||
lTokens = oMyToi.get_tokens()
|
||||
|
||||
for oOverride in lOverrides:
|
||||
if utils.does_token_type_exist_in_list_of_tokens(oOverride, lTokens):
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -1,25 +1,15 @@
|
|||
|
||||
from vsg import parser
|
||||
|
||||
from vsg.vhdlFile import vhdlFile as utils
|
||||
from vsg.vhdlFile.extract import tokens
|
||||
|
||||
|
||||
def get_line_preceeding_line(iLine, lAllTokens):
|
||||
def get_line_preceeding_line(iLine, lAllTokens, iNumLines, oTokenMap):
|
||||
lCarriageReturns = oTokenMap.get_token_indexes(parser.carriage_return)
|
||||
|
||||
iMyLine = 1
|
||||
iTargetLine = iLine - 1
|
||||
bStoreTokens = False
|
||||
lTemp = []
|
||||
for iToken, oToken in enumerate(lAllTokens):
|
||||
if bStoreTokens:
|
||||
lTemp.append(oToken)
|
||||
if isinstance(oToken, parser.carriage_return):
|
||||
iMyLine += 1
|
||||
if bStoreTokens:
|
||||
lTemp.pop()
|
||||
return utils.Tokens(iStartIndex, iTargetLine, lTemp)
|
||||
if iMyLine == iTargetLine:
|
||||
bStoreTokens = True
|
||||
iStartIndex = iToken + 1
|
||||
iAdjust = -1
|
||||
iStart = lCarriageReturns[iLine - iNumLines + iAdjust] + 1
|
||||
iEnd = lCarriageReturns[iLine + iAdjust]
|
||||
lTemp = lAllTokens[iStart:iEnd]
|
||||
|
||||
return None
|
||||
return tokens.New(iStart, iLine - iNumLines, lTemp)
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ class vhdlFile():
|
|||
def set_token_indent(self):
|
||||
set_token_indent(self.lAllObjects)
|
||||
|
||||
def get_line_preceeding_line(self, iLine):
|
||||
return extract.get_line_preceeding_line(iLine, self.lAllObjects)
|
||||
def get_line_preceeding_line(self, iLine, iNumLines=1):
|
||||
return extract.get_line_preceeding_line(iLine, self.lAllObjects, iNumLines, self.oTokenMap)
|
||||
|
||||
def get_line_succeeding_line(self, iLine, iNumLines=1):
|
||||
return extract.get_line_succeeding_line(iLine, self.lAllObjects, iNumLines, self.oTokenMap)
|
||||
|
|
|
|||
Loading…
Reference in New Issue