Question on implementing "printers" in plugins
See original GitHub issueHello.
I am working on prettier-java And do not fully understand the way printers are implemented.
The official docs say:
Printing is a recursive process of converting an AST node (represented by a path to that node) into a doc. The doc is constructed using the builder commands:
And I can inspect an example in the python plugin printer:
case "Lambda": {
return group(
concat([
"lambda",
" ",
path.call(print, "args"),
": ",
path.call(print, "body")
])
);
}
What I do not understand is why the “path” argument is needed. Assuming:
- I have a data structure representing the source code (in my case it is a CST - Concrete Syntax Tree) not an AST.
- I already have utilities to recursively traverse this data structure.
Could I simply traverse my CST and invoke the “builder” commands as needed? Without using the path for traversal?
In what cases would this path be required?
Cheers. Shahar.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Samsung Print Service Plugin FAQs and Troubleshooting Guide
Review frequently asked questions and troubleshooting information for the Samsung Print Service Plugin app.
Read more >Basic Computer Skills: How to Set Up a New Printer
Trying to get your new printer up and running? Here are the basic steps you'll follow to set up almost any printer. Plug...
Read more >How to Fix HP Print Service Plugin App Not Working Problem ...
Notopen #NotWorkingHow to Fix HP Print Service Plugin App Not Working Problem Android & Ios | HP Print Service Plugin Not Open Problem...
Read more >Cura-Dremel-Printer-Plugin - GitHub
Question: Does this plugin support USB-connected printing/Octoprint/Cloud Printing? Do I need an SD card/USB thumb drive? Answer: The plugin only supports ...
Read more >Manage local and network printers - Google Support
Manage local and network printers ... For managed ChromeOS devices. ... As an administrator, you can use Common UNIX Printing System (CUPS) printers...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Toml
In Toml Comments are only allowed in specific points in the grammar. So they are explicitly parsed in the grammar instead of being collected or skipped by the Lexer.
So handling of comments is just like handling any other grammar constructs.
Prettier-Java
In prettier-java (which uses the same parsing library and data structures) it would be more complicated as comments are allowed everywhere in Java. So an additional step would be needed to attach the comments to the CST produced by the parser. and a more generic comment printing concept would be needed as comments could appear as part of any CST node.
Some of those capabilities sound useful and relevant, so I may need to find workarounds for those. Some of that functionality (comments/prettier-ignore) sounds like logical manipulation and analysis of string literals. So in theory it sounds like it does not have to be necessarily coupled to the FastPath and/or could be (re-)implemented as pure utilities.
Keep in mind, I don’t actually know what is going on under the hood and have still not implemented even a single prettier “printer” 😄 So I am likely not understanding the scenario / context completely.
I guess I will learn by doing and be wiser once I have actually written some prettier “printer” code I will be “wiser”.
You can either close this issue, or keep it open if you want me to post links and examples to my work here for farther discussion in the future.
Cheers.