drexlerd / Loki

GNU General Public License v3.0
4 stars 2 forks source link

Formatting PDDL tasks #7

Open jendrikseipp opened 8 months ago

jendrikseipp commented 8 months ago

Another use case for Loki could be to pretty-print input PDDL files. Many of them have quite some strange format. The tricky thing here is to preserve comments. Not sure the parser library can handle that. But maybe there are cases where there are no comments or comments don't need to be preserved.

drexlerd commented 8 months ago

Great suggestion!

Loki currently strips all comments in the preprocessing which makes it difficult to reach back to that information. A solution to this problem is to add an std::optional<std::string> to each AST node indicating a comment might follow. The AST printer could then simply add the comment back. It will also complicate the grammar since comments can occur quite irregular. Hence, I think it is doable but not a priority now.

drexlerd commented 8 months ago

Actually, the grammar does not become much more complicated but one must add a custom comment parser at the end of each grammar rule. There are at least 50 grammar rules though.

jendrikseipp commented 8 months ago

Then I wouldn't suggest going down that route. Instead, if you want, just provide a formatter that drops all comments.

In many of the use cases we're discussing now, ideally there'd be a Python script that does them, instead of users having to write C++ programs.