Combined unparser/parser generator

后端 未结 5 901
孤街浪徒
孤街浪徒 2021-02-02 15:08

Is there a parser generator that also implements the inverse direction, i.e. unparsing domain objects (a.k.a. pretty-printing) from the same grammar specification? As far as I k

5条回答
  •  走了就别回头了
    2021-02-02 15:37

    It is not possible in general.

    What makes a print pretty? A print is pretty, if spaces, tabs or newlines are at those positions, which make the print looking nicely.

    But most grammars ignore white spaces, because in most languages white spaces are not significant. There are exceptions like Python but in general the question, whether it is a good idea to use white spaces as syntax, is still controversial. And therefor most grammars do not use white spaces as syntax.

    And if the abstract syntax tree does not contain white spaces, because the parser has thrown them away, no generator can use them to pretty print an AST.

提交回复
热议问题