Page 1 of 1

Aliases for Keywords (actually phrases)

Posted: 13 April 2006, 10:14 AM
by DH*
How about something like myfile.aka which the compiler would use to substitute abominable phrases like...
  • GetQueue(CByteArray(iq(1, p).DataAddress), data,1)
for shortcuts like...
  • GetQueue(iq1,data,1)
The .aka file could be similar to a Windows .ini file.
  • [aliases]
    iq1=CByteArray(iq(1, p).DataAddress
The user could create/edit it with any text editor.

Posted: 13 April 2006, 10:46 AM
by mikep
You can define aliases using the #define facility as documented in the programming reference - http://www.zbasic.net/doc/ZBasicRef/ZBasicRef64.html.

This works in a similar way to C and also allows for conditional compilation, including of one file in another and undefining of aliases. I think this meets your requirement.

Posted: 13 April 2006, 11:13 AM
by DH*
The way I read the citation, conditional identifiers are used only for conditional compilation. That's not at all what I'm suggesting.

Posted: 13 April 2006, 11:36 AM
by dkinzer
Mike's suggestion doesn't quite fit the bill because the ZBasic compiler does not implement a full C-like preprocessor that performs text substitution.

However, you can use the IDE's abbreviation capability to accomplish your objective. To create an abbreviation, select the 'Open Abbreviations File' entry on the Options menu. Unless you have previously created abbreviations, this file will be empty. To begin, paste the following text in the abbrev.properties file:

Code: Select all

# Global abbreviations file
# Place this file in your home directory, that is, the same directory 
# as the user options file.
# The file ontains a list of entries of the form abbreviation=expansion
# Type the abbreviation and press Ctrl+B to insert the expansion.
# Alternately, choose 'Insert Abbreviation' from the Edit menu and
# choose the abbreviation from the drop down list.
#
# Use '\n' (without the apostrophes) to represent a newline.
# Use '\t' to represent a tab character.
# Use '|' to specify the position the caret after expansion.

#main=Sub Main()\n|\nEnd Sub\n
#for=For | =  to\n\nNext\n
This text contains two example abbreviations that are commented out. For your particular request, you can add this line:

Code: Select all

iq1=CByteArray(iq(1, p).DataAddress|
All properties files are read when the IDE first starts up so after you modify the abbreviations file you will need to exit and restart the IDE.

Posted: 13 April 2006, 12:14 PM
by DH*
All Right! :D

I spoke too soon. It doesn't seem to work. I get a "reference to undefined identifier" error when I compile.

Does this require the recently disabled autocomplete?

Is the substitution made as the abbreviation is typed? (The caret positioning implies this.) If so, it doesn't really meet my needs as I'd prefer to use UltraEdit and just use the IDE for compiling.
EDIT:
I enabled Autocomplete but it still appears to be broken. It does not make the substitution either when I type in the key or at compile time.
EDIT AGAIN:
OK. The cursor must be just past the abbreviation when CTRL+B is typed.

That's OK but not of much use to me. I do not like the IDE and only want to use it when I compile.

Posted: 13 April 2006, 13:16 PM
by dkinzer
To clarify, the abbreviation expansion is performed during editing. To use the abbreviation 'main', you type the word main and then press ctrl-B. The word immediately preceding the caret will be looked up in the abbreviations table. If found, the abbreviation will be replaced by the expansion specified in the abbreviations file.

If you prefer to use UltraEdit, you should be able to configure it to also perform the compilation. I suspect that it has a "next error" capability to allow you to jump to the next error message following a compile/build. If UltraEdit can't be configured to read the error message information that the ZBasic compiler outputs, you may be able to alter the way that the compiler outputs error messages to be compatible with it. See the --error-format compiler option for more information.

Posted: 13 April 2006, 13:41 PM
by DH*
I use UltraEdit to edit files for BasicX, BASCOM AVR, PicBasicPro, PowerBasic, occasionally for VB and REALbasic, and now ZBasic. I use the native compilers for each and really don't want to delve into configuring UE to call the particular compilers. (I think it would get confused as all use the .bas extension.)

By and large this works fine but it would work better if the ZBasic compiler would check for any changes to the files before compiling. UltraEdit prompts when a loaded file changes and asks if I want to reload it.

It would be absolutely superb if the ZBasic compiler would make substitutions like these by scanning the files at compile time but only in the compiled version, leaving the abbreviations in the source file. Perhaps these type abbreviations could be bracketed by an assigned character (e.g. @) to signal the need for substitution.

I can certainly understand why you might not want to consider either request.

Posted: 14 April 2006, 5:32 AM
by DH*
To clarify things...

Abbreviations are a truly neat feature but since they require a simultaneous press of the CTRL and B keys will not work for me since I cannot easily do that with one hand.

I can create a project file in UltraEdit which loads all of the files associated with an application. I can also create macros by recording keystrokes and can assign a macro to a single key (e.g. F12). I can then insert CByteArray(iq(1, p).DataAddress) anywhere I desire with a single keypress. It's not quite what I'd like but does save typing such a lengthy phrase.

Now, if the ZBasic compiler would just check for changes to project files and prompt me when I compile, I can keep the project loaded in the IDE on the machine I use for compiling and can edit the project in UE on any machine on my LAN.

Posted: 14 April 2006, 7:12 AM
by mikep
dhouston wrote:Abbreviations are a truly neat feature but since they require a simultaneous press of the CTRL and B keys will not work for me since I cannot easily do that with one hand.
As I indicated to you before they are programs that can help with your disability e.g. http://www.ehow.com/how_10299_sticky-keys-windows.html

Posted: 14 April 2006, 8:07 AM
by DH*
Having written software and designed hardware to help people with severe handicaps (ALS, CP, quadriplegia, etc) I am well aware of such software and even of helpful hardware gizmos (e.g. footpedals and other switches that connect between KB & PC to press CTRL etc.) and, if they were of use in my situation, I would use them.

Posted: 14 April 2006, 8:52 AM
by dkinzer
Now, if the ZBasic compiler would just check for changes to project files and prompt me when I compile...
When the compiler is invoked, it will read the files as they exist (on the network storage, etc.) irrespective of what is being displayed in the IDE. This, of course, causes a problem if errors are encountered because the IDE will be displaying text that might be different from what was compiled.

In recognition of this, my current development version of the IDE reloads changed files following invocation of the compiler. I believe that this solves the problem that you describe.

Posted: 14 April 2006, 9:09 AM
by DH*
dkinzer wrote:In recognition of this, my current development version of the IDE reloads changed files following invocation of the compiler. I believe that this solves the problem that you describe.
Yes, I think that does what I want. Thanks