Adding parsing for file_declaration.
This commit is contained in:
parent
772952b694
commit
4bf99d84e1
|
|
@ -0,0 +1,78 @@
|
|||
--------------------------------------------------------------------------------
|
||||
0 | None |
|
||||
--------------------------------------------------------------------------------
|
||||
1 | 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'>
|
||||
--------------------------------------------------------------------------------
|
||||
2 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
3 | None | file F1 : IntegerFile;
|
||||
<class 'vsg.token.file_declaration.file_keyword'>
|
||||
<class 'vsg.token.identifier_list.identifier'>
|
||||
<class 'vsg.token.file_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.file_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
4 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
5 | None | file F2 : IntegerFile is "test.dat";
|
||||
<class 'vsg.token.file_declaration.file_keyword'>
|
||||
<class 'vsg.token.identifier_list.identifier'>
|
||||
<class 'vsg.token.file_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.file_open_information.is_keyword'>
|
||||
<class 'vsg.token.file_open_information.file_logical_name'>
|
||||
<class 'vsg.token.file_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
6 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
7 | None | file F3 : IntegerFile open WRITE_MODEW is "test.dat";
|
||||
<class 'vsg.token.file_declaration.file_keyword'>
|
||||
<class 'vsg.token.identifier_list.identifier'>
|
||||
<class 'vsg.token.file_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.file_open_information.open_keyword'>
|
||||
<class 'vsg.token.file_open_information.file_open_kind_expression'>
|
||||
<class 'vsg.token.file_open_information.is_keyword'>
|
||||
<class 'vsg.token.file_open_information.file_logical_name'>
|
||||
<class 'vsg.token.file_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
8 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
9 | None | file F1, F2, F3 : IntegerFile open WRITE_MODEW is "test.dat";
|
||||
<class 'vsg.token.file_declaration.file_keyword'>
|
||||
<class 'vsg.token.identifier_list.identifier'>
|
||||
<class 'vsg.token.identifier_list.comma'>
|
||||
<class 'vsg.token.identifier_list.identifier'>
|
||||
<class 'vsg.token.identifier_list.comma'>
|
||||
<class 'vsg.token.identifier_list.identifier'>
|
||||
<class 'vsg.token.file_declaration.colon'>
|
||||
<class 'vsg.parser.todo'>
|
||||
<class 'vsg.token.file_open_information.open_keyword'>
|
||||
<class 'vsg.token.file_open_information.file_open_kind_expression'>
|
||||
<class 'vsg.token.file_open_information.is_keyword'>
|
||||
<class 'vsg.token.file_open_information.file_logical_name'>
|
||||
<class 'vsg.token.file_declaration.semicolon'>
|
||||
--------------------------------------------------------------------------------
|
||||
10 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
11 | None | begin
|
||||
<class 'vsg.token.architecture_body.begin_keyword'>
|
||||
--------------------------------------------------------------------------------
|
||||
12 | None |
|
||||
<class 'vsg.parser.blank_line'>
|
||||
--------------------------------------------------------------------------------
|
||||
13 | 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,13 @@
|
|||
architecture RTL of FIFO is
|
||||
|
||||
file F1 : IntegerFile;
|
||||
|
||||
file F2 : IntegerFile is "test.dat";
|
||||
|
||||
file F3 : IntegerFile open WRITE_MODEW is "test.dat";
|
||||
|
||||
file F1, F2, F3 : IntegerFile open WRITE_MODEW is "test.dat";
|
||||
|
||||
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,24 @@
|
|||
|
||||
from vsg import parser
|
||||
|
||||
###############################################################################
|
||||
# File objects
|
||||
###############################################################################
|
||||
|
||||
class file_keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
|
||||
class colon(parser.colon):
|
||||
|
||||
def __init__(self, sString=':'):
|
||||
parser.colon.__init__(self)
|
||||
|
||||
|
||||
class semicolon(parser.semicolon):
|
||||
|
||||
def __init__(self, sString=';'):
|
||||
parser.semicolon.__init__(self)
|
||||
|
||||
|
||||
class keyword(parser.keyword):
|
||||
|
||||
|
|
@ -20,11 +35,6 @@ class comma(parser.comma):
|
|||
def __init__(self):
|
||||
parser.comma.__init__(self)
|
||||
|
||||
class colon(parser.colon):
|
||||
|
||||
def __init__(self):
|
||||
parser.colon.__init__(self)
|
||||
|
||||
class subtype_indication(parser.subtype_indication):
|
||||
|
||||
def __init__(self, sString):
|
||||
|
|
@ -52,5 +62,5 @@ class logical_name(parser.logical_name):
|
|||
|
||||
class semicolon(parser.semicolon):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, sString=';'):
|
||||
parser.semicolon.__init__(self)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
from vsg import parser
|
||||
|
||||
|
||||
class open_keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
|
||||
class file_open_kind_expression(parser.expression):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.expression.__init__(self, sString)
|
||||
|
||||
|
||||
class is_keyword(parser.keyword):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.keyword.__init__(self, sString)
|
||||
|
||||
|
||||
class file_logical_name(parser.expression):
|
||||
|
||||
def __init__(self, sString):
|
||||
parser.expression.__init__(self, sString)
|
||||
|
||||
|
|
@ -9,6 +9,7 @@ from vsg.vhdlFile.classify_new import subtype_declaration
|
|||
from vsg.vhdlFile.classify_new import constant_declaration
|
||||
from vsg.vhdlFile.classify_new import signal_declaration
|
||||
from vsg.vhdlFile.classify_new import variable_declaration
|
||||
from vsg.vhdlFile.classify_new import file_declaration
|
||||
|
||||
from vsg.vhdlFile.classify_new import use_clause
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ from vsg.vhdlFile.classify_new import use_clause
|
|||
| subtype_declaration
|
||||
| constant_declaration
|
||||
| signal_declaration
|
||||
| shared_variable_declaration
|
||||
| *shared*_variable_declaration
|
||||
| file_declaration
|
||||
| alias_declaration
|
||||
| component_declaration
|
||||
|
|
@ -75,6 +76,10 @@ def detect(iToken, lObjects):
|
|||
if iReturn != iToken:
|
||||
return iReturn
|
||||
|
||||
iReturn = file_declaration.detect(iToken, lObjects)
|
||||
if iReturn != iToken:
|
||||
return iReturn
|
||||
|
||||
|
||||
|
||||
iReturn = use_clause.detect(iToken, lObjects)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
from vsg.token import file_declaration as token
|
||||
|
||||
from vsg.vhdlFile import utils
|
||||
|
||||
from vsg.vhdlFile.classify_new import file_open_information
|
||||
from vsg.vhdlFile.classify_new import identifier_list
|
||||
from vsg.vhdlFile.classify_new import subtype_indication
|
||||
|
||||
|
||||
'''
|
||||
file_declaration ::=
|
||||
file identifier_list : subtype_indication [ file_open_information ] ;
|
||||
'''
|
||||
|
||||
|
||||
def detect(iToken, lObjects):
|
||||
|
||||
if utils.is_next_token('file', iToken, lObjects):
|
||||
return classify(iToken, lObjects)
|
||||
|
||||
return iToken
|
||||
|
||||
|
||||
def classify(iToken, lObjects):
|
||||
iCurrent = utils.assign_next_token_required('file', token.file_keyword, iToken, lObjects)
|
||||
iCurrent = identifier_list.classify(iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token_required(':', token.colon, iCurrent, lObjects)
|
||||
sEnd = utils.find_earliest_occurance([';', ':=', 'open', 'is'], iCurrent, lObjects)
|
||||
iCurrent = utils.classify_subelement_until(sEnd, subtype_indication, iCurrent, lObjects)
|
||||
iCurrent = file_open_information.detect(iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token_required(';', token.semicolon, iCurrent, lObjects)
|
||||
return iCurrent
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
from vsg.token import file_open_information as token
|
||||
|
||||
from vsg.vhdlFile import utils
|
||||
|
||||
|
||||
'''
|
||||
file_open_information ::=
|
||||
[ open *file_open_kind*_expression ] is file_logical_name
|
||||
'''
|
||||
|
||||
|
||||
def detect(iToken, lObjects):
|
||||
|
||||
if utils.is_next_token('open', iToken, lObjects):
|
||||
return classify(iToken, lObjects)
|
||||
elif utils.is_next_token('is', iToken, lObjects):
|
||||
return classify(iToken, lObjects)
|
||||
|
||||
return iToken
|
||||
|
||||
|
||||
def classify(iToken, lObjects):
|
||||
iCurrent = iToken
|
||||
if utils.is_next_token('open', iCurrent, lObjects):
|
||||
iCurrent = utils.assign_next_token_required('open', token.open_keyword, iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token(token.file_open_kind_expression, iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token_required('is', token.is_keyword, iCurrent, lObjects)
|
||||
iCurrent = utils.assign_next_token(token.file_logical_name, iCurrent, lObjects)
|
||||
return iCurrent
|
||||
Loading…
Reference in New Issue