vickenty / lang-c

Lightweight C parser for Rust
Apache License 2.0
202 stars 30 forks source link

Formatting the AST #8

Open katyo opened 5 years ago

katyo commented 5 years ago

I implements so-called transpiler which process C source before sending to real compiler.

I found lang-c much useful for parsing the sources but it seems the formatting the AST back to the source code still not implemented yet.

I think the line-precise formatter may be very useful feature here.

vickenty commented 5 years ago

Indeed, serializing AST back to source code would be a nice addition. What do you mean by "line precise"?

katyo commented 5 years ago

I mean keeping line-to-line mapping between parsed source and formatted output. This important is some use-cases.

sciencemanx commented 5 years ago

I think this is sometimes referred to as a concrete syntax tree (CST) or lossless syntax tree.

vickenty commented 5 years ago

@katyo We do macro expansion before parsing, so serializing AST would not yield the same text line for line. At best, it would be able to re-create source text after preprocessing. Perhaps for your use case something like tree-sitter would be a better fit?

katyo commented 4 years ago

Hmm, tree-sitter looks interesting. I will try to play with it. Thanks.