sommar@enea.UUCP (02/15/87)
A programmable pretty-printer (PPP) is an idea that's been in my head for a while and I have been thinking that I should write one if I ever get the time. Unfortunately I have to spend my daytime writing the software the customer pays my company for. Anyway, I thought it could be a good idea to make survey on the net to get a glimpse of what is available today. Perhaps I don't have to write anything at all. Before you post your reply, let me explain my notion of a PPP. Why I want it and what I want it to do. As you may know there exists about as many formatting styles of programmes as there are programmers. As you also may have discovered, every one else writes code that is totally unreadable, while yourself you write the most beautiful code. Another important fact is that in a programming project, you want the same formatting style being used throughout all modules. Often you even want a company standard. You can bet that the chances are small that the standard conforms with your formatting style. Although I think that every one recognizes these problems I'd like to give some examples of different way to write the same piece of code. (The example is in Pascal where case is insignificant. I also assume that underscore is allowed in identifiers, which deviates from the standard.) (1) If SomeValue > 23 then Begin DoApproriateAction(Parameter1, Parameter2, FunctionCall(SomeValue), StatusParameter); NotifyUser('Some value is too large!'); End; (2) IF some_value > 23 THEN BEGIN translation := function_call(some_value); do_approriate_action(parameter1, parameter2, translation, status_parameter); notify_user('Some value is too large!'); END; (3) if somevalue > 23 then begin doapproriateaction (parameter1, parameter2, functioncall(somevalue) , statusparameter); notifyuser ('Some value is too large!'); end; (4) if SOME_VALUE > 23 then begin DO_APPRORIATE_ACTION( PARAMETER1, PARAMETER2, FUNCTION_CALL( SOME_VALUE ), STATUS_PARAMETER ); NOTIFY_USER( 'Some value is too large!' ); end; As you see we could make a lot of combinations of these versions. Privately I use (1). When I got into my first project at my current job, they were using (2). Writing reserved words with capital letters I could accept and even appreciate. But putting THEN under IF I found unreadable. So the code from that project contains IF statements of both kinds. Since I made corrections while the other guys were on holiday, there are even modules that contain both styles. If we had had an PPP, this would never have occurred. Then we would had our own profile for the PPP. If I wanted to read some of the other guys' code I'd just run it through the PPP, and I would have gotten something that was acceptable for me. And then there would have been a project profile, to be used on delivery. You see what I'm after? I want my PPP to be able to re-format the code to any of the versions in the example above. (Perhaps with exception of disallowing function calls in parameter lists as in (2). That may be out of the scope, since it concerns programming style rather than formatting style.) Another thing I find important that the PPP must be flexible to the language. Ideally, it would be capable to handle any language, but that is not realistic. But, if it is going to be used on Pascal, there must be a possibility to tell it about new syntax constructs, new standard names etc. Pascal compilers often offers you a lot of extensions. It is also usual, that you have a special pascal-type of language to be used with one certain (industry) computer. You can't ask for a PPP for each one of these. Instead you want one you can take with you where ever you go. (As a consultant I change environment from project to project.) Well, if you know anything that is similar to what I have described, write a mail to sommar@enea.UUCP and tell me. I would be glad if you could supply the following information: * Which language(s) it works upon. * Under which OS(s) it runs if it is dependable. * Costing money or not. * Pointer to more information (author/vendor/distributor). To be a bit specific, the languages I am mainly interested of are the Pascal dialects and Ada and I want the PPP to run under VMS. I am however interested in others too, if not for my own use, so for the reference. If this survey gives any interesting result, I will of course give a summary to the net. Erland Sommarskog sommar@enea.UUCP ENEA DATA, Stockholm
shebs@utah-cs.UUCP (02/16/87)
In article <1704@enea.UUCP> sommar@enea.UUCP(Erland Sommarskog) writes: >A programmable pretty-printer (PPP) is an idea that's been in my head for a >while and I have been thinking that I should write one if I ever get the >time. This isn't a reference to a particular program, but Dick Waters' paper "User Format Control in a LISP Prettyprinter" in the Oct 1983 TOPLAS (vol. 5, no. 4) is about how to do it in a Lisp context (although the idea could be applied to other languages). The main idea is to decouple formatting from printing and run each as a sort of coroutine. The interface is a stream of tokens, some of which represent literal objects, others mark required line breaks, while still others mark optional breaks. Then you have a user control that specifies how a given language construct is to be broken into these tokens. The specification syntax is a little ugly, but you probably wouldn't want to use it directly anyway... In any case, the hard part of prettyprinting is counting columns and fitting stuff, and this is handled by a module that doesn't need to know very much besides what to do with tokens. >Erland Sommarskog sommar@enea.UUCP >ENEA DATA, Stockholm stan shebs (shebs@cs.utah.edu)
cjh@petsd.UUCP (02/17/87)
[] In article <4299@utah-cs.UUCP> shebs@utah-cs.UUCP (Stanley Shebs) writes: >In article <1704@enea.UUCP> sommar@enea.UUCP(Erland Sommarskog) writes: > >>A programmable pretty-printer (PPP) is an idea that's been in my head for a >>while and I have been thinking that I should write one if I ever get the >>time. > >This isn't a reference to a particular program, but Dick Waters' paper >"User Format Control in a LISP Prettyprinter" in the Oct 1983 TOPLAS >(vol. 5, no. 4) is about how to do it in a Lisp context (although the >idea could be applied to other languages). The main idea is to decouple >formatting from printing and run each as a sort of coroutine. See also a paper by Derek C. Oppen, "Prettyprinting", in Transactions on Programming Languages and Systems, October 1980. Regards, Chris -- Full-Name: Christopher J. Henrich UUCP: ...!hjuxa!petsd!cjh US Mail: MS 313; Concurrent Computer Corporation; 106 Apple St; Tinton Falls, NJ 07724 Phone: (201) 758-7288 Concurrent Computer Corporation is a Perkin-Elmer company.