From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA02852; Sun, 14 Sep 2003 06:30:04 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA12584 for ; Sun, 14 Sep 2003 06:30:02 +0200 (MET DST) Received: from mail1.tpgi.com.au (mail.tpgi.com.au [203.12.160.57]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8E4U0T12672 for ; Sun, 14 Sep 2003 06:30:01 +0200 (MET DST) Received: from 203-213-82-41-syd-ts14-2600.tpgi.com.au (203-213-82-41-syd-ts14-2600.tpgi.com.au [203.213.82.41]) by mail1.tpgi.com.au (8.11.6/8.11.6) with ESMTP id h8E4TnH30543; Sun, 14 Sep 2003 14:29:50 +1000 Subject: Re: [Caml-list] O'Caml looks at the contents of comments?! From: skaller Reply-To: skaller@ozemail.com.au To: Jim Farrand Cc: caml-list@inria.fr In-Reply-To: <20030913104552.GA21760@farrand.net> References: <20030913104552.GA21760@farrand.net> Content-Type: text/plain Message-Id: <1063513765.23073.46.camel@pelican> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 14 Sep 2003 14:29:25 +1000 Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ozemail:01 farrand:01 camlp:01 commenting:01 ignores:01 enforced:01 c's:01 terminator:01 span:99 compiler:01 ocaml:01 ocaml:01 sci:01 behaviour:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 2003-09-13 at 20:45, Jim Farrand wrote: > I've spent a long time puzzling over a "string not terminated" error > which was being reported inside a class I'm writing. Camlp4r reported > the error just as being somewhere in the class (i.e. Line 267 character > 4 - 1076) which gave me quite a bit of code to look over. I spent a > long while staring at the code quite puzzled because I couldn't see an > unterminated string anywhere. > > Eventually I started commenting out bits of code, and I was even more > confused when I'd commented out the entire class and STILL got the > error. > > Eventually I traced the error to an unterminated string inside a > comment. This strikes me as slightly odd behaviour - one of the first > things comp sci students are taught about comments is that the compiler > ignores them. As this has been my experience for many years it took me > a long time to even consider that I could have a syntax error inside a > comment. > > So why is this restriction enforced? > The reason is: Ocaml comments are designed to be able to comment out code. If you consider the code: " (* " ^ x and comment out the first part like this: (* " (* " ^ *) x it wouldn't work unless the (* in the string was detected as being inside a string and ignored. The contents of comments are not ignored, in the sense that every lexer even C's, has to find the comment terminator. Bash and C++ comments: # .... // .... do not have this problem, since they're terminated by end of line. Also: Ocaml, wrongly I think, allows strings to span lines. Hmm .. Felix doesn't do the string detection .. which means its nestable /* .. */ comments wont wrap code containing strings containing /* or */ .. Hmmmm .. thanks for raising this issue .. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners