Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error replicating example from the docs #10

Open
jagjordi opened this issue Feb 21, 2020 · 10 comments
Open

Error replicating example from the docs #10

jagjordi opened this issue Feb 21, 2020 · 10 comments
Assignees
Labels

Comments

@jagjordi
Copy link

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

@Paebbels Paebbels self-assigned this Feb 23, 2020
@Paebbels Paebbels added the Bug label Feb 23, 2020
@Paebbels
Copy link
Owner

Can you please attache the error message and stacktrace? This would help a lot.

What Python version are you using?

@jagjordi
Copy link
Author

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

@jagjordi
Copy link
Author

jagjordi commented Mar 6, 2020

I have tried in a linux machine and the result is the same, just FYI

@el-coder-sb
Copy link

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 .

@jagjordi
Copy link
Author

I think that the syntax error is because you are not using python 3.8 version

@el-coder-sb
Copy link

I don´t think so as I´m using python 3.8.2 version.

@Brandon-Valley
Copy link

Brandon-Valley commented Nov 11, 2020

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))    

@Paebbels
Copy link
Owner

This tool is still in alpha state. I want to implement the 2 missing main features in my Christmas holidays.

@Brandon-Valley
Copy link

@Paebbels Thank you very much for your support!

@Paebbels
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants