Adding generic clause objects.
This commit is contained in:
parent
f32d4e1a1b
commit
1c1dc3ccd0
|
|
@ -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
|
||||
###############################################################################
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
generic ( );
|
||||
|
||||
generic (
|
||||
|
||||
);
|
||||
|
||||
generic
|
||||
(
|
||||
)
|
||||
;
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue