From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Roehler Newsgroups: gmane.emacs.devel Subject: Re: cc-mode help - how to support literal strings in C# syntax? Date: Fri, 01 Jan 2010 12:43:09 +0100 Message-ID: <4B3DDFCD.60909@online.de> 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: 7bit X-Trace: ger.gmane.org 1262346191 11450 80.91.229.12 (1 Jan 2010 11:43:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Jan 2010 11:43:11 +0000 (UTC) Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org To: dino chiesa Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 01 12:43:03 2010 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 1NQfuH-0005Pl-DZ for ged-emacs-devel@m.gmane.org; Fri, 01 Jan 2010 12:43:01 +0100 Original-Received: from localhost ([127.0.0.1]:47348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NQfuH-0007u2-RZ for ged-emacs-devel@m.gmane.org; Fri, 01 Jan 2010 06:43:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NQfuC-0007tx-IU for emacs-devel@gnu.org; Fri, 01 Jan 2010 06:42:56 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NQfu7-0007tN-Ee for emacs-devel@gnu.org; Fri, 01 Jan 2010 06:42:55 -0500 Original-Received: from [199.232.76.173] (port=34667 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NQfu7-0007tK-8D for emacs-devel@gnu.org; Fri, 01 Jan 2010 06:42:51 -0500 Original-Received: from moutng.kundenserver.de ([212.227.126.186]:53733) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NQfu0-0004zv-S4; Fri, 01 Jan 2010 06:42:45 -0500 Original-Received: from [192.168.178.27] (p54BE8E2D.dip0.t-ipconnect.de [84.190.142.45]) by mrelayeu.kundenserver.de (node=mreu1) with ESMTP (Nemesis) id 0M2pyk-1OGhzN1Ld8-00sUVB; Fri, 01 Jan 2010 12:42:40 +0100 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: X-Provags-ID: V01U2FsdGVkX18anunxUezs2R/h1AfT3eHkgF7RsoOO/xIh3qa kaPpTDjCdS6w+dYJ6Q/UqLhRgEEwZ7wdBoPMxopenl4MJ7sPTl BfrBXQZyyo1Qsf/3H0pdC4NnB9YjFgsmoQdLErNAIU= X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:119198 Archived-At: ok, had to change beg-end.el still a little bit, as beg- and end-string are equal here Here its use in thingatpt-utils-base.el ;; Doublequoted (put 'doublequoted 'beginning-op-at (lambda () (beginning-of-form-base "\"" "\"" nil 1))) (put 'doublequoted 'end-op-at (lambda () (when (looking-at "\"") (end-of-form-base "\"" "\"" nil 1)))) It now returns things between regardless escapes. Not uploaded yet. Still some minor issues, checks to do. I'll send a message, if its ready. hopefully, happy new year Andreas dino chiesa wrote: > Andreas, thanks for the reply. > The mode is available at: > http://www.emacswiki.org/emacs/csharp-mode.el > > > And here is a source code module that exhibits the problem: > //======================================== > using System; > using System.Collections.Generic; > > namespace Example.LiteralStrings > { > public class Pippo > { > // Problem: when the final char in an "escaped" string literal is a > // slash, indenting and fontification breaks. > List directories = new List { > // string #1 in the list > @"C:\Temp\sub1\", > // The emacs parser thinks the string has not ended. > // This comment is fontified and indented as if it is in > // the middle of a string literal. > // string #2 > @"C:\Temp\sub2\", > // Because we have another \" at the end of a string, > // emacs now thinks we're "out" of the string literal. > // This comment is now indented and fontified correctly. > // string #3 > @"C:\Home\" > // A third \", and now emacs thinks we're back inside the string literal. > // The rest of the code will be treated as if it were inside the string literal. > }; // this is indented wrongly > // and the incorrect indenting continues all the way through > protected void Page_Load(object sender, EventArgs e) > { > Console.WriteLine("Hello {0}", "world"); > } > } > } > > //======================================== > > > I will check out the beg-end.el as well, to see if I can figure out how to use it in cc-mode. > (csharp-mode). > > I'll be interested to see what you find. > > > -Dino > > > >> Date: Tue, 29 Dec 2009 11:43:58 +0100 >> From: andreas.roehler@online.de >> To: dpchiesa@hotmail.com >> CC: emacs-devel@gnu.org; bug-cc-mode@gnu.org >> Subject: Re: cc-mode help - how to support literal strings in C# syntax? >> >> dino chiesa wrote: >>> I'm improving the csharp-mode from http://www.emacswiki.org/emacs/CSharpMode . In case you're not aware, it's derived from cc-mode, something like Java, but with a few different syntactic quirks. >>> >>> The existing csharp-mode.el is pretty good. >>> There were a couple things I fixed: >>> >>> - #if/else/endif was not being properly recognized, >>> was indenting and fontifying strangely >>> >>> - a struct was not being treated as a class - indenting inside the block was broken. >>> >>> - class definitions that derived from other classes were not being parsed as a class. >>> >>> These are all minor things I was able to resolve by using c-lang-defconst on various constants: c-typeless-decl-kwds, c-other-block-decl-kwds, c-cpp-message-directives, c-cpp-expr-directives, c-colon-type-list-kwds, c-symbol-chars, c-block-prefix-disallowed-chars, and a few others. >>> >>> There's one think I haven't been able to resolve. In C# syntax, strings can be specified as they are in C - surrounded by quotes. There's also a special form of literal string that begins with @, n which all characters in the string are to be treated as "escaped". In other words >>> >>> @"\usr\bin" == "\\usr\\bin" >>> >>> The problem happens when the literal string ends in a slash. Eg @"\usr\bin\" The cc-mode syntax engine sees that as an unterminated string, the \" is an escaped double-quote. On the other hand the C# compiler sees it as a string of 9 chars. >>> >>> Because it isn't parsed correctly, the fontification and indenting is wrong after a @-prefixed string that ends in a slash. >>> >>> >>> How can I get the prefixed strings to be treated correctly? >>> >> 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. >> >> Should you want to try it yourself, get beg-end.el at >> >> https://code.launchpad.net/s-x-emacs-werkstatt/ >> >> >> Andreas >> >> >> >> >>> Defining a special c-in-literal seems not to be it. That function uses parse-partial-sexp , which apparently determines if the point is within a string or not. >>> >>> Modifying the syntax table to insert @ as a special prefix is also not it. >>> >>> Any suggestions? >>> >>> dpchiesa@hotmail.com >>> >>> _________________________________________________________________ >>> Hotmail: Trusted email with powerful SPAM protection. >>> http://clk.atdmt.com/GBL/go/177141665/direct/01/ >>> >>> >> > _________________________________________________________________ > Hotmail: Trusted email with powerful SPAM protection. > http://clk.atdmt.com/GBL/go/177141665/direct/01/