[Gambas-user] Scripter - using Class to define a reference to a not class loaded by the main script

Benoît Minisini g4mba5 at gmail.com
Sat Mar 13 19:30:07 CET 2021


Le 13/03/2021 à 18:46, Brian G a écrit :
> Hi Ben,
> 
> In Gambas you may define a reference to a class not loaded by main or 
> project component list with:
> 
>       Class eval
> 
> Which allows the compiler to process references to elements of that class.
> 
>       This of course does not work in scripter as it will interpret this 
> as the definition of a new class beginning.
> 
> Should a note be added to the CLASS page that this is not supported by 
> the scripter?
> And indicate how this is used by a script.
> 
> Or is there a way to identify this as not a script begin class 
> definition through the highlighter.
> 
> Right now this generates a syntax error missing end class in the script 
> when it occurs.
> 
> 
> "Failure is the key to success;
>   each mistake teaches us something"  .. Morihei Ueshiba
> Brian G
> 
> 

This is unfortunate, as "Class xxxx" declaration is the only way to use 
a class not known at compilation time.

(I should have been more cautious with what was done with this scripter 
thing to avoid these kind of problems before being they hit us... You 
see now why I am reluctant to each specific syntax added to it.)

The right thing to do would have been not using "Class" to define a new 
class, but the preprocessor keywords (for example "#Class").

Alas, because of backward-compatibility, I guess that we must support 
the current use of "Class".

The only idea I can give you is analyzing the script file in two passes:

At first pass, you identify the "Class xxx" and "End Class" lines.

At second pass, every "Class xxx" without a corresponding "End Class" is 
supposed to be a class declaration. Two "End Class" without an 
intermediate "Class xxxx" is a syntax error.

Of course, then you cannot detect that the user forgot the last "End 
Class" keyword.

Note that you can't use the indentation to solve the problem, as 
indentation as no syntax meaning in Gambas - it's not Python! :-)

If you have better ideas, tell me.

Regards,

-- 
Benoît Minisini


More information about the User mailing list