home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
e
/
epmmac2.zip
/
ASSIST.E
< prev
next >
Wrap
Text File
|
1993-01-21
|
4KB
|
74 lines
/*****************************************************************************/
/* Assist interface for E3 Ralph Yozzo */
/* */
/* This macro is intended for use with programming language */
/* which have tokens which must be balanced to compile correctly. */
/* We shall call these tokens "balanceable tokens" or BalTok for */
/* short. */
/* */
/* The functions provided include moving from an opening token */
/* (e.g., (, {, [ ) to a closing token (e.g., ), }, ] ) and vice versa. */
/* */
/* KEYS: */
/* Ctrl-[, Ctrl-] -- move to corresponding BalTok */
/* */
/* CONSTANTS: */
/* gold -BalTok tokens are defined in the const gold and additional */
/* tokens may be added. */
/* */
/* Example: */
/* if ((c=getch())=='c' */
/* &&(d=complicatedisntit(e))){ */
/* lookforbracket(); */
/* } */
/* In the above program segment if one places the cursor on an opening */
/* parenthesis and presses Ctrl-[ the cursor will move to the corresponding */
/* closing parenthesis if one exists. Pressing Ctrl-[ again will reverse */
/* the process. */
/* */
/* Modified by Larry Margolis to use the GREP option of Locate to search */
/* for either the opening or closing token, rather than checking a line at */
/* a time. I also changed the key from Ctrl-A to Ctrl-[ or -], which are */
/* newly allowed as definable keys, and deleted the matching of /* and */. */
/* (The GREP search is much faster than the way Ralph did it, but doesn't */
/* let you match either of 2 strings.) Finally, the user's previous search */
/* arguments are saved and restored, so Ctrl-F (repeatfind) will not be */
/* affected by this routine. */
/*****************************************************************************/
const GOLD = '(){}[]<>' -- Parens, braces, brackets & angle brackets.
def c_leftbracket, c_rightbracket = call passist()
defproc passist
compile if EVERSION >= '5.50'
call psave_pos(savepos)
compile endif
n=1
c=substr(textline(.line),.col,1)
GETSEARCH search_command -- Save user's search command.
k=pos(c,GOLD) -- '(){}[]<>'
if not k then sayerror 'Not a balanceable character.'; return; endif
search = substr(GOLD,(k+1)%2*2-1,2)
if k//2 then direction='+F'; else direction='-R'; endif
if search='[]' then search='\[\]'; endif
'L /['search']/eg'direction
loop
repeatfind
if rc then leave; endif
if substr(textline(.line), .col, 1) = c then n=n+1; else n=n-1; endif
if n=0 then leave; endif
endloop
if rc=sayerror('String not found') then
sayerror 'Unbalanced token.'
else
sayerror 1
endif
SETSEARCH search_command -- Restores user's command so Ctrl-F works.
compile if EVERSION >= '5.50'
newline = .line; newcol = .col
call prestore_pos(savepos)
.col = newcol
.lineg = newline
right; left -- scroll_to_cursor
compile endif