home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / sprint / uppascal.zip / UPPASC.SPM
Text File  |  1989-07-02  |  5KB  |  135 lines

  1. ;;----------------------------------------------------------------------------
  2. ;; 
  3. ;;   Turbo Pascal Version 5.0 Key Word Upper Caser
  4. ;;   ---------------------------------------------
  5. ;;
  6. ;;   The macro 'pascal' when invoked within a buffer will make all occurances
  7. ;;   of Pascal keywords ( reserved words and few others ) uppercase.
  8. ;;
  9. ;;   If Pascal ( Turbo or otherwise ) is not your language then I hope that the
  10. ;;   code below is straightforward enough for easy adaptation to the syntax
  11. ;;   of your favourite language.
  12. ;;
  13. ;;   Designed & Implemented by Ken Westerback 73547,3520
  14. ;;                    Using Sprint v1.00
  15. ;;
  16. ;;   Public Domain -- use & abuse as you will at your own risk.
  17. ;;
  18. ;;   Comments & constructive criticism welcome
  19. ;;
  20. ;;----------------------------------------------------------------------------
  21. ;;
  22. ;; Turbo Pascal Reserved Words ( from page 11 of TP v5.0 Reference Guide )
  23. ;;
  24. ;; sorted by size & alphabetically
  25. ;;
  26. ;; do        if        in        of     or     to
  27. ;; and       div       end       for    mod    nil  not  set  shl shr var xor
  28. ;; case      else      file      goto   then   type unit uses with
  29. ;; array     begin     const     label  until  while
  30. ;; downto    inline    packed    record repeat string
  31. ;; forward   program 
  32. ;; absolute  external  function 
  33. ;; interface interrupt procedure
  34. ;;
  35. ;; implementation
  36. ;;
  37. ;;----------------------------------------------------------------------------
  38. ;;
  39. ;; Additional ( non-reserved? ) words that are upper cased :
  40. ;;
  41. ;; dec      inc      ord 
  42. ;; addr     byte     char    comp pred real succ true word
  43. ;; false  
  44. ;; double   single   string
  45. ;; integer  longint  pointer
  46. ;; extended shortint
  47. ;;
  48. ;;----------------------------------------------------------------------------
  49.  
  50. ;;----------------------------------------------------------------------------
  51. ;; setmark1
  52. ;;----------------------------------------------------------------------------
  53. ;; this macro sets mark1 to whichever of the following occurs first after the
  54. ;; current point : 1) end of the file
  55. ;;                 2) an opening '{' comment
  56. ;;                 3) an opening '(*' comment
  57. ;;                 4) a  single quote
  58.  
  59. setmark1 : mark ( f toend set mark1 )
  60.           mark ( if ('{' csearch) (set mark1) )
  61.          mark ( if ( ('(' csearch) && (c current = '*') )
  62.                    (if (before mark1) (set mark1) ) )      
  63.            mark ( if (''' csearch) ( if (before mark1) (set mark1) ) )
  64.  
  65. ;;-----------------------------------------------------------------------------
  66. ;; skipprotected
  67. ;;-----------------------------------------------------------------------------
  68. ;; this macro goes to mark1 and then skips past the protected source, where
  69. ;; protected source is that source inside a string literal, a { } comment or a
  70. ;; (* *) comment.  Note that imbedded quotes are handled correctly though they
  71. ;; appear to the macro to be two consecutive strings, the first being null
  72.  
  73. skipprotected : ; assume mark1 is at character starting non-source
  74.              to mark1
  75.                 if ( current = '{' )  
  76.                 ( c '}' csearch )
  77.                 else if ( current = ''' ) 
  78.                 ( c ''' csearch )
  79.              else if ( current = '*' )
  80.                 ( c '*' csearch
  81.                   while ( (!isend) && (c current != ')' ) ) ('*' csearch) ) 
  82.              c
  83.              past isgray
  84.  
  85. ;;----------------------------------------------------------------------------
  86. ;; upkeywords
  87. ;;----------------------------------------------------------------------------
  88. ;; this macros examines each token from the current point to mark1 and if it
  89. ;; is a key word for pascal it upper cases it
  90.  
  91. upkeywords : int upit
  92.              while ( (to istoken) && (!after mark1) )
  93.                    ( mark (copy past istoken q4)
  94.                    4 allcaps ; capitalize q register 4
  95.                      length q4 
  96.                  case (
  97.                         2 set q7 "DO IF IN OF OR TO"
  98.                    ,3 set q7 "AND DIV END FOR MOD NIL NOT SET SHL SHR VAR XOR DEC INC ORD"
  99.                    ,4 set q7 "CASE ELSE FILE GOTO THEN TYPE UNIT USES WITH ADDR BYTE CHAR COMP PRED REAL SUCC TRUE WORD"
  100.                    ,5 set q7 "ARRAY BEGIN CONST LABEL UNTIL WHILE FALSE"
  101.                    ,6 set q7 "DOWNTO INLINE PACKED RECORD REPEAT STRING DOUBLE SINGLE STRING"
  102.                    ,7 set q7 "PROGRAM FORWARD INTEGER  LONGINT  POINTER"
  103.                    ,8 set q7 "ABSOLUTE EXTERNAL FUNCTION EXTENDED SHORTINT"
  104.                    ,9 set q7 "INTERFACE INTERRUPT PROCEDURE"
  105.                   ,14 set q7 "IMPLEMENTATION"
  106.                    ,$ set q7 ""
  107.                     )
  108.                  0 -> upit
  109.                  if ( length q7 > 0 ) 
  110.                     mark ( to q7 if ( 0 search q4 ) ( 1 -> upit ) )
  111.                  if ( upit )
  112.                     ( while istoken toupper )
  113.                    else
  114.                     ( past istoken )
  115.                 )
  116.            draw
  117.  
  118. ;;----------------------------------------------------------------------------
  119. ;; pascal
  120. ;;----------------------------------------------------------------------------
  121. ;; this macro scans the entire file chunk by chunk for keywords that should be
  122. ;; upper case
  123.  
  124. pascal : ; go to start of the file
  125.  
  126.         r toend
  127.         past isgray
  128.             
  129.         while ( !isend )    
  130.             ( setmark1      ; mark region up to next comment or string start
  131.              upkeywords    ; make each keyword to mark1 upper case 
  132.             skipprotected ; skip to character after comment or string
  133.            )  
  134.  
  135.