pyVHDLParser
pyVHDLParser copied to clipboard
Error replicating example from the docs
I am trying to run the example from the docs https://pyvhdlparser.readthedocs.io/en/latest/BlockStream/Usage.html And I get an NoneType is not iterable error.
here is my code
from pyVHDLParser.Token.Parser import Tokenizer
from pyVHDLParser.Blocks import TokenToBlockParser
from pyVHDLParser.Base import ParserException
# Open a source file
with open('strobe_analyzer.vhd', 'r') as fileHandle:
content = fileHandle.read()
# get a token generator
tokenStream = Tokenizer.GetVHDLTokenizer(content)
# get a block generator
blockStream = TokenToBlockParser.Transform(tokenStream)
try:
for block in blockStream:
print("{block!s}".format(block=block))
for token in block:
print(" {token!s}".format(token=token))
except ParserException as ex:
print("ERROR: {0!s}".format(ex))
except NotImplementedError as ex:
print("NotImplementedError: {0!s}".format(ex))
and you can see the vhdl file I am using to test this attetched (just change the extension to vhd, stupid github issue woudltn let me upload .vhd files.....) strobe_analyzer.txt
Can you please attache the error message and stacktrace? This would help a lot.
What Python version are you using?
error trace
C:\Users\Jordi\AppData\Local\Programs\Python\Python38\python.exe C:/Users/Jordi/PycharmProjects/untitled1/parser_test.py
Traceback (most recent call last):
File "C:/Users/Jordi/PycharmProjects/untitled1/parser_test.py", line 18, in <module>
for block in blockStream:
<StartOfDocumentToken>
File "C:\Users\Jordi\AppData\Local\Programs\Python\Python38\lib\site-packages\pyVHDLParser\Blocks\__init__.py", line 193, in GetGenerator
self.NextState(self)
File "C:\Users\Jordi\AppData\Local\Programs\Python\Python38\lib\site-packages\pyVHDLParser\Blocks\__init__.py", line 426, in stateDocument
for keyword in cls.KEYWORDS:
TypeError: 'NoneType' object is not iterable
the python version is 3.8.1
I have also checked if it works with the code you have in the documentatino and it produces the same error
I have tried in a linux machine and the result is the same, just FYI
I´ve got the same error.
When inserting the following code block to the code of https://pyvhdlparser.readthedocs.io/en/latest/BlockStream/Usage.html (before the try-block) it runs.
from pyVHDLParser.Blocks import MetaBlock
for block in MetaBlock.BLOCKS:
try:
block.__cls_init__()
except AttributeError:
pass
It is copied from unit/__init__.py where the comment says:
XXX: move to pyVHDLParser.Blocks; call it from frontend
So I think this has to be done to run the code without the above mentioned code block, i.e. to solve this issue in a clean way.
By the way. It runs but throws an other error after some blocks:
ERROR: Expected ';', ':=' or whitespace after subtype indication.
Which belongs to #9 .
I think that the syntax error is because you are not using python 3.8 version
I don´t think so as I´m using python 3.8.2 version.
I had the same issue, just for anyone else, this is what worked for me:
vhdl_file_path = "RELATIVE_PATH_TO_YOUR_VHDL_FILE"
# Open a source file
with open(vhdl_file_path, 'r') as fileHandle:
content = fileHandle.read()
from pyVHDLParser.Token.Parser import Tokenizer
from pyVHDLParser.Blocks import TokenToBlockParser
from pyVHDLParser.Base import ParserException
# get a token generator
tokenStream = Tokenizer.GetVHDLTokenizer(content)
# get a block generator
blockStream = TokenToBlockParser.Transform(tokenStream)
from pyVHDLParser.Blocks import MetaBlock
for block in MetaBlock.BLOCKS:
try:
block.__cls_init__()
except AttributeError:
pass
try:
for block in blockStream:
print("{block!s}".format(block=block))
for token in block:
print(" {token!s}".format(token=token))
except ParserException as ex:
print("ERROR: {0!s}".format(ex))
except NotImplementedError as ex:
print("NotImplementedError: {0!s}".format(ex))
This tool is still in alpha state. I want to implement the 2 missing main features in my Christmas holidays.
@Paebbels Thank you very much for your support!
The project contains now >250 test cases and reaches circa 48% branch coverage. More tests are coming ... Besides simple tests (individual syntax tests), more complicated real world tests will be added soon.
When this works, I can add issue testcases, this means an minimal failing example can added to the test suite for regression testing.