Another refactor in the parsing.
Now only supports use_clause parsing.
This commit is contained in:
parent
0e00d53832
commit
ce3fdc956c
|
|
@ -0,0 +1,26 @@
|
|||
--------------------------------------------------------------------------------
|
||||
0 | None |
|
||||
--------------------------------------------------------------------------------
|
||||
1 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
2 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
3 | None | use ieee.std_logic.1164;
|
||||
<class 'vsg.token.use_clause.keyword'>
|
||||
<class 'vsg.token.use_clause.selected_name'>
|
||||
<class 'vsg.token.use_clause.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
4 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
5 | None | use ieee.std_logic.1164, ieee.std_logic_arith.all;
|
||||
<class 'vsg.token.use_clause.keyword'>
|
||||
<class 'vsg.token.use_clause.selected_name'>
|
||||
<class 'vsg.token.use_clause.comma'>
|
||||
<class 'vsg.token.use_clause.selected_name'>
|
||||
<class 'vsg.token.use_clause.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
6 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
|
||||
use ieee.std_logic.1164;
|
||||
|
||||
use ieee.std_logic.1164, ieee.std_logic_arith.all;
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
import os
|
||||
|
||||
import unittest
|
||||
|
||||
from vsg.vhdlFile import vhdlFile_new
|
||||
from vsg.tests import utils
|
||||
|
||||
sLrmUnit = 'use_clause'
|
||||
|
||||
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..',sLrmUnit,'classification_test_input.vhd'))
|
||||
oFile = vhdlFile_new.vhdlFile(lFile)
|
||||
|
||||
|
||||
class test_token(unittest.TestCase):
|
||||
|
||||
|
||||
def test_classification(self):
|
||||
sTestDir = os.path.join(os.path.dirname(__file__),'..',sLrmUnit)
|
||||
|
||||
lExpected = []
|
||||
utils.read_file(os.path.join(sTestDir, 'classification_results.txt'), lExpected, False)
|
||||
|
||||
lActual = []
|
||||
|
||||
for oObject in utils.extract_objects(oFile, True):
|
||||
lActual.append(str(oObject))
|
||||
|
||||
self.assertEqual(lExpected, lActual)
|
||||
|
||||
# def test_debug(self):
|
||||
# utils.print_objects(oFile,True)
|
||||
|
|
@ -1,26 +1,25 @@
|
|||
|
||||
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):
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from vsg.vhdlFile.classify import block_header
|
|||
from vsg.vhdlFile.classify import block_declarative_part
|
||||
from vsg.vhdlFile.classify import block_statement_part
|
||||
|
||||
def is_it(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
def detect(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
iItemCount = 0
|
||||
iIndex = iObject
|
||||
try:
|
||||
|
|
@ -27,6 +27,31 @@ def is_it(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
|||
return False
|
||||
|
||||
|
||||
def tokenize(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
|
||||
iToken = iObject
|
||||
|
||||
while not utils.object_value_is(lAllObjects iToken, 'block'):
|
||||
if utils.is_item(lAllObjects, iToken):
|
||||
if utils.object_value_is(lAllObjects, iToken, ':'):
|
||||
utils.assign_token(lAllObjects, iToken, token.label_colon)
|
||||
else:
|
||||
utils.assign_token(lAllObjects, iToken, token.label_name)
|
||||
iToken += 1
|
||||
else:
|
||||
utils.assign_token(lAllObjects, iToken, token.keyword)
|
||||
iToken += 1
|
||||
|
||||
while not
|
||||
|
||||
for iToken in range(iObject, len(lAllObjects):
|
||||
kk
|
||||
if utils.is_item(lAllObjects, iToken):
|
||||
if utils.object_value_is(lAllObjects, iToken, ':'):
|
||||
utils.assign_token(lAllObjects, iToken, token.label_colon)
|
||||
elif utils.object_value_is(lAllObjects, iToken, 'block'):
|
||||
utils.assign_token(lAllObjects, iToken, token.label_colon)
|
||||
|
||||
def tokenize_begin_declaration(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
|
||||
if oObject.get_value().lower() == ':':
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ def is_it(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
|||
| generate_statement
|
||||
| *PSL*_PSL_Directive
|
||||
'''
|
||||
if block_statement.is_it(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
if block_statement.detect(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
return True
|
||||
|
||||
if generate_statement.is_it(iObject, oObject, lAllObjects, lNewObjects, dVars):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
from vsg.vhdlFile.classify_new import context_item
|
||||
|
||||
|
||||
def detect(iCurrent, lObjects):
|
||||
'''
|
||||
context_clause ::=
|
||||
{ context_item }
|
||||
'''
|
||||
|
||||
return context_item.detect(iCurrent, lObjects)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
from vsg.vhdlFile.classify_new import use_clause
|
||||
|
||||
|
||||
def detect(iCurrent, lObjects):
|
||||
'''
|
||||
context_item ::=
|
||||
library_clause
|
||||
| use_clause
|
||||
| context_reference
|
||||
'''
|
||||
iReturn = use_clause.detect(iCurrent, lObjects)
|
||||
|
||||
return iReturn
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
from vsg.vhdlFile.classify_new import design_unit
|
||||
|
||||
from vsg.vhdlFile import utils
|
||||
|
||||
|
||||
def tokenize(lObjects):
|
||||
'''
|
||||
design_file ::=
|
||||
design_unit { design_unit }
|
||||
'''
|
||||
for iCurrent in range(0, len(lObjects)):
|
||||
if utils.is_item(lObjects, iCurrent):
|
||||
iCurrent = design_unit.detect(iCurrent, lObjects)
|
||||
else:
|
||||
iCurrent += 1
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
from vsg.vhdlFile.classify_new import context_clause
|
||||
#from vsg.vhdlFile.classify_new import library_unit
|
||||
|
||||
|
||||
def detect(iCurrent, lObjects):
|
||||
'''
|
||||
design_unit ::=
|
||||
context_clause library_unit
|
||||
'''
|
||||
iReturned = context_clause.detect(iCurrent, lObjects)
|
||||
|
||||
# if library_unit.tokenize(oObject, iObject, lObjects, dVars):
|
||||
# return True
|
||||
#
|
||||
# return False
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
from vsg import parser
|
||||
from vsg.token import use_clause as token
|
||||
|
||||
from vsg.vhdlFile import utils
|
||||
|
||||
|
||||
def detect(iCurrent, lObjects):
|
||||
'''
|
||||
use_clause ::=
|
||||
use selected_name { , selected_name } ;
|
||||
'''
|
||||
if utils.object_value_is(lObjects, iCurrent, 'use'):
|
||||
return classify(iCurrent, lObjects)
|
||||
return iCurrent
|
||||
|
||||
|
||||
def classify(iCurrent, lObjects):
|
||||
|
||||
iStart, iEnd = utils.get_range(lObjects, iCurrent, ';')
|
||||
|
||||
for iToken in range(iStart, iEnd):
|
||||
if utils.is_item(lObjects, iToken):
|
||||
if utils.classify_token('use', token.keyword, iToken, lObjects):
|
||||
continue
|
||||
if utils.classify_token(',', token.comma, iToken, lObjects):
|
||||
continue
|
||||
utils.assign_token(lObjects, iToken, token.selected_name)
|
||||
|
||||
utils.classify_token(';', token.semicolon, iEnd, lObjects)
|
||||
return iEnd
|
||||
|
|
@ -70,11 +70,14 @@ def have_is_keyword(iObject, lAllObjects):
|
|||
iIndex += 1
|
||||
return False
|
||||
|
||||
def assign_token(lAllObjects, iToken, token):
|
||||
lAllObjects[iToken] = token(lAllObjects[iToken].get_value())
|
||||
def assign_token(lObjects, iToken, token):
|
||||
try:
|
||||
lObjects[iToken] = token(lObjects[iToken].get_value())
|
||||
except TypeError:
|
||||
lObjects[iToken] = token()
|
||||
|
||||
def object_value_is(lAllObjects, iToken, iString):
|
||||
if lAllObjects[iToken].get_value().lower() == iString.lower():
|
||||
def object_value_is(lAllObjects, iToken, sString):
|
||||
if lAllObjects[iToken].get_value().lower() == sString.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -83,12 +86,28 @@ def is_item(lAllObjects, iToken):
|
|||
return True
|
||||
return False
|
||||
|
||||
def get_bounds(lAllObjects, iStart, sEnd):
|
||||
def get_bounds(lObjects, iStart, sEnd):
|
||||
iIndex = iStart
|
||||
while lAllObjects[iIndex].get_value() != ';':
|
||||
while lObjects[iIndex].get_value() != sEnd:
|
||||
iIndex += 1
|
||||
else:
|
||||
iEnd = iIndex
|
||||
iStart = iStart
|
||||
iCurrent = iStart
|
||||
return iStart, iCurrent, iEnd
|
||||
|
||||
def get_range(lObjects, iStart, sEnd):
|
||||
iIndex = iStart
|
||||
while lObjects[iIndex].get_value() != sEnd:
|
||||
iIndex += 1
|
||||
else:
|
||||
iEnd = iIndex
|
||||
iStart = iStart
|
||||
return iStart, iEnd
|
||||
|
||||
def classify_token(sToken, token, iToken, lObjects):
|
||||
if object_value_is(lObjects, iToken, sToken):
|
||||
assign_token(lObjects, iToken, token)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ from vsg import line
|
|||
from vsg.vhdlFile.classify_new import blank
|
||||
from vsg.vhdlFile.classify_new import whitespace
|
||||
from vsg.vhdlFile.classify_new import comment
|
||||
from vsg.vhdlFile.classify_new import architecture_body
|
||||
from vsg.vhdlFile.classify_new import entity_declaration
|
||||
from vsg.vhdlFile.classify_new import generate_statement
|
||||
from vsg.vhdlFile.classify_new import block_statement
|
||||
from vsg.vhdlFile.classify_new import concurrent_statement
|
||||
from vsg.vhdlFile.classify_new import case_generate_alternative
|
||||
from vsg.vhdlFile.classify_new import design_file
|
||||
#from vsg.vhdlFile.classify_new import architecture_body
|
||||
#from vsg.vhdlFile.classify_new import entity_declaration
|
||||
#from vsg.vhdlFile.classify_new import generate_statement
|
||||
#from vsg.vhdlFile.classify_new import block_statement
|
||||
#from vsg.vhdlFile.classify_new import concurrent_statement
|
||||
#from vsg.vhdlFile.classify_new import case_generate_alternative
|
||||
|
||||
from vsg import parser
|
||||
|
||||
|
|
@ -65,6 +66,17 @@ class vhdlFile():
|
|||
lAllObjects.extend(lObjects)
|
||||
lAllObjects.append(parser.carriage_return())
|
||||
|
||||
iToken = 0
|
||||
|
||||
design_file.tokenize(lAllObjects)
|
||||
|
||||
for iLine, lLine in enumerate(split_on_carriage_return(lAllObjects)):
|
||||
self.lines[iLine + 1].objects = lLine
|
||||
|
||||
|
||||
|
||||
def old_stuff():
|
||||
|
||||
lNewObjects = []
|
||||
for iObject, oObject in enumerate(lAllObjects):
|
||||
if not type(oObject) == parser.item:
|
||||
|
|
|
|||
Loading…
Reference in New Issue