home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / STRIPCOM.ICN < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.7 KB  |  70 lines

  1. ############################################################################
  2. #
  3. #    File:     stripcom.icn
  4. #
  5. #    Subject:  Procedures to strip comments out of Icon line
  6. #
  7. #    Author:   Richard L. Goerwitz
  8. #
  9. #    Date:     June 3, 1991
  10. #
  11. ###########################################################################
  12. #
  13. #    Version:  1.4
  14. #
  15. ###########################################################################
  16. #  
  17. #  Strip commented-out portion of a line of Icon code.  Fails on lines
  18. #  which, either stripped or otherwise, come out as an empty string.
  19. #
  20. #  Note: It also removes whitespace, leaving the program un-indented.  REG
  21. #
  22. ############################################################################
  23. #
  24. #  BUGS:  Can't handle lines ending in an underscore as part of a
  25. #  broken string literal, since stripcom is not intended to be used
  26. #  on sequentially read files.  It simply removes comments from indi-
  27. #  vidual lines.
  28. #
  29. ############################################################################
  30.  
  31.  
  32. # To preserve parallelism between file and procedure names.
  33. procedure stripcom(s)
  34.     return strip_comments(s)
  35. end
  36.  
  37.  
  38. # The original name -
  39. procedure strip_comments(s)
  40.  
  41.     local i, j, c, c2, s2
  42.  
  43.     s ? {
  44.     tab(many(' \t'))
  45.     pos(0) & fail
  46.         find("#") | (return trim(tab(0),' \t'))
  47.     match("#") & fail
  48.     (s2 <- tab(find("#"))) ? {
  49.         c2 := &null
  50.         while tab(upto('\\"\'')) do {
  51.         case c := move(1) of {
  52.             "\\"   : {
  53.             if match("^")
  54.             then move(2)
  55.             else move(1)
  56.             }
  57.             default: {
  58.             if \c2
  59.             then (c == c2, c2 := &null)
  60.             else c2 := c
  61.             }
  62.         }
  63.         }
  64.         /c2
  65.     }
  66.     return "" ~== trim((\s2 | tab(0)) \ 1, ' \t')
  67.     }
  68.  
  69. end
  70.