[Prev][Next][Index]

Re: Whitespace in source code



"Peter Booth." <p.booth@ic.ac.uk> wrote:
> I hope to use Sage++ to make cosmetic reformats to Fortran
> source code. I can see see how the class structure gives me
> the parse tree information I need to distinguish names which
> represent PARAMETERS and, say local variables. I don't know
> whether I can use the unparser when I access and modify the
> whitespace surrounding symbols and operators, the casing of
> identifiers, or if I am restricted to building a list of 
> textual substitutions from the parsed file, and then applying 
> them to the source code myself. Any suggestions? 

Peter, when a FORTRAN source file is parsed by f2dep, the parser will
strip off the idents and spaces. The "dep" file contains information
about the block structure of the original source code. When unparse
it, you can add the spaces or idents back according to the block
structure, or whatever you want.

There are two ways to convert "dep" files back to sources. The first
one is to use Sage++ classes to access the structures in "dep" file.
I will recommand this approach if the source code conversion is more
than changing spaces and idents. You can find a good example on how
to use Sage++ in ~sage/Sage++/demos/dump_info. If the only thing you
need is to change spaces and idents, the other way is to modify
~sage/lib/include/unparse.def, and recompile unparse to do the work.
Hope this help.

BTW, you might want to use "sage-user" next time instead of "sage-bugs"
for a wider distribution of your questions.

Chih-Yi Chen
cychen@cs.indiana.edu


Reference(s):