home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
sprint
/
uppascal.zip
/
UPPASC.SPM
Wrap
Text File
|
1989-07-02
|
5KB
|
135 lines
;;----------------------------------------------------------------------------
;;
;; Turbo Pascal Version 5.0 Key Word Upper Caser
;; ---------------------------------------------
;;
;; The macro 'pascal' when invoked within a buffer will make all occurances
;; of Pascal keywords ( reserved words and few others ) uppercase.
;;
;; If Pascal ( Turbo or otherwise ) is not your language then I hope that the
;; code below is straightforward enough for easy adaptation to the syntax
;; of your favourite language.
;;
;; Designed & Implemented by Ken Westerback 73547,3520
;; Using Sprint v1.00
;;
;; Public Domain -- use & abuse as you will at your own risk.
;;
;; Comments & constructive criticism welcome
;;
;;----------------------------------------------------------------------------
;;
;; Turbo Pascal Reserved Words ( from page 11 of TP v5.0 Reference Guide )
;;
;; sorted by size & alphabetically
;;
;; do if in of or to
;; and div end for mod nil not set shl shr var xor
;; case else file goto then type unit uses with
;; array begin const label until while
;; downto inline packed record repeat string
;; forward program
;; absolute external function
;; interface interrupt procedure
;;
;; implementation
;;
;;----------------------------------------------------------------------------
;;
;; Additional ( non-reserved? ) words that are upper cased :
;;
;; dec inc ord
;; addr byte char comp pred real succ true word
;; false
;; double single string
;; integer longint pointer
;; extended shortint
;;
;;----------------------------------------------------------------------------
;;----------------------------------------------------------------------------
;; setmark1
;;----------------------------------------------------------------------------
;; this macro sets mark1 to whichever of the following occurs first after the
;; current point : 1) end of the file
;; 2) an opening '{' comment
;; 3) an opening '(*' comment
;; 4) a single quote
setmark1 : mark ( f toend set mark1 )
mark ( if ('{' csearch) (set mark1) )
mark ( if ( ('(' csearch) && (c current = '*') )
(if (before mark1) (set mark1) ) )
mark ( if (''' csearch) ( if (before mark1) (set mark1) ) )
;;-----------------------------------------------------------------------------
;; skipprotected
;;-----------------------------------------------------------------------------
;; this macro goes to mark1 and then skips past the protected source, where
;; protected source is that source inside a string literal, a { } comment or a
;; (* *) comment. Note that imbedded quotes are handled correctly though they
;; appear to the macro to be two consecutive strings, the first being null
skipprotected : ; assume mark1 is at character starting non-source
to mark1
if ( current = '{' )
( c '}' csearch )
else if ( current = ''' )
( c ''' csearch )
else if ( current = '*' )
( c '*' csearch
while ( (!isend) && (c current != ')' ) ) ('*' csearch) )
c
past isgray
;;----------------------------------------------------------------------------
;; upkeywords
;;----------------------------------------------------------------------------
;; this macros examines each token from the current point to mark1 and if it
;; is a key word for pascal it upper cases it
upkeywords : int upit
while ( (to istoken) && (!after mark1) )
( mark (copy past istoken q4)
4 allcaps ; capitalize q register 4
length q4
case (
2 set q7 "DO IF IN OF OR TO"
,3 set q7 "AND DIV END FOR MOD NIL NOT SET SHL SHR VAR XOR DEC INC ORD"
,4 set q7 "CASE ELSE FILE GOTO THEN TYPE UNIT USES WITH ADDR BYTE CHAR COMP PRED REAL SUCC TRUE WORD"
,5 set q7 "ARRAY BEGIN CONST LABEL UNTIL WHILE FALSE"
,6 set q7 "DOWNTO INLINE PACKED RECORD REPEAT STRING DOUBLE SINGLE STRING"
,7 set q7 "PROGRAM FORWARD INTEGER LONGINT POINTER"
,8 set q7 "ABSOLUTE EXTERNAL FUNCTION EXTENDED SHORTINT"
,9 set q7 "INTERFACE INTERRUPT PROCEDURE"
,14 set q7 "IMPLEMENTATION"
,$ set q7 ""
)
0 -> upit
if ( length q7 > 0 )
mark ( to q7 if ( 0 search q4 ) ( 1 -> upit ) )
if ( upit )
( while istoken toupper )
else
( past istoken )
)
draw
;;----------------------------------------------------------------------------
;; pascal
;;----------------------------------------------------------------------------
;; this macro scans the entire file chunk by chunk for keywords that should be
;; upper case
pascal : ; go to start of the file
r toend
past isgray
while ( !isend )
( setmark1 ; mark region up to next comment or string start
upkeywords ; make each keyword to mark1 upper case
skipprotected ; skip to character after comment or string
)