caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] O'Caml looks at the contents of comments?!
@ 2003-09-13 10:45 Jim Farrand
  2003-09-13 11:34 ` Stephane Legrand
  2003-09-14  4:29 ` skaller
  0 siblings, 2 replies; 4+ messages in thread
From: Jim Farrand @ 2003-09-13 10:45 UTC (permalink / raw)
  To: caml-list

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?

To be fair, it seems that the when compiling without the camlp4
preprocessor, the error message points out the problem very clearly, and
so it wouln't stump people like it did me, and obviously I won't ever be
confused by it again, now I know.  STill I'm curious about why this
should be an error.

Regards,
Jim

-- 
Jim Farrand
-- 
NB: I have a spam-filter on my e-mail account.  The first time you e-mail
me you may be asked to confirm your e-mail address before the system delivers
your mail.  http://farrand.net/home-spamfilter.shtml

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] O'Caml looks at the contents of comments?!
  2003-09-13 10:45 [Caml-list] O'Caml looks at the contents of comments?! Jim Farrand
@ 2003-09-13 11:34 ` Stephane Legrand
  2003-09-14  4:29 ` skaller
  1 sibling, 0 replies; 4+ messages in thread
From: Stephane Legrand @ 2003-09-13 11:34 UTC (permalink / raw)
  To: caml-list

On Sat, Sep 13, 2003 at 11:45:52AM +0100, Jim Farrand wrote:
> ...
> 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?
> ...

It's a FAQ: http://caml.inria.fr/FAQ/FAQ_EXPERT-eng.html#commentaire


Regards,
Stephane.

-- 
<stephane@freebsd-fr.org> - <stephane@freebsd.org>          (\(__)/)
FreeBSD Francophone : www.freebsd-fr.org                     `(QQ)'
Club Unix/Log. libres Cosne/Loire : www.cosnix.org            )  (
                                                             (o  o)
% ATTAC : www.attac.org                                       `--'

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] O'Caml looks at the contents of comments?!
  2003-09-13 10:45 [Caml-list] O'Caml looks at the contents of comments?! Jim Farrand
  2003-09-13 11:34 ` Stephane Legrand
@ 2003-09-14  4:29 ` skaller
  2003-09-14  4:49   ` Shawn Wagner
  1 sibling, 1 reply; 4+ messages in thread
From: skaller @ 2003-09-14  4:29 UTC (permalink / raw)
  To: Jim Farrand; +Cc: caml-list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] O'Caml looks at the contents of comments?!
  2003-09-14  4:29 ` skaller
@ 2003-09-14  4:49   ` Shawn Wagner
  0 siblings, 0 replies; 4+ messages in thread
From: Shawn Wagner @ 2003-09-14  4:49 UTC (permalink / raw)
  To: caml-list

On Sun, Sep 14, 2003 at 02:29:25PM +1000, skaller wrote:
> 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.
> 

I keep getting hit with this too. The problem in my case? Single quotes used
as apostrophes in the documentation in comments. Annoying, even if you know
why it's happening. 

-- 
Shawn Wagner
shawnw@speakeasy.org

-------------------
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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-14  4:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-13 10:45 [Caml-list] O'Caml looks at the contents of comments?! Jim Farrand
2003-09-13 11:34 ` Stephane Legrand
2003-09-14  4:29 ` skaller
2003-09-14  4:49   ` Shawn Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).