Refactoring parser.use objects to token.use_clause tokens.
This commit is contained in:
parent
f6e8670f51
commit
fcdbdbaf72
|
|
@ -336,27 +336,6 @@ class library_semicolon(semicolon):
|
|||
def __init__(self):
|
||||
semicolon.__init__(self)
|
||||
|
||||
###############################################################################
|
||||
# Use objects
|
||||
###############################################################################
|
||||
|
||||
|
||||
class use_keyword(keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
keyword.__init__(self, sString)
|
||||
|
||||
class use_selected_name(selected_name):
|
||||
|
||||
def __init__(self, sString):
|
||||
selected_name.__init__(self, sString)
|
||||
|
||||
class use_semicolon(semicolon):
|
||||
|
||||
def __init__(self):
|
||||
semicolon.__init__(self)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Variable objects
|
||||
###############################################################################
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause
|
||||
from vsg.rules import case_item_rule
|
||||
|
||||
|
||||
|
|
@ -8,6 +8,6 @@ class rule_005(case_item_rule):
|
|||
Checks the "use" keyword has proper case.
|
||||
'''
|
||||
def __init__(self):
|
||||
case_item_rule.__init__(self, 'library', '005', parser.use_keyword)
|
||||
self.regionBegin = parser.use_keyword
|
||||
self.regionEnd = parser.use_semicolon
|
||||
case_item_rule.__init__(self, 'library', '005', use_clause.keyword)
|
||||
self.regionBegin = use_clause.keyword
|
||||
self.regionEnd = use_clause.keyword
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause
|
||||
from vsg.rules import space_between_items_rule
|
||||
|
||||
|
||||
class rule_006(space_between_items_rule):
|
||||
'''
|
||||
Checks for a single space between the use keyword and the use logical name
|
||||
Checks for a single space between the use keyword and the use selected_name
|
||||
|
||||
'''
|
||||
def __init__(self):
|
||||
space_between_items_rule.__init__(self, 'library', '006', parser.use_keyword, parser.use_selected_name)
|
||||
self.regionBegin = parser.use_keyword
|
||||
self.regionEnd = parser.use_semicolon
|
||||
space_between_items_rule.__init__(self, 'library', '006', use_clause.keyword, use_clause.selected_name)
|
||||
self.regionBegin = use_clause.keyword
|
||||
self.regionEnd = use_clause.semicolon
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause
|
||||
from vsg.rules import indent_item_rule
|
||||
|
||||
|
||||
class rule_008(indent_item_rule):
|
||||
'''
|
||||
Checks for indent off the use keyword.
|
||||
Checks for indent of the use keyword.
|
||||
'''
|
||||
def __init__(self):
|
||||
indent_item_rule.__init__(self, 'library', '008', parser.use_keyword)
|
||||
indent_item_rule.__init__(self, 'library', '008', use_clause.keyword)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause
|
||||
from vsg.rules import move_item_and_items_to_the_right_to_next_line_rule
|
||||
|
||||
|
||||
|
|
@ -10,6 +10,6 @@ class rule_011(move_item_and_items_to_the_right_to_next_line_rule):
|
|||
'''
|
||||
|
||||
def __init__(self):
|
||||
move_item_and_items_to_the_right_to_next_line_rule.__init__(self, 'library', '011', parser.use_keyword)
|
||||
self.regionBegin = parser.use_keyword
|
||||
self.regionEnd = parser.use_semicolon
|
||||
move_item_and_items_to_the_right_to_next_line_rule.__init__(self, 'library', '011', use_clause.keyword)
|
||||
self.regionBegin = use_clause.keyword
|
||||
self.regionEnd = use_clause.semicolon
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
from vsg import parser
|
||||
|
||||
###############################################################################
|
||||
# Use objects
|
||||
###############################################################################
|
||||
|
||||
|
||||
class keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
class selected_name(parser.selected_name):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.selected_name.__init__(self, sString)
|
||||
|
||||
class comma(parser.comma):
|
||||
|
||||
def __init__(self):
|
||||
parser.comma.__init__(self)
|
||||
|
||||
class semicolon(parser.semicolon):
|
||||
|
||||
def __init__(self):
|
||||
parser.semicolon.__init__(self)
|
||||
|
|
@ -4,6 +4,7 @@ from vsg.vhdlFile.classify import constant_declaration
|
|||
from vsg.vhdlFile.classify import file_declaration
|
||||
from vsg.vhdlFile.classify import signal_declaration
|
||||
from vsg.vhdlFile.classify import shared_variable_declaration
|
||||
from vsg.vhdlFile.classify import use_clause
|
||||
|
||||
def tokenize(oObject, iObject, lObjects, dVars):
|
||||
'''
|
||||
|
|
@ -43,3 +44,5 @@ def tokenize(oObject, iObject, lObjects, dVars):
|
|||
return True
|
||||
if attribute_declaration.tokenize(oObject, iObject, lObjects, dVars):
|
||||
return True
|
||||
if use_clause.tokenize(oObject, iObject, lObjects, dVars):
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause
|
||||
|
||||
|
||||
def context(self, dVars, lTokens, lObjects, oLine):
|
||||
|
|
@ -150,7 +151,7 @@ def classify_context_reference_comma(sToken, iToken, lObjects, dVars):
|
|||
|
||||
|
||||
def classify_context_reference_semicolon(sToken, iToken, lObjects, dVars):
|
||||
if sToken == ';' and not isinstance(lObjects[iToken], parser.library_semicolon) and not isinstance(lObjects[iToken], parser.use_semicolon) and not dVars['bContextEndFound']:
|
||||
if sToken == ';' and not isinstance(lObjects[iToken], parser.library_semicolon) and not isinstance(lObjects[iToken], use_clause.semicolon) and not dVars['bContextEndFound']:
|
||||
lObjects[iToken] = parser.context_reference_semicolon()
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import re
|
||||
|
||||
from vsg import parser
|
||||
import re
|
||||
|
||||
|
||||
def use(dVars, lTokens, lObjects, oLine):
|
||||
|
|
@ -23,33 +22,6 @@ def use(dVars, lTokens, lObjects, oLine):
|
|||
if not oLine.insideEntity and not oLine.insideArchitecture and not oLine.insidePackage and not oLine.insidePackageBody:
|
||||
check_use_keyword(oLine)
|
||||
|
||||
for iToken, sToken in enumerate(lTokens):
|
||||
if dVars['bInsideUse']:
|
||||
|
||||
classify_use_identifier(sToken, iToken, lObjects, dVars)
|
||||
|
||||
classify_semicolon(sToken, iToken, lObjects, dVars)
|
||||
|
||||
else:
|
||||
classify_use_keyword(sToken, iToken, lObjects, dVars)
|
||||
|
||||
|
||||
def classify_semicolon(sToken, iToken, lObjects, dVars):
|
||||
if sToken == ';':
|
||||
lObjects[iToken] = parser.use_semicolon()
|
||||
dVars['bInsideUse'] = False
|
||||
|
||||
|
||||
def classify_use_identifier(sToken, iToken, lObjects, dVars):
|
||||
if not isinstance(lObjects[iToken], parser.whitespace) and not isinstance(lObjects[iToken], parser.comment):
|
||||
lObjects[iToken] = parser.use_selected_name(sToken)
|
||||
|
||||
|
||||
def classify_use_keyword(sToken, iToken, lObjects, dVars):
|
||||
if sToken.lower() == 'use':
|
||||
lObjects[iToken] = parser.use_keyword(sToken)
|
||||
dVars['bInsideUse'] = True
|
||||
|
||||
|
||||
def check_use_keyword(oLine):
|
||||
if re.match('^\s*use', oLine.lineLower):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause
|
||||
|
||||
|
||||
def tokenize(oObject, iObject, lObjects, dVars):
|
||||
|
||||
'''
|
||||
use_clause ::=
|
||||
use selected_name { , selected_name } ;
|
||||
'''
|
||||
|
||||
if not dVars['bUseClauseKeywordFound']:
|
||||
|
||||
if classify_keyword(oObject, iObject, lObjects, dVars):
|
||||
return True
|
||||
|
||||
else:
|
||||
|
||||
if classify_semicolon(oObject, iObject, lObjects, dVars):
|
||||
return True
|
||||
|
||||
if classify_comma(oObject, iObject, lObjects, dVars):
|
||||
return True
|
||||
|
||||
if classify_selected_name(oObject, iObject, lObjects, dVars):
|
||||
return True
|
||||
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def classify_keyword(oObject, iObject, lObjects, dVars):
|
||||
sValue = oObject.get_value()
|
||||
if sValue.lower() == 'use':
|
||||
lObjects[iObject] = use_clause.keyword(sValue)
|
||||
dVars['bUseClauseKeywordFound'] = True
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def classify_selected_name(oObject, iObject, lObjects, dVars):
|
||||
if type(oObject) == parser.item:
|
||||
lObjects[iObject] = use_clause.selected_name(oObject.get_value())
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def classify_comma(oObject, iObject, lObjects, dVars):
|
||||
if oObject.get_value() == ',':
|
||||
lObjects[iObject] = use_clause.comma()
|
||||
clear_flags(dVars)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def classify_semicolon(oObject, iObject, lObjects, dVars):
|
||||
if oObject.get_value() == ';':
|
||||
lObjects[iObject] = use_clause.semicolon()
|
||||
clear_flags(dVars)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def clear_flags(dVars):
|
||||
dVars['bUseClauseKeywordFound'] = False
|
||||
|
|
@ -7,6 +7,9 @@ from vsg.vhdlFile import classify
|
|||
from vsg.vhdlFile.classify import entity
|
||||
from vsg.vhdlFile.classify import entity_declaration
|
||||
from vsg.vhdlFile.classify import architecture_body
|
||||
from vsg.vhdlFile.classify import use_clause
|
||||
|
||||
from vsg.token import use_clause as use_clause_token
|
||||
|
||||
from vsg import parser
|
||||
|
||||
|
|
@ -64,6 +67,7 @@ class vhdlFile():
|
|||
dVars['bInsideLibrary'] = False
|
||||
|
||||
dVars['bInsideUse'] = False
|
||||
dVars['bUseClauseKeywordFound'] = False
|
||||
|
||||
dVars['bArchitectureKeywordFound'] = False
|
||||
dVars['bArchitectureIdentifierFound'] = False
|
||||
|
|
@ -143,6 +147,13 @@ class vhdlFile():
|
|||
classify.blank(oLine) # lTokens
|
||||
classify.whitespace(lTokens, lObjects)
|
||||
classify.comment(dVars, lTokens, lObjects, oLine)
|
||||
|
||||
for iObject, oObject in enumerate(lObjects):
|
||||
use_clause.tokenize(oObject, iObject, lObjects, dVars)
|
||||
entity_declaration.tokenize(oObject, iObject, lObjects, dVars)
|
||||
architecture_body.tokenize(oObject, iObject, lObjects, dVars)
|
||||
|
||||
|
||||
classify.library(dVars, lTokens, lObjects, oLine)
|
||||
classify.use(dVars, lTokens, lObjects, oLine)
|
||||
classify.context(self, dVars, lTokens, lObjects, oLine)
|
||||
|
|
@ -156,10 +167,6 @@ class vhdlFile():
|
|||
|
||||
|
||||
|
||||
for iObject, oObject in enumerate(lObjects):
|
||||
entity_declaration.tokenize(oObject, iObject, lObjects, dVars)
|
||||
architecture_body.tokenize(oObject, iObject, lObjects, dVars)
|
||||
|
||||
|
||||
|
||||
classify.concurrent(dVars, oLine)
|
||||
|
|
@ -338,7 +345,7 @@ class vhdlFile():
|
|||
oLine.indentLevel = 1
|
||||
else:
|
||||
oLine.indentLevel = 0
|
||||
if _does_line_start_with_item_or_whitespace_and_then_item(oLine, parser.use_keyword):
|
||||
if _does_line_start_with_item_or_whitespace_and_then_item(oLine, use_clause_token.keyword):
|
||||
if dIndent['insideContextDeclaration']:
|
||||
oLine.indentLevel = 2
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue