
from vsg import rule
from vsg import fix

import re


class rule_005(rule.rule):
    '''
    Constant rule 005 checks there is a single space after the colon.
    '''

    def __init__(self):
        rule.rule.__init__(self)
        self.name = 'constant'
        self.identifier = '005'
        self.solution = 'Ensure only a single space after the colon.'
        self.phase = 2

    def _analyze(self, oFile, oLine, iLineNumber):
        if oLine.isConstant:
            if not re.match('^\s*constant\s+\w+\s*:\s\w', oLine.lineLower):
                self.add_violation(iLineNumber)

    def _fix_violations(self, oFile):
        for iLineNumber in self.violations:
            fix.enforce_one_space_after_word(self, oFile.lines[iLineNumber], ':')
