From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: dino chiesa Newsgroups: gmane.emacs.devel Subject: RE: cc-mode help - how to support literal strings in C# syntax? Date: Tue, 29 Dec 2009 20:40:56 -0800 Message-ID: References: , <4B39DD6E.1070204@online.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1262148083 28171 80.91.229.12 (30 Dec 2009 04:41:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Dec 2009 04:41:23 +0000 (UTC) Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 30 05:41:15 2009 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 1NPqN0-00070y-Bg for ged-emacs-devel@m.gmane.org; Wed, 30 Dec 2009 05:41:14 +0100 Original-Received: from localhost ([127.0.0.1]:55052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPqN0-0000QS-OX for ged-emacs-devel@m.gmane.org; Tue, 29 Dec 2009 23:41:14 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NPqMw-0000Q5-OZ for emacs-devel@gnu.org; Tue, 29 Dec 2009 23:41:10 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NPqMs-0000Oz-7H for emacs-devel@gnu.org; Tue, 29 Dec 2009 23:41:10 -0500 Original-Received: from [199.232.76.173] (port=50001 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPqMs-0000Ow-3i for emacs-devel@gnu.org; Tue, 29 Dec 2009 23:41:06 -0500 Original-Received: from col0-omc3-s11.col0.hotmail.com ([65.55.34.149]:64432) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NPqMp-0005d1-7m; Tue, 29 Dec 2009 23:41:03 -0500 Original-Received: from COL124-W52 ([65.55.34.137]) by col0-omc3-s11.col0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 29 Dec 2009 20:40:56 -0800 X-Originating-IP: [96.236.193.50] Importance: Normal In-Reply-To: <4B39DD6E.1070204@online.de> X-OriginalArrivalTime: 30 Dec 2009 04:40:56.0759 (UTC) FILETIME=[4703CC70:01CA890A] X-detected-operating-system: by monty-python.gnu.org: Windows 2000 SP4, XP SP1+ 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:119014 Archived-At: Andreas=2C thanks for the reply.=20 The mode is available at:=20 http://www.emacswiki.org/emacs/csharp-mode.el =20 =20 And here is a source code module that exhibits the problem: //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D using System=3B using System.Collections.Generic=3B namespace Example.LiteralStrings { public class Pippo { // Problem: when the final char in an "escaped" string literal is a // slash=2C indenting and fontification breaks. List directories =3D new List { // string #1 in the list @"C:\Temp\sub1\"=2C // The emacs parser thinks the string has not ended. // This comment is fontified and indented as if it is i= n // the middle of a string literal. // string #2 @"C:\Temp\sub2\"=2C // Because we have another \" at the end of a string=2C // emacs now thinks we're "out" of the string literal. // This comment is now indented and fontified correctly. // string #3 @"C:\Home\" // A third \"=2C and now emacs thinks we're back inside= the string literal. // The rest of the code will be treated as if it were i= nside the string literal. }=3B // this is indented wrongly // and the incorrect indenting continues all the way through protected void Page_Load(object sender=2C EventArgs e) { Console.WriteLine("Hello {0}"=2C "world")=3B } } } //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 =20 I will check out the beg-end.el as well=2C to see if I can figure out how t= o use it in cc-mode.=20 (csharp-mode). =20 I'll be interested to see what you find.=20 =20 =20 -Dino =20 > Date: Tue=2C 29 Dec 2009 11:43:58 +0100 > From: andreas.roehler@online.de > To: dpchiesa@hotmail.com > CC: emacs-devel@gnu.org=3B bug-cc-mode@gnu.org > Subject: Re: cc-mode help - how to support literal strings in C# syntax? >=20 > dino chiesa wrote: >>=20 >> I'm improving the csharp-mode from http://www.emacswiki.org/emacs/CSharp= Mode . In case you're not aware=2C it's derived from cc-mode=2C something l= ike Java=2C but with a few different syntactic quirks.=20 >>=20 >> The existing csharp-mode.el is pretty good.=20 >> There were a couple things I fixed:=20 >>=20 >> - #if/else/endif was not being properly recognized=2C=20 >> was indenting and fontifying strangely >>=20 >> - a struct was not being treated as a class - indenting inside the block= was broken. >>=20 >> - class definitions that derived from other classes were not being parse= d as a class.=20 >>=20 >> These are all minor things I was able to resolve by using c-lang-defcons= t on various constants: c-typeless-decl-kwds=2C c-other-block-decl-kwds=2C = c-cpp-message-directives=2C c-cpp-expr-directives=2C c-colon-type-list-kwds= =2C c-symbol-chars=2C c-block-prefix-disallowed-chars=2C and a few others. >>=20 >> There's one think I haven't been able to resolve. In C# syntax=2C string= s can be specified as they are in C - surrounded by quotes. There's also a = special form of literal string that begins with @=2C n which all characters= in the string are to be treated as "escaped". In other words=20 >>=20 >> @"\usr\bin" =3D=3D "\\usr\\bin" >>=20 >> The problem happens when the literal string ends in a slash. Eg @"\usr\b= in\" The cc-mode syntax engine sees that as an unterminated string=2C the \= " is an escaped double-quote. On the other hand the C# compiler sees it as = a string of 9 chars.=20 >>=20 >> Because it isn't parsed correctly=2C the fontification and indenting is = wrong after a @-prefixed string that ends in a slash.=20 >>=20 >>=20 >> How can I get the prefixed strings to be treated correctly?=20 >>=20 >=20 > Made a beg-end.el for this kind of parsings. > Would try it with your problem. > Feel free to send me your mode as far its done. > Maybe some larger test-code too. >=20 > Should you want to try it yourself=2C get beg-end.el at >=20 > https://code.launchpad.net/s-x-emacs-werkstatt/ >=20 >=20 > Andreas >=20 >=20 >=20 >=20 >>=20 >> Defining a special c-in-literal seems not to be it. That function uses p= arse-partial-sexp =2C which apparently determines if the point is within a = string or not.=20 >>=20 >> Modifying the syntax table to insert @ as a special prefix is also not i= t.=20 >>=20 >> Any suggestions?=20 >>=20 >> dpchiesa@hotmail.com >>=20 >> _________________________________________________________________ >> Hotmail: Trusted email with powerful SPAM protection. >> http://clk.atdmt.com/GBL/go/177141665/direct/01/ >>=20 >>=20 > =20 _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/177141665/direct/01/=