question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question on implementing "printers" in plugins

See original GitHub issue

Hello.

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:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bd82commented, Feb 4, 2019

How do you handle comments?

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.

1reaction
bd82commented, Jan 12, 2019

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found