all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: dino chiesa <dpchiesa@hotmail.com>
To: <andreas.roehler@online.de>
Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org
Subject: RE: cc-mode help - how to support literal strings in C# syntax?
Date: Tue, 29 Dec 2009 20:40:56 -0800	[thread overview]
Message-ID: <COL124-W52C69E8810C2D0EAC1263BCE790@phx.gbl> (raw)
In-Reply-To: <4B39DD6E.1070204@online.de>


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<string> directories = new List<string> {
            // 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/



  reply	other threads:[~2009-12-30  4:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-29  1:51 cc-mode help - how to support literal strings in C# syntax? dino chiesa
2009-12-29 10:43 ` Andreas Roehler
2009-12-30  4:40   ` dino chiesa [this message]
2010-01-01 11:43     ` Andreas Roehler
2010-01-01 16:04     ` Andreas Roehler
2009-12-30  5:01   ` first-class support for csharp in cc-mode.el dino chiesa
2009-12-30  6:17     ` Miles Bader
2009-12-30  7:18       ` dino chiesa
2009-12-30 11:09         ` Miles Bader
2009-12-30 15:00           ` dino chiesa
2009-12-30 15:19     ` Alan Mackenzie
2009-12-30 15:39       ` Stefan Monnier
2009-12-30 16:29         ` dino chiesa
2009-12-30 16:57           ` Stefan Monnier
2009-12-30 21:01           ` Alan Mackenzie
2009-12-30 21:03             ` dino chiesa
2009-12-31  2:44               ` Miles Bader
2009-12-31  2:58                 ` Jason Rumney
2009-12-31  3:08                 ` Deniz Dogan
2009-12-31  3:18                   ` dino chiesa
2009-12-31  3:13                 ` dino chiesa
2009-12-31 11:43           ` Vagn Johansen
2009-12-30 20:19         ` Alan Mackenzie

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=COL124-W52C69E8810C2D0EAC1263BCE790@phx.gbl \
    --to=dpchiesa@hotmail.com \
    --cc=andreas.roehler@online.de \
    --cc=bug-cc-mode@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.