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

Brian G brian at westwoodsvcs.com
Sun Mar 14 00:46:27 CET 2021


To be more clear 
Perhaps use ClassDef ClassName
 or         #Script Class ClassName


inside a script to do the job or the original 
  Class ClassName

The scripter would do the correct translation as it creates the project.

This is in reality not very likely to happen very often in a script at all.


"Failure is the key to success; 
 each mistake teaches us something"  .. Morihei Ueshiba
Brian G

----- On Mar 13, 2021, at 3:26 PM, Brian brian at westwoodsvcs.com wrote:

> my simple suggestion that inside a script the key word class means start of
> class definition
> and DefClass is used inside a script for simple class reference, Scripter
> translates that to that the correct
> Class definition for the compiler and we document the heck out of it in the
> Class keyword, as being different in a script. And Perhaps explain why?
> 
> or perhaps a #Script Class classname  to do the job.
> 
> 
> "Failure is the key to success;
> each mistake teaches us something"  .. Morihei Ueshiba
> Brian G
> 
> ----- On Mar 13, 2021, at 10:30 AM, Benoît Minisini g4mba5 at gmail.com wrote:
> 
>> 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
>> 
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> 
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----


More information about the User mailing list