atom / language-csharp

C# language support for Atom
Other
62 stars 52 forks source link

`private` modifier on getter/setter not highlighted correctly #99

Closed Xyene closed 6 years ago

Xyene commented 7 years ago

It looks like on Github, the private modifier on a setter doesn't get highlighted red as it should:

uint _A;
private uint A
{
    get => _A;
    private set { _A = foo(value);  }
}

In a simpler example, it does indeed get highlighted, but perhaps not the right color:

public uint A { get; private set; }
jaredmpayne commented 6 years ago

I second this issue.

It looks like the grammar only defines the beginning (up to the opening brace) and end (the closing brace or semicolon) of a property declaration rather than its actual form. Thus, everything inside of it is treated no differently than any other code even though a property has a very unique format compared to other snippets of C# code.

A screenshot of this in action:

capture

The property grammar according to dotnet: https://github.com/dotnet/csharplang/blob/master/spec/classes.md#properties

property_declaration
    : attributes? property_modifier* type member_name property_body
    ;

property_modifier
    : 'new'
    | 'public'
    | 'protected'
    | 'internal'
    | 'private'
    | 'static'
    | 'virtual'
    | 'sealed'
    | 'override'
    | 'abstract'
    | 'extern'
    | property_modifier_unsafe
    ;

property_body
    : '{' accessor_declarations '}' property_initializer?
    | '=>' expression ';'
    ;

property_initializer
    : '=' variable_initializer ';'
    ;

accessor_declarations
    : get_accessor_declaration set_accessor_declaration?
    | set_accessor_declaration get_accessor_declaration?
    ;

get_accessor_declaration
    : attributes? accessor_modifier? 'get' accessor_body
    ;

set_accessor_declaration
    : attributes? accessor_modifier? 'set' accessor_body
    ;

accessor_modifier
    : 'protected'
    | 'internal'
    | 'private'
    | 'protected' 'internal'
    | 'internal' 'protected'
    ;

accessor_body
    : block
    | ';'
    ;