spirit icon indicating copy to clipboard operation
spirit copied to clipboard

Custom debug handler support for X3

Open saki7 opened this issue 5 years ago • 5 comments

In Spirit.Qi, we had qi::debug(...) function for specifying custom debug handler. https://github.com/boostorg/spirit/blob/889babc3839e12ac0bba448ecd7150956d17c783/include/boost/spirit/home/qi/nonterminal/debug_handler.hpp#L75-L123

However in X3's current implementation, simple_trace is hard-coded:

https://github.com/boostorg/spirit/blob/889babc3839e12ac0bba448ecd7150956d17c783/include/boost/spirit/home/x3/nonterminal/detail/rule.hpp#L60-L91

I'd love to see custom debug handler support in X3.

EDIT: The reason why I need this functionality is because X3's default debug handler prints Unicode strings as an array of integer code points. What I expected to see was e.g. ['H', 'e', 'l', 'l', 'o'], but instead I get [72, 101, 108, 108, 111]. Perhaps this specific issue is more suited to be handled in a separate issue...

saki7 avatar Mar 05 '20 07:03 saki7

I have the same need, it's very hard to debug what's going on with all those numbers

theodelrieu avatar Dec 30 '20 00:12 theodelrieu

Would anyone care to submit a PR?

djowel avatar Dec 30 '20 00:12 djowel

Sure, I wonder if one should be able to fully customize the handler, or if it's sufficient to add a customization point for token_printer_debug (in support/traits/print_token.hpp).

theodelrieu avatar Dec 30 '20 00:12 theodelrieu

I'd personally prefer customization points. Start with something usable but simple, then we can improve the API as needed.

djowel avatar Dec 30 '20 07:12 djowel

I'll tackle this next week, I have to write a patch to make char32_t the char_type of the unicode encoding, which can have an impact on how to solve this unicode debug handler problem.

theodelrieu avatar Dec 30 '20 19:12 theodelrieu