[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Nested Comments in Haskell



Original-Via: uk.ac.nsf; Tue, 18 Sep 90 08:04:11 BST
Date: Tue, 18 Sep 90 00:59:15 EDT
From: Paul Hudak <hudak-paul@cs.yale.edu>
To: haskell@cs.yale.edu
Cc: hudak@cs.yale.edu
Subject: Nested Comments in Haskell
Sender: haskell-request@cs.glasgow.ac.uk

Kent Karlsson complains about the proposed "improvement" to nested
comments:

   ncomment   ->   {- junk <junk> }
   junk       ->   < any_<-> | whitestuff_<comment> > - <->

that I sent out recently, pointing out that:

(1) things like "-}" inside a string may "catch" an outer nested comment, and
(2) "{- {- -}" is permitted as a complete ncomment.

With regard to (1), I thought I made it pretty clear in my message
that we were making no attempt at solving that particular problem.

With regard to (2), the problem is ambiguity -- note that whitestuff
contains ncomment, and thus things like "{- {- -} -}" do have a proper
parse.  But I agree with Kent that the ambiguity should be removed.

Kent goes on to propose two alternative solutions, both of which
remove the ambiguity (but I found it humorous that he initially made
the same error (2) that was in my solution :-).

On the other hand, I'm not sure that I agree with Kent that it's
reasonable to require strings in nested comments to be properly
constructed.  I can imagine writing:

   WriteFile file quote    -- write " to file

which could lead to trouble.  Kent's first solution also rules out the
"C-ism" example, which again may not be reasonable.

I like Kent's second solution better -- syntactically disallowing
"{-" and "-}" in non-nested comments and strings -- but again the
solution is not perfect.

I conclude that we have not found the perfect solution (perhaps there
is none).  Therefore "on behalf of the committee" I suggest that we
think about it some more before yielding to a near-perfect solution.

(One idea, by the way, is to treat {- and -} as lexemes, create a class
 of "illegal" lexemes (namely, all sequences of characters not
 currently accounted for in the syntax), and then define a nested
 comment to be something like:

   ncomment -> {- <legal_<{-,-}> | illegal | ncomment> -}

 Note that a string is a legal lexeme.  But I think this needs some
 further thought... any takers?
)

Thanks for your comments Kent (no pun intended).

  -Paul