Replies: 3 comments 14 replies
-
Morning @jfcliche ,
It looks like you found
The parser was written to follow the LRM and is contained in the
Unfortunately at the moment there is not an API documented for it. Maybe this is an opportunity to create one though.
VSG keeps all tokens in a list which represents the entire file. Unfortunately this does not show any kind of structure of the file. This has been a challenge sometimes when trying to write certain rules, but I have developed a methodology to move through the structure. Depending on what you want to do it should be fairly easy to get the information you want.
That sounds intriguing. Is this something you are working open source? There are methods on vhdlFile.get_tokens_matching([vsg.token.entity_declaration.identifier]) This would return a list of Tokens of Interest (ToI) objects. You can get the value of the identifier by using The For example with this code: 1
2 entity FIFO is
3
4 end entity;
There are methods for extracting ranges of tokens based on a left and right token: vhdlFile.get_tokens_bounded_by(vsg.token.entity_declaration.entity_keyword, vsg.token.entity_declaration.semicolon) and some methods at a higher level of abstraction: vhdlFile.get_subprogram_body()
vhdlFile.get_function_subprogram_body()
vhdlFile.get_procedure_subprogram_body() I'm sure we can extract the information you are looking for. vhdlFile may already have the methods you need, and if it does not then I can add some. Let me know how you would like to proceed. Regards, --Jeremy |
Beta Was this translation helpful? Give feedback.
-
Morning @jfcliche , I found the issue with the failing tests. The attribute 577 replace_token(lOpenParens[-1], lTokens, token.aggregate.open_parenthesis(), iId=lTokens[lOpenParens[-1]]) it should be: 577 replace_token(lOpenParens[-1], lTokens, token.aggregate.open_parenthesis(), iId=lTokens[lOpenParens[-1]].iId) |
Beta Was this translation helpful? Give feedback.
-
Hi. I have submitted PR #1309 that enables VSG to be used as a VHDL parser. |
Beta Was this translation helpful? Give feedback.
-
I am looking for a Python-based VHDL parser that mostly is up to date with VHDL2008. Many existing parsers I have tried fail with the codebase in my project, but VSG seems to be doing fine with it. I just need to extract entities, ports and associated comment blocks and comment lines to automatically generate documentation for my Sphinx VHDL Domain plugin.
Is the VSG parser accessible in python, what level of parsing can it do, and is there API documentation for it?
So far I have been able to tokenize a file with
vhdlFile.vhdlFile(lines).get_all_tokens().get_tokens()
by looking at the source code and some guesswork, but is there some method/class that I could access to get more info on the code structure while still having access to the comments?I suspect that VSG does not need to deeply understand the code to lint it and might not need do do much more processing passed the tokenizing, but my guess is there is a bit more than what I have seen by a quick look around.
Thanks for the great tool!
Beta Was this translation helpful? Give feedback.
All reactions