[comp.lang.icon] Stripping comments

alex@laguna.metaphor.COM (Bob Alexander) (09/27/90)

Here's a routine I just whipped up.  I tested it some but don't have
complete confidence in it.  Comments? (pun intended)

procedure trimcomment(s1) # s2
   local c,delim
   s1 ? {
      while tab(upto('"\'\\#')) do {
         case c := move(1) of {
            !"\"'": {
               delim := if \delim then {
                  if delim == c then &null
                  }
               else c
               }
            "\\": if \delim then ="^" & move(1)   # in case he used "\^'"
            "#": if /delim then return trim(&subject[1:&pos - 1])
            }
         }
      }
   return trim(s1)
end

-- Bob Alexander

Metaphor Computer Systems   (415) 961-3600 x751   alex@metaphor.com
====^=== Mountain View, CA  ...{uunet}!{decwrl,apple}!metaphor!alex