简体   繁体   中英

generator from boost::spirit::x3 AST?

Esteemed Colleagues,

I've a boost::spirit::x3 parser (of an AST) that works fine for its purpose of bringing in input files into our application.

I'd like to flip things around and ask it to GENERATE output streams based on the same tree.

This is something I've never done. Should I use boost::karma, or just write a visitor/walker for the tree? What facilities does boost provide that might help me get started with either of these approaches?

I imagine that specifying the recursion depth globally, and at each level might be useful as otherwise the output could be HUGE.

Other issues for someone new to this to consider?

Thanks!

There is nothing like Karma for X3.

There are no facilities outside the underlying Proto library to traverse the expression tree.

However. You will run into predictable issues where the mapping from input-output is not a bijection. You will always have to pick a preferred output representation for such data, which means that your data may not roundtrip, you might have a lossy transform. You need to take these into account.

I would actually not consider this. Instead of tightly coupling my implementation on implementation details of a complicated library¹, I would base my algorithm on the AST or datastructures that you actually control.


¹ like X3, which is also experimental, so things might change without notice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM