From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: CC Mode - syntactical can of worms. Date: Thu, 31 Jan 2008 22:05:19 +0000 Message-ID: <20080131220519.GA3770@muc.de> References: <20080131114546.GA2150@muc.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1201816488 2565 80.91.229.12 (31 Jan 2008 21:54:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 31 Jan 2008 21:54:48 +0000 (UTC) Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 31 22:55:09 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JKhN2-0004gY-43 for ged-emacs-devel@m.gmane.org; Thu, 31 Jan 2008 22:54:56 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JKhMa-0004Uw-Ne for ged-emacs-devel@m.gmane.org; Thu, 31 Jan 2008 16:54:28 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JKhMS-0004S4-O0 for emacs-devel@gnu.org; Thu, 31 Jan 2008 16:54:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JKhMQ-0004Pn-6N for emacs-devel@gnu.org; Thu, 31 Jan 2008 16:54:20 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JKhMP-0004Pb-RZ for emacs-devel@gnu.org; Thu, 31 Jan 2008 16:54:17 -0500 Original-Received: from colin.muc.de ([193.149.48.1] helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JKhMP-0002NN-A3 for emacs-devel@gnu.org; Thu, 31 Jan 2008 16:54:17 -0500 Original-Received: (qmail 17460 invoked by uid 3782); 31 Jan 2008 21:54:12 -0000 Original-Received: from acm.muc.de (p57AF62B3.dip.t-dialin.net [87.175.98.179]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Thu, 31 Jan 2008 22:54:10 +0100 Original-Received: (qmail 3966 invoked by uid 1000); 31 Jan 2008 22:05:19 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:87887 Archived-At: Hi, Stefan! On Thu, Jan 31, 2008 at 10:00:07AM -0500, Stefan Monnier wrote: > > Hi, Emacs and CC Mode! > > Following up from: [orium69@gmail.com: Bug in emacs 22.1.1 (cosmetic > > bug)]. > > This bug was in C Mode, with the following source line: > > #warning for isn't a keyword here. > > This fouls up the fontification, because the syntactic fontification > > recognises the apostrophe as a string opener. It can get pretty bad - > > here is a syntactically correct C function: > > 1 #warning for isn't a keyword here. ( > > 2 //#warning for isnt a keyword here. > > 3 void foo (bar) > > 4 { > > 5 #error Brace yourself! } > > 6 printf ("Hello, world!\n") ; /* the famous one liner! */ > > 7 } > You forget other interesting constructs such as > #define HELLO } > #define WORLD ) > void foo (WORLD > { > printf ("Hello\n"WORLD; > HELLO Well, anybody who writes anything like this will get what she deserves. > and of course, the more common ones like > #if foo > void foo (void) > { > size_t toto; > #else > int foo () > { > unsigned toto; > #endif Yes, this has been on my TODO list for a long time. It shouldn't be that difficult to fix. I'm intending a fix in CC Mode 5.32. > CC-mode's job is fundamentally impossible. Hey, don't be like that! ;-) Yes, people can deliberately break it with the likes of HELLO and WORLD, but the more modest aim of CC Mode, to deal properly with anything reasonable, is doable. I think I can fix this by setting a neutral syntax-table property on anything obtrusive in a CPP construct. Here's a first shot at doing that: ;; Set syntax table properties on a CPP (logical) line, so that it becomes ;; "syntactically neutral". This means that lines such as: ;; ;; #warning for isn't a keyword. ;; ^ ;; and ;; ;; #define RBRACE } ;; ^ ;; won't interact syntactically with the rest of the file. (defun c-neutralize-CPP-line (beg end) (let (s) (while (progn (setq s (parse-partial-sexp beg end -1)) (cond ((< (nth 0 s) 0) ; found an unmated ),},] (c-put-char-property (1- (point)) 'syntax-table '(1)) ; "punctuation". t) ((or (nth 3 s) (nth 4 s)) ; In a string or comment. (c-put-char-property (nth 8 s) 'syntax-table '(1)) t) ((> (nth 0 s) 0) ; In a (,{,[ (c-put-char-property (nth 1 s) 'syntax-table '(1)) t) (t nil)))))) > Stefan -- Alan Mackenzie (Nuremberg, Germany).