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

Avoid variable length lookbehind #220

Merged

Conversation

am11
Copy link
Member

@am11 am11 commented Sep 6, 2021

  • GH Linguist supports PCRE grammar, which supports variable (as well as fixed) length lookbehind.
  • VSCode supports Oniguruma grammar, which only support fixed length lookbehind.

so the solution to keep both worlds happy is to use most common syntax; fixed length lookbehind.

@am11
Copy link
Member Author

am11 commented Sep 6, 2021

cc @Gerrit0, this should fix VSCode issue.

@am11 am11 force-pushed the feature/avoid-variable-length-lookbehind branch 5 times, most recently from db92540 to df577c2 Compare September 6, 2021 03:19
@Gerrit0
Copy link

Gerrit0 commented Sep 6, 2021

This doesn't seem to do the right thing:

Screenshot

image

I'm not sure about Linguist, but TextMate regexes are not permitted to match across lines (microsoft/vscode-textmate#32), which makes properly handling the last two cases essentially impossible.

Am I missing some reason that we need lookbehind here at all? The following (with \s*$ branch to avoid detecting a conditional at EOL, for the last two cases) seems to do the trick

\\?(?!\\s*[?.\\[]|\\s*$)
Screenshot

image

@am11 am11 force-pushed the feature/avoid-variable-length-lookbehind branch from df577c2 to 5426265 Compare September 6, 2021 03:45
@am11
Copy link
Member Author

am11 commented Sep 6, 2021

Updated. seems to work on linguist side as well. Thanks!

@am11
Copy link
Member Author

am11 commented Sep 6, 2021

lightshow with 5426265

@Gerrit0
Copy link

Gerrit0 commented Sep 6, 2021

Shoot, I figured out why the lookbehind was there...

public class A {
    public void Nullish() {
        char s = ss ?? 'x'
        if (true) {} // if is wrong color
    }
}

This feels like something else is out of order though. Why is the grammar even getting to conditional expressions if null coalescing matches? This is my first foray into this bit of work, so I'm probably not understanding something else...

@am11
Copy link
Member Author

am11 commented Sep 6, 2021

That case is handled otherwise

describe("Null-coalescing Operator", () => {
would have failed in the CI.

@am11
Copy link
Member Author

am11 commented Sep 6, 2021

public class A {
    public void Nullish() {
-        char s = ss ?? 'x'
+        char s = ss ?? 'x';
        if (true) {} // if is wrong color
    }
}

@Gerrit0
Copy link

Gerrit0 commented Sep 6, 2021

Oh! That makes sense, thanks!... too much time in TypeScript where I never have to type them and they will get automatically added on save.

@am11
Copy link
Member Author

am11 commented Sep 6, 2021

Regarding github/linguist repo, since now it supports (more superior) tree-sitter grammar (github-linguist/linguist#5483 (comment)), we maybe able to switch to https://github.com/tree-sitter/tree-sitter-c-sharp.

The code navigation feature in GitHub has already started to use it: https://docs.github.com/en/github/managing-files-in-a-repository/managing-files-on-github/navigating-code-on-github.

@JoeRobich
Copy link
Member

@am11 Thanks!

@JoeRobich JoeRobich merged commit ff57b2e into dotnet:main Sep 7, 2021
@am11 am11 deleted the feature/avoid-variable-length-lookbehind branch September 7, 2021 20:11
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.

3 participants