-
|
I am writing a parser that builds a CST using A demo project can be seen in this gist: https://gist.github.com/lynzrand/713ba99f3a6987b38ceb569758cb8bdf Although the To ensure the CST gets built correctly, I need to replace So, my question is: is there a way to ensure side effects are executed even if it's in Update: #928 referenced that closures should be semantically "pure". That means that if I want to construct a CST sideband, I need to be extra careful to not let |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hmm, so if I'm understanding you correctly, the issue is that your map/fold functions generate outputs, but also produce a side-effect that is observed by your CST state? So, as stated, the mapping/folding functions are intended to only be used for transforming parser outputs. In the short turn you can 'hack' a fix together by using Out of interest, why does node creation have to be impure? Is it not sufficient to simply use |
Beta Was this translation helpful? Give feedback.
Hmm, so if I'm understanding you correctly, the issue is that your map/fold functions generate outputs, but also produce a side-effect that is observed by your CST state?
So, as stated, the mapping/folding functions are intended to only be used for transforming parser outputs. In the short turn you can 'hack' a fix together by using
.try_map(|x| Ok(x)): becausetry_mapcan change the outcome of a parse, and because it depends on the output, it forces previous outputs to be generated.Out of interest, why does node creation have to be impure? Is it not sufficient to simply use
Inspector::on_tokento record the input as it is read?