diff --git a/vsg/parser.py b/vsg/parser.py index 879122e9..aed7c180 100644 --- a/vsg/parser.py +++ b/vsg/parser.py @@ -125,6 +125,17 @@ class label_colon(colon): colon.__init__(self) +class open_parenthesis(item): + + def __init__(self): + item.__init__(self, '(') + + +class close_parenthesis(item): + + def __init__(self): + item.__init__(self, ')') + ############################################################################### # Architecture objects ############################################################################### diff --git a/vsg/tests/generic_clause/classification_test_input.vhd b/vsg/tests/generic_clause/classification_test_input.vhd new file mode 100644 index 00000000..d11bd058 --- /dev/null +++ b/vsg/tests/generic_clause/classification_test_input.vhd @@ -0,0 +1,11 @@ + +generic ( ); + +generic ( + +); + +generic +( +) +; diff --git a/vsg/tests/vhdlFile/test_vhdlFile_generic_clause.py b/vsg/tests/vhdlFile/test_vhdlFile_generic_clause.py new file mode 100644 index 00000000..811d3c08 --- /dev/null +++ b/vsg/tests/vhdlFile/test_vhdlFile_generic_clause.py @@ -0,0 +1,46 @@ +import os + +import unittest +from vsg import vhdlFile +from vsg.tests import utils +from vsg import parser +from vsg.token import generic_clause + + +lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','generic_clause','classification_test_input.vhd')) +oFile = vhdlFile.vhdlFile(lFile) + +class tokens(unittest.TestCase): + + def test_keyword(self): + lExpected = [] + lExpected.append((2,0)) + lExpected.append((4,0)) + lExpected.append((8,0)) + + utils.validate_token(self, oFile, lExpected, generic_clause.keyword) + + def test_open_parenthesis(self): + lExpected = [] + lExpected.append((2,2)) + lExpected.append((4,2)) + lExpected.append((9,0)) + + utils.validate_token(self, oFile, lExpected, generic_clause.open_parenthesis) + + def test_close_parenthesis(self): + lExpected = [] + lExpected.append((2,4)) + lExpected.append((6,0)) + lExpected.append((10,0)) + + utils.validate_token(self, oFile, lExpected, generic_clause.close_parenthesis) + + def test_semicolon(self): + lExpected = [] + lExpected.append((2,5)) + lExpected.append((6,1)) + lExpected.append((11,0)) + + utils.validate_token(self, oFile, lExpected, generic_clause.semicolon) + diff --git a/vsg/token/generic_clause.py b/vsg/token/generic_clause.py new file mode 100644 index 00000000..ace8f52f --- /dev/null +++ b/vsg/token/generic_clause.py @@ -0,0 +1,26 @@ + +from vsg import parser + +############################################################################### +# Component objects +############################################################################### + +class keyword(parser.keyword): + + def __init__(self, sString): + parser.keyword.__init__(self, sString) + +class open_parenthesis(parser.open_parenthesis): + + def __init__(self): + parser.open_parenthesis.__init__(self) + +class close_parenthesis(parser.close_parenthesis): + + def __init__(self): + parser.open_parenthesis.__init__(self) + +class semicolon(parser.semicolon): + + def __init__(self): + parser.semicolon.__init__(self) diff --git a/vsg/vhdlFile/classify/__init__.py b/vsg/vhdlFile/classify/__init__.py index 57134743..28150d66 100644 --- a/vsg/vhdlFile/classify/__init__.py +++ b/vsg/vhdlFile/classify/__init__.py @@ -16,6 +16,7 @@ from .for_loop import for_loop from .function import function from .generate import generate from .generic import generic +from .generic_clause import generic_clause from .if_statement import if_statement from .instantiation import instantiation from .library import library diff --git a/vsg/vhdlFile/classify/generic_clause.py b/vsg/vhdlFile/classify/generic_clause.py new file mode 100644 index 00000000..d14e98dd --- /dev/null +++ b/vsg/vhdlFile/classify/generic_clause.py @@ -0,0 +1,43 @@ + +from vsg.token import generic_clause as token + + +def generic_clause(dVars, lTokens, lObjects, oLine): + ''' + Classifies generic clauses: + + generic ( generic_list ) ; + ''' + for iToken, sToken in enumerate(lTokens): + if not dVars['bGenericKeywordFound']: + classify_keyword(sToken, iToken, lObjects, dVars) + else: + if not dVars['bGenericOpenParenthesisFound']: + classify_open_parenthesis(sToken, iToken, lObjects, dVars) + else: + classify_semicolon(sToken, iToken, lObjects, dVars) + classify_close_parenthesis(sToken, iToken, lObjects, dVars) + + +def classify_keyword(sToken, iToken, lObjects, dVars): + if sToken.lower() == 'generic': + lObjects[iToken] = token.keyword(sToken) + dVars['bGenericKeywordFound'] = True + + +def classify_open_parenthesis(sToken, iToken, lObjects, dVars): + if sToken == '(': + lObjects[iToken] = token.open_parenthesis() + dVars['bGenericOpenParenthesisFound'] = True + + +def classify_close_parenthesis(sToken, iToken, lObjects, dVars): + if sToken == ')': + lObjects[iToken] = token.close_parenthesis() + + +def classify_semicolon(sToken, iToken, lObjects, dVars): + if sToken == ';': + lObjects[iToken] = token.semicolon() + dVars['bGenericKeywordFound'] = False + dVars['bGenericOpenParenthesisFound'] = False diff --git a/vsg/vhdlFile/vhdlFile.py b/vsg/vhdlFile/vhdlFile.py index 23c8cc19..539f61ad 100644 --- a/vsg/vhdlFile/vhdlFile.py +++ b/vsg/vhdlFile/vhdlFile.py @@ -109,6 +109,9 @@ class vhdlFile(): dVars['bComponentIsKeywordFound'] = False dVars['bComponentEndKeywordFound'] = False + dVars['bGenericKeywordFound'] = False + dVars['bGenericOpenParenthesisFound'] = False + oLinePrevious = line.blank_line() for sLine in self.filecontent: @@ -133,7 +136,8 @@ class vhdlFile(): classify.code_tags(dVars, oLine, oLinePrevious) classify.port(dVars, oLine) - classify.generic(dVars, oLine) + classify.generic(dVars, oLine) #lTokens + classify.generic_clause(dVars, lTokens, lObjects, oLine) classify.concurrent(dVars, oLine) classify.architecture(self, dVars, lTokens, lObjects, oLine)