Search code examples
pharo

Simple formatter and trying to create custom formatting style around code?


I'm trying to create a custom, or modify the existing, method formatter to experiment with different styles of arranging code.

BISimpleFormatter is a subclass of RBProgramNodeVisitor so I plan to use something like that too.

As a generic starting point, how can I insert my own characters(spaces or tabs) before and after each code node?


Solution

  • Create a subclass of BISimpleFormatter. For every #visit<XYZ> method in the BISimpleFormatter implement in your class the same method by doing whatever pre-decoration you want, then call super visit<XYZ> and end with your post-decoration.

    For instance,

    MySpaciousFormatter could do something on the lines of

    visitLiteralNode: aLiteralNode
      codeStream space.
      super visitLiteralNode: aLiteralNode.
      codeStream space
    

    This way every time the formatter is about to print a LiteralNode it will put spaces around it. I'm sure you have much better ideas; I just wanted to give you a simple example.