[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: cc-mode help - how to support literal strings in C# syntax?

From: dino chiesa
Subject: RE: cc-mode help - how to support literal strings in C# syntax?
Date: Tue, 29 Dec 2009 20:40:56 -0800

Andreas, thanks for the reply. 
The mode is available at: 
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
                    // 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
            // 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
                    // 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. 
I'll be interested to see what you find. 

> Date: Tue, 29 Dec 2009 11:43:58 +0100
> From: address@hidden
> To: address@hidden
> CC: address@hidden; address@hidden
> 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? 
>> address@hidden
>> _________________________________________________________________
>> Hotmail: Trusted email with powerful SPAM protection.
>> http://clk.atdmt.com/GBL/go/177141665/direct/01/
Hotmail: Trusted email with powerful SPAM protection.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]