Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSharp] Rules and labels that collide with C# keywords aren't escaped with a @ prefix in all cases. #3503

Open
NickStrupat opened this issue Jan 19, 2022 · 1 comment

Comments

@NickStrupat
Copy link

It seems the keyword escaping is not working in this example grammar. I believe the left recursion is to blame. Demonstration code is below. I suspect it's around here but not sure: https://github.com/antlr/antlr4/blob/master/tool/resources/org/antlr/v4/tool/templates/codegen/CSharp/CSharp.stg#L934

Just run dotnet build and you'll see the syntax errors of the ANTLR-generated code.

Grammar.g4

grammar Grammar;

root: keyword+;

keyword
    : string=keyword id #str
    | base=keyword id   #b
    | id                #kw
    ;
    
id: Id;

Id: [A-Za-z]+;

A.cs (blank file)

A.csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <NoWarn>108,3021</NoWarn>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Antlr4.Runtime.Standard" Version="4.9.3"/>
        <PackageReference Include="Antlr4BuildTasks" Version="8.17">
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
    </ItemGroup>

    <ItemGroup>
        <Antlr4 Include="Grammar.g4"/>
    </ItemGroup>

</Project>
@KvanTTT
Copy link
Member

KvanTTT commented Jan 19, 2022

Thanks, we've fixed escaping for some cases, see #3451 But another part is ongoing. It looks like your case is already covered in master (reserved string and base for labels).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants