From: skaller <skaller@ozemail.com.au>
To: Jim Farrand <jim@farrand.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] O'Caml looks at the contents of comments?!
Date: 14 Sep 2003 14:29:25 +1000 [thread overview]
Message-ID: <1063513765.23073.46.camel@pelican> (raw)
In-Reply-To: <20030913104552.GA21760@farrand.net>
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
next prev parent reply other threads:[~2003-09-14 4:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-13 10:45 Jim Farrand
2003-09-13 11:34 ` Stephane Legrand
2003-09-14 4:29 ` skaller [this message]
2003-09-14 4:49 ` Shawn Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1063513765.23073.46.camel@pelican \
--to=skaller@ozemail.com.au \
--cc=caml-list@inria.fr \
--cc=jim@farrand.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).