diff --git a/vsg/rules/architecture/rule_006.py b/vsg/rules/architecture/rule_006.py index 5d4ee91c..efdc8263 100644 --- a/vsg/rules/architecture/rule_006.py +++ b/vsg/rules/architecture/rule_006.py @@ -11,17 +11,16 @@ class rule_006(rule.rule): ''' def __init__(self): - rule.rule.__init__(self) - self.name = 'architecture' - self.identifier = '006' + rule.rule.__init__(self, 'architecture', '006') self.solution = 'Ensure "is" keyword is on the same line as the "architecture" keyword.' self.phase = 1 def analyze(self, oFile): for iLineNumber, oLine in enumerate(oFile.lines): - if oLine.isArchitectureKeyword and re.match('^\s*architecture\s+\w+\s+of\s+\w+', oLine.line, re.IGNORECASE): - if not re.match('^\s*architecture\s+\w+\s+of\s+\w+\s+is', oLine.line, re.IGNORECASE): - self.add_violation(iLineNumber) + if oLine.isArchitectureKeyword and \ + re.match('^\s*architecture\s+\w+\s+of\s+\w+', oLine.line, re.IGNORECASE) and \ + not re.match('^\s*architecture\s+\w+\s+of\s+\w+\s+is', oLine.line, re.IGNORECASE): + self.add_violation(iLineNumber) def _fix_violations(self, oFile): for iLineNumber in self.violations: diff --git a/vsg/rules/concurrent/__init__.py b/vsg/rules/concurrent/__init__.py index 5ca4186d..9c0950c4 100644 --- a/vsg/rules/concurrent/__init__.py +++ b/vsg/rules/concurrent/__init__.py @@ -1,4 +1,6 @@ +from keyword_alignment_rule import keyword_alignment_rule + from rule_001 import rule_001 from rule_002 import rule_002 from rule_003 import rule_003 diff --git a/vsg/rules/concurrent/keyword_alignment_rule.py b/vsg/rules/concurrent/keyword_alignment_rule.py new file mode 100644 index 00000000..cc081e7b --- /dev/null +++ b/vsg/rules/concurrent/keyword_alignment_rule.py @@ -0,0 +1,58 @@ + +from vsg import rule +from vsg import check +from vsg import fix + + +class keyword_alignment_rule(rule.rule): + ''' + Checks for keyword alignment in consecutive concurrent statements. + + Parameters + ---------- + + name : string + The group the rule belongs to. + + identifier : string + unique identifier. Usually in the form of 00N. + + Attributes + ---------- + + sKeyword : string + The keyword to align. + + sStartGroupTrigger: string + The line attribute which marks the start of a group to align. + + sEndGroupTrigger: string + The line attribute which ends the group to align. + NOTE: This is inversed to allow for grouping of consecutive lines. + ''' + + def __init__(self, name, identifier): + rule.rule.__init__(self, name, identifier) + self.phase = 5 + self.sKeyword = None + self.sStartGroupTrigger = None + self.sEndGroupTrigger = None + + def analyze(self, oFile): + lGroup = [] + fGroupFound = False + iStartGroupIndex = None + for iLineNumber, oLine in enumerate(oFile.lines): + if oLine.__dict__[self.sStartGroupTrigger] and not fGroupFound: + fGroupFound = True + iStartGroupIndex = iLineNumber + if not oLine.__dict__[self.sEndGroupTrigger] and fGroupFound: + fGroupFound = False + check.keyword_alignment(self, iStartGroupIndex, self.sKeyword, lGroup) + lGroup = [] + iStartGroupIndex = None + if fGroupFound: + lGroup.append(oLine) + + def _fix_violations(self, oFile): + fix.keyword_alignment(self, oFile) diff --git a/vsg/rules/concurrent/rule_006.py b/vsg/rules/concurrent/rule_006.py index 00fb70a7..2b5371c6 100644 --- a/vsg/rules/concurrent/rule_006.py +++ b/vsg/rules/concurrent/rule_006.py @@ -1,34 +1,15 @@ -from vsg import rule -from vsg import check -from vsg import fix +from vsg.rules.concurrent import keyword_alignment_rule -class rule_006(rule.rule): +class rule_006(keyword_alignment_rule): ''' Concurrent rule 006 ensures the alignment of the "<=" keyword over multiple lines. ''' def __init__(self): - rule.rule.__init__(self, 'concurrent', '006') + keyword_alignment_rule.__init__(self, 'concurrent', '006') self.solution = 'Inconsistent alignment of "<=" in group of lines.' - self.phase = 5 - - def analyze(self, oFile): - lGroup = [] - fGroupFound = False - iStartGroupIndex = None - for iLineNumber, oLine in enumerate(oFile.lines): - if oLine.isConcurrentBegin and not fGroupFound: - fGroupFound = True - iStartGroupIndex = iLineNumber - if not oLine.insideConcurrent and fGroupFound: - fGroupFound = False - check.keyword_alignment(self, iStartGroupIndex, '<=', lGroup) - lGroup = [] - iStartGroupIndex = None - if fGroupFound: - lGroup.append(oLine) - - def _fix_violations(self, oFile): - fix.keyword_alignment(self, oFile) + self.sKeyword = '<=' + self.sStartGroupTrigger = 'isConcurrentBegin' + self.sEndGroupTrigger = 'insideConcurrent' diff --git a/vsg/rules/concurrent/rule_008.py b/vsg/rules/concurrent/rule_008.py index 0a003a53..023547ab 100644 --- a/vsg/rules/concurrent/rule_008.py +++ b/vsg/rules/concurrent/rule_008.py @@ -1,36 +1,15 @@ -from vsg import rule -from vsg import check -from vsg import fix +from vsg.rules.concurrent import keyword_alignment_rule -class rule_008(rule.rule): +class rule_008(keyword_alignment_rule): ''' Concurrent rule 008 ensures the alignment of comments in sequential conccurent statements. ''' def __init__(self): - rule.rule.__init__(self) - self.name = 'concurrent' - self.identifier = '008' + keyword_alignment_rule.__init__(self, 'concurrent', '008') self.solution = 'Inconsistent alignment of comments in group of lines.' - self.phase = 5 - - def analyze(self, oFile): - lGroup = [] - fGroupFound = False - iStartGroupIndex = None - for iLineNumber, oLine in enumerate(oFile.lines): - if oLine.isConcurrentBegin and not fGroupFound: - fGroupFound = True - iStartGroupIndex = iLineNumber - if not oLine.insideConcurrent and fGroupFound: - fGroupFound = False - check.keyword_alignment(self, iStartGroupIndex, '--', lGroup) - lGroup = [] - iStartGroupIndex = None - if fGroupFound: - lGroup.append(oLine) - - def _fix_violations(self, oFile): - fix.keyword_alignment(self, oFile) + self.sKeyword = '--' + self.sStartGroupTrigger = 'isConcurrentBegin' + self.sEndGroupTrigger = 'insideConcurrent' diff --git a/vsg/rules/keyword_alignment_rule.py b/vsg/rules/keyword_alignment_rule.py index a6d101c2..b54d4714 100644 --- a/vsg/rules/keyword_alignment_rule.py +++ b/vsg/rules/keyword_alignment_rule.py @@ -7,7 +7,31 @@ from vsg import line class keyword_alignment_rule(rule.rule): ''' - Instantiation rule 015 ensures the alignment of the => operator for every generic in the instantiation. + Checks for keyword alignment in consecutive concurrent statements. + + Parameters + ---------- + + name : string + The group the rule belongs to. + + identifier : string + unique identifier. Usually in the form of 00N. + + Attributes + ---------- + + sKeyword : string + The keyword to align. + + sStartGroupTrigger: string + The line attribute which marks the start of a group to align. + + sEndGroupTrigger: string + The line attribute which ends the group to align. + + sLineTrigger : string + Stores lines in a group which match this attribute. ''' def __init__(self, name=None, identifier=None):