Current status of parsing and plc-autodoc #80
Replies: 1 comment 1 reply
-
Thanks for reaching out, @RobertoRoos! There are definitely similarities in our projects which is neat. TextX is new to me, but it looks like a pretty powerful library to develop on top of. blark is a fun side project of sorts for me, so it probably can't compete in many ways. I wouldn't be offended (of course!) if you decided to continue on your current path - and would be interested in seeing how it works out for you. I should add your project to the 'related projects' in the README section at some point...
Some random points about the status/goals of blark:
You can selectively parse sections of code - just declaration or just implementation.
Yes, comments are mostly preserved (* if you work within the bounds of the blark transformed dataclasses at least; if you want to use the underlying grammar parser without the machinery that blark adds, then it'll be extra work on your end) The The test suite shows this off a bit - reading in declarations and verifying that it matches up comments appropriately: blark/blark/tests/test_summary.py Lines 201 to 244 in 6fae121 Correspond to this code https://github.com/klauer/blark-twincat-root-example/blob/16191a36164ff215414a1b67f2d6f95eb5bd207b/lcls-twincat-general/v2.8.1/LCLSGeneral/LCLSGeneral/Data%20types/Misc/ST_System.TcDUT#L8-L14 Now that's a bit complicated, code-wise to dig through.A bit more tersely (this is running on blark master keep in mind!): import blark.parse
# Pick the same DUT from the test suite
fn = "blark/tests/twincat_root/lcls-twincat-general/v2.8.1/LCLSGeneral/LCLSGeneral/Data types/Misc/ST_System.TcDUT"
(parsed,) = list(blark.parse.parse(fn))
# Transform the lark tokens and rules into blark dataclasses:
transformed = parsed.transform()
# Pick off the meta information from the first declaration:
meta = transformed.items[0].declaration.declarations[0].meta
print("Comments for the first declaration:", meta.comments)
Now if you were OK working with the summary layer, this gets a bit easier. This is where I'm initially handling all the sphinx domain stuff: import blark.summary
summary = blark.summary.CodeSummary.from_parse_results([parsed])
comments = summary.data_types["ST_System"].declarations["xSwAlmRst"].meta.comments
print("From the summary", comments) The existing sphinx domain code may be broken as-is but I plan to get back to it at some point. My team was less interested in PLC API documentation in Sphinx than I had hoped! (Code is here: https://github.com/klauer/blark/blob/master/blark/sphinxdomain.py ) Hope that clarifies things a bit. |
Beta Was this translation helpful? Give feedback.
-
Hi @klauer ,
We talked in pcdshub/lcls-twincat-general#80 (comment) where I learned about this project. I started my own Sphinx-PLC integration a while back and the similarities are striking.
What is the current status of your ST parsing? I am only interested in the Declarations. Are comments preserved?
My parser (based on TextX) seems to work for all Structured Text declarations now, but it's not exactly robust. I might go over to yours instead. I guess in general I am interesting in putting (parts of) these projects together.
Beta Was this translation helpful? Give feedback.
All reactions