From: Eric B. <er...@go...> - 2007-05-24 09:46:05
|
Andreas Leitner wrote: > Hi all: > > I have been generating a lot of code over the years. Printing > indentation was always a messy issue. It involved lots of unreadable '% > T's. I very much liked Eric's approach in gec where you have a tripple > of rouintes (one for increasing indentation, one for decreasing and one > for printing the current level). > > I have generalized this approach now for Erl-G into an output filter. It > is a class that you put in front of your actual text output stream. This > class _is_ an outputstream with the two additional public commands of > `indent' and `detent' (better names welcome!) and transparently prints > indentation for every line to a given target output stream. > > I have attached the class as it might be useful to others. Eric if you > like it please feel free to include it in Gobo. I'm just trying to find a better name. If it *is* an output stream, then it is not a filter. What about KL_INDENTED_TEXT_OUTPUT_STREAM (should it really be in the kernel library, or elsewhere (where?))? Or should the indentation facility be part of KI_TEXT_OUTPUT_STREAM with an option to enable it or not? In fact we probably don't need an option, the fact that `indent' is never called (and hence `indentation' is kept to 0) should be enough. The questions are: is it acceptable to add 2 attributes to class KI_TEXT_OUTPUT_STREAM, and will the test to figure out that there is actually no indentation to be printed be noticeable in terms of performance? Note your implementation is not bullet-proof. It won't work if we call `put_string' with an argument that contains newlines. Is that acceptable? If yes, it should be clearly stated. -- Eric Bezault mailto:er...@go... http://www.gobosoft.com |