[comp.lang.icon] line splits & uncommenting

goer%sophist@GARGOYLE.UCHICAGO.EDU (Richard Goerwitz) (09/28/90)

	Has anybody thought about the pathological split line literal?
	           
	           tmp := []
	           while find("\"567_
	                 #934.\355\\\'",read()) do # Unbelievable isn't it
	                    put(tmp,"Field_1_
	                        _78\'#\\\"YYY_
	                        Continuing_String_
	                        Literally_Pathetic#")  # \\ "ack!" #\\

I confess that I hadn't thought about the split-line literal.  I don't
use them myself, and generally don't like the look of code that does.
That's no excuse, though.

BTW, do you have a solution in mind?

We know that the underscore has to be the last thing on the line, except
for whitespace and comments.  I'll bet it would be possible to modify the
procedures posted so that they look, not only for " and ' and \, but also
_.  If the underscore is encountered, then you could tab past any spaces
and newlines (if present), and if either pos(0) or match("#") succeed,
then abort all attempts at ' and "-matching, and return &subject[1:&pos].

Just an off-the-cuff guess.  If anyone cleans up our collective postings
and makes the _ thing work, could he or she please re-post the resulting
procedure?

-Richard

/

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

Wow -- the problems and solutions are coming in faster than I can
formulate a reply!  Have to learn to type (and think) faster.

Another possible solution to the split-string-literal problem is simply
to make the variable that remembers the string literal delimiter
persistant (static or global).  Using as an example the version I
previously posted, "delim" is the variable in question.  The results
could be very wierd if the input program contains certain syntax
errors.

procedure trimcomment(s1) # s2
#
#  Trim comments (and any trailing spaces) from Icon program text line "s1".
#
   static delim
   local c
   s1 ? {
      while tab(upto('"\'\\#')) do {
         case c := move(1) of {
            "#": if /delim then return trim(&subject[1:&pos - 1],' \t')
            "\\": if \delim then {="^" ; move(1)}   # in case he used "\^""
            default: delim := if \delim then (if delim == c then &null) else c
            }
         }
      }
   return trim(s1,' \t')
end

-- Bob Alexander

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