So I’m looking at this currently, and found myself wanting a pretty printed output of the data structure. I’m coming from Elixir, so I think about the way that the data structure is usually output in a way that’s readable without having to copy the “got” result and manually indent everything myself.
I tried looking at the spec documentation to see if there’s some configuration I can set to make this pretty printed format possible, and I haven’t been able to ascertain whether it is possible.
https://crystal-lang.org/api/0.35.1/Spec.html#add_formatter(formatter)-class-method
I also did a quick forum search before posting this, and I’m still at a loss.
If there’s something very obvious that I’m missing, I’d greatly appreciate it being pointed out.
Expected: “BOOM”
got: {{“#sapphire.off” => State::ExecutableNormal(@id=State::AbsoluteStateID(@id=“#sapphire.off”), @initial_state=nil, @on_entry=nil, @on_exit=nil, @transitions=[ExecutableTransition(@event=EventType(@type=“OFF_TO_ON”), @from=State::AbsoluteStateID(@id=“#sapphire.off”), @to=State::AbsoluteStateID(@id=“#sapphire.on”), @actions=nil, @guards=nil)], @child_states=nil, @invoke=nil), “#sapphire.State::RelativeStateID(@id="on")” => State::ExecutableParallel(@id=State::AbsoluteStateID(@id=“#sapphire.State::RelativeStateID(@id="on")”), @on_entry=nil, @on_exit=nil, @transitions=[ExecutableTransition(@event=EventType(@type=“ON_TO_OFF”), @from=State::AbsoluteStateID(@id=“#sapphire.on”), @to=State::AbsoluteStateID(@id=“#sapphire.on”), @actions=nil, @guards=nil)], @parallel_states=[State::AbsoluteStateID(@id=“#sapphire.charging_status”), State::AbsoluteStateID(@id=“#sapphire.playing_status”)], @invoke=nil)}, [State::AbsoluteStateID(@id=“#sapphire.on”), State::AbsoluteStateID(@id=“#sapphire.on”)]}
Coming back to this a few hours later, as I haven’t received a response as fast as I did the first time I posted something on this forum.
If I can create a parser which could pretty print format this, and it be considered an open source contribution to Crystal, please let me know.
I have a book I can reference, never written one before, but if I can contribute to the language in this way then that would be cool.