antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.1k stars 3.69k forks source link

CSharp grammar has incorrect definition of Interpolated Strings #1146

Open attodorov opened 6 years ago

attodorov commented 6 years ago

From the grammar:

interpolated_verbatium_string_part
    : interpolated_string_expression
    | DOUBLE_CURLY_INSIDE
    | VERBATIUM_DOUBLE_QUOTE_INSIDE
    | VERBATIUM_INSIDE_STRING
    ;

It's not a double curly by spec. It's a single curly. Here's the correct def:

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated

So the grammar should be

interpolated_verbatium_string_part
    : interpolated_string_expression
    | SINGLE_CURLY_INSIDE
    | VERBATIUM_DOUBLE_QUOTE_INSIDE
    | VERBATIUM_INSIDE_STRING
    ;
attodorov commented 6 years ago

hmm, this still doesn't seem right for other scenarios. If I use the original (unmodified) current grammar, I am experiencing issues with the following code snippets:

s = Regex.Replace(s, pname, $"'{p.Value:MM/dd/yy HH:mm:ss}'");

 Db.Email(person.FromEmail, list,
                    "Volunteer Substitute Commitment for " + org.OrganizationName,
                    $@"
    <p>{person.Name} has requested a substitute on {attend.MeetingDate:MMM d} at {attend.MeetingDate:h:mm tt}.</p>
    <blockquote>
    {reportlink}
    </blockquote>");

public string Schedule => $"{MeetingTime:ddd h:mm tt}";

Thanks

attodorov commented 6 years ago

I found this:

https://github.com/ljw1004/csharpspec/pull/1/files

as well as this:

https://github.com/ljw1004/csharpspec/blob/gh-pages/csharp.g4

But i am having a bit of a hard time transferring the interpolated string spec to the current ANTLR4 grammar.

Thanks, Angel