Skip to content

Be a bit more restrictive in the negative lookahead for properties#117

Merged
DustinCampbell merged 1 commit intodotnet:masterfrom
DustinCampbell:issue-115
May 14, 2018
Merged

Be a bit more restrictive in the negative lookahead for properties#117
DustinCampbell merged 1 commit intodotnet:masterfrom
DustinCampbell:issue-115

Conversation

@DustinCampbell
Copy link
Copy Markdown
Member

Fixes #75 and #115

There is a bit of negative lookahead for properties to avoid matching nested types as property declarations. Consider the following code:

class Outer
{
    class Inner
    {
    }
}

When the line "class Inner" is matched it really looks like a property declaration where the type is "class" and the name is "Inner". So, there's negative lookahead to ensure that properties can't start with "class" or other keywords.

Before this change, the lookahead was matching .*(class|event|etc...), which was too permissive and allowed it to eat up comments. This change adjusts the lookahead to [[:word:][:space:]]*(class|event|etc...) to make it a little less restrictive.

In addition, there was a spurious \s* after the negative lookahead that seems like it was only there to help distinguish field and property declarations. This is more properly handled by just ordering the rules differently (putting properties first) and removing the \s*.

Fixes dotnet#75 and dotnet#115

There is a bit of negative lookahead for properties to avoid matching nested types
as property declarations. Consider the following code:

```C#
class Outer
{
    class Inner
    {
    }
}
```

When the line "class Inner" is matched it really looks like a property declaration
where the type is "class" and the name is "Inner". So, there's negative lookahead to
ensure that properties can't start with "class" or other keywords.

Before this change, the lookahead was matching `.*(class|event|etc...)`, which was
too permissive and allowed it to eat up comments. This change adjusts the lookahead to
`[[:word:][:space:]]*(class|event|etc...)` to make it a little less restrictive.

In addition, there was a spurious `\s*` after the negative lookahead that seems like it
was only there to help distinguish field and property declarations. This is more properly
handled by just ordering the rules differently (putting properties first) and removing
the `\s*`.
@DustinCampbell DustinCampbell merged commit 09d01b0 into dotnet:master May 14, 2018
@DustinCampbell DustinCampbell deleted the issue-115 branch May 14, 2018 18:17
DustinCampbell added a commit to DustinCampbell/vscode that referenced this pull request May 14, 2018
This grammar update fixes an issue with comments after property declarations
solved by dotnet/csharp-tmLanguage#117.
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

Successfully merging this pull request may close these issues.

1 participant