1.3 Exercise 3: Editing using syntactic code fragments

A central feature of the Mjolner tool is that it enables you to copy and move around large chunks of code quite easily -- without running into syntactic errors such as missing brackets etc. Unfortunately, it is difficult to illustrate the usefulness of this feature in a small example. Therefore this exercise consists of a description of the techniques required to use syntactic editing.

Load the file syntaxedit.bet.

1.3.1 Marking code fragments

First of all, you need to know how to mark a chunk of code. In the Mjolner tool it is impossible to mark something that is not a "whole", for instance you cannot select half a descriptor. The tool will always expand the marking until it fits a syntactic category.

[4kb 448x142 PNG][4kb 444x137 PNG]

In the example above, the selection becomes the entire pattern.

Another example: Mark from the middle of one pattern to the middle of the next.

[4kb 460x176 PNG][4kb 456x172 PNG]

The tool selects both patterns.

Try marking different chunks of code and observe what is being selected. For example, try marking the following:

Experiment with the use of Alt+Up (overview), Alt+Left (abstract recursively), Alt+Right (detail) and Alt+Down (detail recursively).

1.3.2 Code fragments: Cut, copy & paste

The tool supports cut, copy, paste, undo and redo on the usual keys:

Command Keyboard shortcut
cut
copy
paste
undo
redo
Ctrl+X
Ctrl+C
Ctrl+V
Ctrl+Z
Ctrl+Y

Now we want to move the Person pattern down to aPerson: @person:

  1. Mark the Person pattern.
    [9kb 414x444 PNG]

  2. Press Ctrl+X to cut.
    [9kb 414x444 PNG]

  3. Mark Moped: UnregisteredVehicle.
    [9kb 414x444 PNG]

  4. Press Enter to insert code.
    [9kb 414x444 PNG]

  5. Press Ctrl+V to paste.
    [9kb 414x444 PNG]

Now try undoing it all using Ctrl+Z.

Notice that the Person pattern could have been thousands of lines of code, and it would still be very simple to move it around or copy it.

You can apply this to all sorts of other code fragments: imperatives, descriptors, do-parts, enter-parts, exit-parts, variabels, superpattern-prefixes. But it does take a little practice to be able to use it efficiently.


Mjolner Tool Workshop
© 2001-2004 Mjølner Informatics
[Modified: Wednesday September 12th 2001 at 16:34]