Adding parsing of record_type_definition.
This commit is contained in:
parent
f257d5aa5d
commit
f8cd2d571d
|
|
@ -0,0 +1,120 @@
|
|||
--------------------------------------------------------------------------------
|
||||
0 | None |
|
||||
--------------------------------------------------------------------------------
|
||||
1 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
2 | None | architecture RTL of FIFO is
|
||||
<class 'vsg.token.architecture_body.architecture_keyword'>
|
||||
<class 'vsg.token.architecture_body.identifier'>
|
||||
<class 'vsg.token.architecture_body.of_keyword'>
|
||||
<class 'vsg.token.architecture_body.entity_name'>
|
||||
<class 'vsg.token.architecture_body.is_keyword'>
|
||||
--------------------------------------------------------------------------------
|
||||
3 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
4 | None | type Operation is record
|
||||
<class 'vsg.token.full_type_declaration.type_keyword'>
|
||||
<class 'vsg.token.identifier.identifier'>
|
||||
<class 'vsg.token.full_type_declaration.is_keyword'>
|
||||
<class 'vsg.token.record_type_definition.record_keyword'>
|
||||
--------------------------------------------------------------------------------
|
||||
5 | None | Mnemonic : String (1 to 10);
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
6 | None | OpCode : Bit_Vector(3 downto 0);
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
7 | None | Op1, Op2, Res : RegName;
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.identifier_list.comma'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.identifier_list.comma'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
8 | None | end record;
|
||||
<class 'vsg.token.record_type_definition.end_keyword'>
|
||||
<class 'vsg.token.record_type_definition.end_record_keyword'>
|
||||
<class 'vsg.token.full_type_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
9 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
10 | None | type Operation is record
|
||||
<class 'vsg.token.full_type_declaration.type_keyword'>
|
||||
<class 'vsg.token.identifier.identifier'>
|
||||
<class 'vsg.token.full_type_declaration.is_keyword'>
|
||||
<class 'vsg.token.record_type_definition.record_keyword'>
|
||||
--------------------------------------------------------------------------------
|
||||
11 | None | Mnemonic : String (1 to 10);
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
12 | None | OpCode : Bit_Vector(3 downto 0);
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
13 | None | Op1, Op2, Res : RegName;
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.identifier_list.comma'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.identifier_list.comma'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.element_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
14 | None | end record Operation;
|
||||
<class 'vsg.token.record_type_definition.end_keyword'>
|
||||
<class 'vsg.token.record_type_definition.end_record_keyword'>
|
||||
<class 'vsg.token.record_type_definition.record_type_simple_name'>
|
||||
<class 'vsg.token.full_type_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
15 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
16 | None | begin
|
||||
<class 'vsg.token.architecture_body.begin_keyword'>
|
||||
--------------------------------------------------------------------------------
|
||||
17 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
18 | None | end architecture RTL;
|
||||
<class 'vsg.token.architecture_body.end_keyword'>
|
||||
<class 'vsg.token.architecture_body.end_architecture_keyword'>
|
||||
<class 'vsg.token.architecture_body.architecture_simple_name'>
|
||||
<class 'vsg.token.architecture_body.semicolon'>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
architecture RTL of FIFO is
|
||||
|
||||
type Operation is record
|
||||
Mnemonic : String (1 to 10);
|
||||
OpCode : Bit_Vector(3 downto 0);
|
||||
Op1, Op2, Res : RegName;
|
||||
end record;
|
||||
|
||||
type Operation is record
|
||||
Mnemonic : String (1 to 10);
|
||||
OpCode : Bit_Vector(3 downto 0);
|
||||
Op1, Op2, Res : RegName;
|
||||
end record Operation;
|
||||
|
||||
begin
|
||||
|
||||
end architecture RTL;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import os
|
||||
|
||||
import unittest
|
||||
|
||||
from vsg.tests import utils
|
||||
from vsg.vhdlFile import vhdlFile_new
|
||||
|
||||
sLrmUnit = utils.extract_lrm_unit_name(__name__)
|
||||
|
||||
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,9 +1,19 @@
|
|||
|
||||
from vsg import parser
|
||||
|
||||
###############################################################################
|
||||
# Entity objects
|
||||
###############################################################################
|
||||
|
||||
class colon(parser.colon):
|
||||
|
||||
def __init__(self, sString=':'):
|
||||
parser.colon.__init__(self)
|
||||
|
||||
|
||||
class semicolon(parser.semicolon):
|
||||
|
||||
def __init__(self, sString=';'):
|
||||
parser.semicolon.__init__(self)
|
||||
|
||||
# jcl - remove the folling objects when the new parser is done
|
||||
|
||||
class identifier(parser.identifier):
|
||||
|
||||
|
|
@ -15,18 +25,7 @@ class comma(parser.comma):
|
|||
def __init__(self):
|
||||
parser.comma.__init__(self)
|
||||
|
||||
class colon(parser.colon):
|
||||
|
||||
def __init__(self):
|
||||
parser.colon.__init__(self)
|
||||
|
||||
class element_subtype_definition(parser.subtype_definition):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.subtype_definition.__init__(self, sString)
|
||||
|
||||
class semicolon(parser.semicolon):
|
||||
|
||||
def __init__(self):
|
||||
parser.semicolon.__init__(self)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,33 @@
|
|||
|
||||
from vsg import parser
|
||||
|
||||
###############################################################################
|
||||
# Entity objects
|
||||
###############################################################################
|
||||
|
||||
class keyword(parser.keyword):
|
||||
class record_keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
|
||||
class end_keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
class record_keyword(parser.keyword):
|
||||
|
||||
class end_record_keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
|
||||
class record_type_simple_name(parser.simple_name):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.simple_name.__init__(self, sString)
|
||||
|
||||
# jcl - remove the following objects when the new parser is done
|
||||
|
||||
class keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
|
||||
from vsg.vhdlFile.classify_new import array_type_definition
|
||||
#from vsg.vhdlFile.classify_new import record_type_definition
|
||||
from vsg.vhdlFile.classify_new import record_type_definition
|
||||
|
||||
'''
|
||||
composite_type_definition ::=
|
||||
|
|
@ -16,8 +16,8 @@ def detect(iToken, lObjects):
|
|||
if iReturn != iToken:
|
||||
return iReturn
|
||||
|
||||
# iReturn = record_type_definition.detect(iToken, lObjects)
|
||||
# if iReturn != iToken:
|
||||
# return iReturn
|
||||
iReturn = record_type_definition.detect(iToken, lObjects)
|
||||
if iReturn != iToken:
|
||||
return iReturn
|
||||
|
||||
return iToken
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
from vsg.token import element_declaration as token
|
||||
|
||||
from vsg.vhdlFile import utils
|
||||
|
||||
from vsg.vhdlFile.classify_new import identifier_list
|
||||
from vsg.vhdlFile.classify_new import element_subtype_definition
|
||||
|
||||
'''
|
||||
element_declaration ::=
|
||||
identifier_list : element_subtype_definition ;
|
||||
'''
|
||||
|
||||
|
||||
def classify(iToken, lObjects):
|
||||
iCurrent = identifier_list.classify(iToken, lObjects)
|
||||
|
||||
iCurrent = utils.assign_next_token_required(':', token.colon, iCurrent, lObjects)
|
||||
|
||||
iCurrent = utils.classify_subelement_until(';', element_subtype_definition, iCurrent, lObjects)
|
||||
|
||||
iCurrent = utils.assign_next_token_required(';', token.semicolon, iCurrent, lObjects)
|
||||
|
||||
return iCurrent
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
from vsg.vhdlFile.classify_new import subtype_indication
|
||||
|
||||
'''
|
||||
element_subtype_definition ::=
|
||||
subtype_indication
|
||||
'''
|
||||
|
||||
|
||||
def classify(iToken, lObjects):
|
||||
return subtype_indication.classify(iToken, lObjects)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
from vsg.token import record_type_definition as token
|
||||
|
||||
from vsg.vhdlFile import utils
|
||||
|
||||
from vsg.vhdlFile.classify_new import element_declaration
|
||||
|
||||
'''
|
||||
record_type_definition ::=
|
||||
record
|
||||
element_declaration
|
||||
{ element_declaration }
|
||||
end record [ *record_type*_simple_name ]
|
||||
'''
|
||||
|
||||
|
||||
def detect(iToken, lObjects):
|
||||
if utils.is_next_token('record', iToken, lObjects):
|
||||
return classify(iToken, lObjects)
|
||||
|
||||
return iToken
|
||||
|
||||
|
||||
def classify(iToken, lObjects):
|
||||
iCurrent = utils.assign_next_token_required('record', token.record_keyword, iToken, lObjects)
|
||||
|
||||
iCurrent = utils.classify_subelement_until('end', element_declaration, iCurrent, lObjects)
|
||||
|
||||
iCurrent = utils.assign_next_token_required('end', token.end_keyword, iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token_required('record', token.end_record_keyword, iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token_if_not(';', token.record_type_simple_name, iCurrent, lObjects)
|
||||
return iCurrent
|
||||
|
|
@ -99,6 +99,15 @@ def assign_next_token_if(sToken, token, iToken, lObjects):
|
|||
return iToken
|
||||
|
||||
|
||||
def assign_next_token_if_not(sToken, token, iToken, lObjects):
|
||||
iCurrent = find_next_token(iToken, lObjects)
|
||||
if not object_value_is(lObjects, iCurrent, sToken):
|
||||
lObjects[iCurrent] = token(lObjects[iCurrent].get_value())
|
||||
iCurrent += 1
|
||||
return iCurrent
|
||||
return iToken
|
||||
|
||||
|
||||
def assign_next_token_required(sToken, token, iToken, lObjects):
|
||||
iCurrent = find_next_token(iToken, lObjects)
|
||||
if object_value_is(lObjects, iCurrent, sToken):
|
||||
|
|
|
|||
Loading…
Reference in New Issue