[Gambas-devel] about PrettyPrinter

Benoit Minisini gambas at ...1...
Fri Aug 13 22:29:22 CEST 2004


On Friday 13 August 2004 23:53, Charlie wrote:
> Benoit Minisini schrieb:
> >On Sunday 08 August 2004 11:49, Benoit Minisini wrote:
> >>I think... I think :-)
> >
> >I continue...
> >
> >>Wouldn't it be a better idea to pretty print the code directly with the
> >>compiler, or to create a pretty-printer program that uses the same
> >> sources than the compiler ? This need passing many options to the
> >> command line, but I think syntax analyzing code must be centralized as
> >> much as possible.
> >
> >I think you could have wrote your pretty printer in Gambas, as the
> >GambasEditor class has a method, Analyze() that splits a line into
> > symbols, spaces, comments, operators... and tells you what is what. I
> > made it to implement automatic completion, display method signatures and
> > find symbol definitions in code.
>
> The first PrettyPrinte was written in gambas-0.56 and posted to the list
> (25.05.2003) .
> Then I wrote it in C to re-get in touche with C in Linux and for reason
> speed .
> The Indenter4 is mostly part of it. Now keeped to  choose the Parameters.
>
> >I think it would be a good idea. Is it a problem for you to rewrite your C
> >pretty printer in Gambas, if I tell you how to use the Analyze() method ?
>
> No it (I think) will not be a problem, to rewrite it, let us know about
> Analyze().
> I will have a look at it, but hints about will be welcome.
>
> Amicalement
> Charlie
>

The GambasEditor offers the following static methods and properties:


STATIC SUB Analyze(sLine AS String)

This function split a Gambas line code into its syntactic components.


STATIC PROPERTY READ Symbols AS String[]

Returns an array of symbols included in the analyzed line. For example,
the following line:

IF Message.Warning(("The file has been modified."), ("Reload"), ("Cancel")) <> 
1 THEN RETURN

will be splitted in the following array:

[ "IF",  "Message", ".", "Warning", "(", "(", "The file has been modified.", 
")", ",", "(", "Reload", ")", "(", "Cancel", ")", ")", "<>", "1", "THEN", 
"RETURN" ]


STATIC PROPERTY READ Types AS String[]

Returns an array of integer giving the "type" (actually the color) of the 
corresponding symbol in the array returned by the Symbols property.

Use the GambasEditor.Color.* constants.


If you have more questions, tell them :-)

And soory for asking you to rewrite your pretty printer back in Gambas, but at 
the 0.56 version, the previous functions didn't exist.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list