ExpressionTreeToString
ExpressionTreeToString copied to clipboard
Create custom reducible expression types, instead of passing block metadata
The current signature of WriteBlock looks like this:
protected abstract void WriteBlock(BlockExpression expr, object? metadata);
where metadata is language-specific information about how the block needs to be formatted.
Instead, we could create our own custom expression types which would contain this information.
When at a containing expression, we could generate an instance of the custom expression type and pass that into WriteNode. It would forward the expression to WriteExtension, which would be overridden in the formatter to handle these custom types.
We can do the same for parameter declaration vs parameter usage.
We currently have two use cases for this:
- Parameter declarations need to be handled differently from parameter usage, The code to handle the custom type could be in the BuiltinRenderer.
- Different block types could have a new expression type with NodeType == Extension; CodeWriterVisitor could forward the inner block to an appropriate abstract method.