Kommander New Parser
Prev
Next

Kommander New Parser

Michal Rudolf

Eric Laffoon

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

The new parser was introduced in Kommander with version 1.2, released with KDE 3.4. This document was originally released to show all the features of new parser. As of Kommander 1.3, released with KDE 3.5.9, the new parser is now the default, except for MainWindow applications created in Qt™ Designer. Because the new parser is so much richer in ability, overcomes the limitations of nesting in the old parser and adds so many new features we strongly recommend using it.

Kommander itself will not be described here. Please refer to other documents to see what is Kommander for, how to create dialogs and how to manipulate widgets on runtime.

Old parser

Here we compare the two parsers. While we advocate the new one for most purposes the old one is still supported and useful, particularly when working with other scripting languages.

Old parser

The old parser was in fact macro parser. Only strings beginning with @ were recognized, locally parsed and expanded.

@LineEdit1.setText(@ListBox.selection)

All the underlying functionality (local variables, expressions, file manipulation) had to be done in another scripting language, such as Bash. While the intent with Kommander is to support all other scripting languages, and this is presently possible to some degree, there was a need for a fast, native scripting language that was assured to be portable. The biggest problem with the old parser is that the Kommander specials are evaluated before the code is passed to the scripting language, making them impossible to use in loops and conditions.

The developers considered bash slow and not friendly to new users, and the old parser had been initially bash calling DCOP. The paradox for Kommander being language neutral resulted in a need to do more than just functions natively.

New parser

The new parser is a full parser. It parses the whole script, not just functions. As we were interested in GUI interaction, not the proliferation of scripting languages, we made compromises. As a result you should find Kommander's scripting to be capable for most basic tasks and natural and easy to use. There is also the Function Browser, which will help you assemble statements. The Function Browser is intended to make Kommander accessible to complete novice programmers. It is similar to what you would find in KSpread to help you choose a function and fill in the parameters.

Tip

If you want enhanced functionality found in other languages you can include them in Kommander script objects headed with a shebang. While in these scripts the Function Browser will help you insert references to widgets. Just remember when using this functionality that the parser makes one pass for the old parser functions and one pass for your script. So if you try to change something in a widget and read it in the middle of a script you may not get what you expect.

#!/usr/bin/php

The following feature list is from version 1.2

  • local and global variables and associative arrays

  • numerical expressions

  • string manipulation

  • various structure commands: if, while, for, foreach

  • most functions from old parser

  • direct widget manipulation

  • many additional functions

  • decent execution speed

  • receive parameters from signals in script slots

This list is from version 1.3

  • pass parameters and receive them with script execute calls

  • return a value from a script

  • create widgets on the fly

  • connect signals and slots on the fly

  • use a variable alias for a widget name

  • simple indexed array functions

  • directly access a widgets slots

Invoking new parser

To enable new parser, set useInternalParser property of the dialog to true. You can also enable new parser in a single script by putting

#!kommander
on the first line of the script. Also note if you are using another scripting language in a script with a shebang that Kommander automatically enables the old parser for interacting with the dialog.
#!/bin/bash
echo @Self.item(0)
# returns first parameter passed to script
# echo $returnvalue passes back to calling script

Prev
Next
Home


Would you like to comment or contribute an update to this page?
Send feedback to the TDE Development Team