To use LSE to create or edit source code requires an understanding of
the concepts of tokens and placeholders. Tokens and placeholders are
language elements that have been predefined for each of the supported
languages. These elements can be expanded into templates for
language constructs.
Placeholders
Placeholders are markers in the source code that indicate locations
where you can provide program text. These placeholders help you to
supply the appropriate syntax in a given context. Generally, you do
not need to type placeholders, rather, they are inserted for you by
LSE. Placeholders can be recognized because they are surrounded by
brackets or braces. The exact choice for placeholder brackets is
language dependent.
There are three types of placeholders:
o Terminal placeholders
o Nonterminal placeholders
o Menu placeholders
Terminal placeholders provide text strings that describe valid
replacements for the placeholder. Nonterminal placeholders expand
into additional language constructs. Menu placeholders provide a
list of options corresponding to the placeholder. The type of a
placeholder is a property of the placeholder name.
Placeholders are either optional or required. Required placeholders,
indicated by braces, represent places in the source code where you
must provide program text. Optional placeholders, indicated by
brackets, represent places in the source code where you can either
provide additional constructs or erase the placeholder.
For example, the declaration
INTEGER {identifier}...
when expanded becomes
INTEGER id,
[identifier]...
The first appearance of the identifier placeholder is surrounded by
braces because you need at least one identifier in this declaration.
The second appearance is surrounded by brackets because additional
identifiers are optional.
Some placeholders are duplicated when expanded. These placeholders
are followed by an ellipsis. Generally, these placeholders represent
items such as identifiers, statements, expressions, datatypes, or any
location where lists of items are expected. A placeholder is
duplicated either vertically or horizontally, depending on the
context and the placeholder definition. For example, the placeholder
[identifier] in the previous example was duplicated vertically.
You may move forward or backward from placeholder to placeholder. In
addition, you can delete or expand placeholders as needed. LSE
allows you to specify uppercase, lowercase, or as defined for all
text expanded into the buffer.
You may modify placeholder definitions by means of the EXTRACT
command. See Chapter 6 for information on modifying placeholders.
Placeholder definitions may be stored in an environment file. See
Chapter 7 for information on defining your own placeholders.
TOKENS
Tokens are typically keywords in programming languages. When
expanded, tokens provide additional language constructs. Tokens are
typed directly into the buffer. Generally, tokens are used in
situations when you want to add additional language constructs where
there are no placeholders. For example, typing IF and pressing the
EXPAND key causes a template for an IF construct to appear on your
screen. Tokens are also used to bypass long menus in situations
where expanding a placeholder, such as {statement}, would result in a
lengthy menu.
You can use tokens to insert text when editing an existing file.
Because most languages have tokens for built-in functions and
keywords, you type the name for a function or keyword and press the
EXPAND key. In addition, most languages provide a token named
'statement' or 'expression' that expands into a menu of all possible
statements or expressions.
The following example demonstrates how to use tokens to edit an
existing program. In this case, the buffer, TEST.EXAMPLE, contains
the following code:
PROCEDURE test ()
IF A = B
THEN
A = C + 1
ENDIF
ENDPROCEDURE test
If you want to add more statements to this program before the IF
construct, do the following:
1. Move the cursor to the beginning of the IF procedure line.
2. Press the OPEN LINE key (PF1-KP0).
3. Press the TAB key.
Note that the cursor is placed at the same level of indentation
as the next line.
4. Type statement and press the EXPAND key.
A menu of statements will now appear on your screen. You use the
arrow keys to scroll through the menu. To select a menu item, you
press the EXPAND, ENTER, or RETURN key. You can press the space bar
to exit a menu without selecting an item.
1 – Terminal Placeholders
If the current position is on a terminal placeholder when the EXPAND key is pressed, the Editor displays a description of valid replacements for the terminal placeholder. Pressing the up and down arrows (bound to the GOTO CHARACTER/VERTICAL command) allows you to move within the text. Pressing the space bar removes the text and returns you to the original buffer without making any changes. Pressing any other key clears the text and performs the operation normally associated with the key.
2 – Nonterminal Placeholders
If the current position is on a nonterminal placeholder when the EXPAND key is pressed, the Editor deletes the placeholder and replaces it with the text of the placeholder body.
3 – Menu Placeholders
When a menu placeholder is expanded, the Editor displays a list of
options. Pressing the up and down arrow keys (bound to the GOTO
CHARACTER/VERTICAL command) allows you to move from one option to
another.
To obtain help text on an indicated option, press the GOLD-HELP (PF2)
sequence.
Pressing the EXPAND, ENTER, or RETURN key allows you to expand the
selected option and remove the menu display.
Pressing the key bound to the GOTO SCREEN command (Keypad 8 key) also
allows you to move through the menu, skipping several options at a
time.
Pressing any other key removes the menu display and performs the
operation normally associated with the key.
If the option is a placeholder name, the placeholder is enclosed in
the same class of delimiter as the menu option being expanded (unless
the /LIST qualifier on DEFINE PLACEHOLDER specifies otherwise) and
the Editor then automatically performs an EXPAND operation. If /LIST
is specified, the list form of the delimiter found on the menu option
is used.
If there is a description associated with the placeholder or token
name appearing as a choice in a menu, the Editor displays the
description along with the name. For example:
IF: tests an expression and establishes an action