-
Notifications
You must be signed in to change notification settings - Fork 52
Use PCRE-compatible CSON grammar #116
Conversation
We finally managed to make this work as expected. This CSON grammar is PCRE compatible and so can be used both in Atom and in GitHub web interface.
Here is how the highlighting works now. All bugs are gone, types and method calls get highlighted properly. Maybe some color tweaks will be needed, but anyway it looks great now! |
Removes '-' characters from named groups to make Oniguruma expressions compatible with PCRE engine.
That's great! Thanks for this. I need a day or two to figure out how to get the atom and github versions to co-exist nicely in this repo - right now what you did will make github.com work but will break our Atom text editor as it isn't PCRE based and also uses this repo. |
@damieng I suppose this grammar will also play well with Atom editor. The conversion we've made can be described as follows:
And it worked. Perhaps, Oniguruma should also support this grammar, as named groups syntax is the same, but just without special characters in group names. |
Just tested the new grammar in Atom editor by using This means an old grammar can be simply replaced with a newer one from this pull request and both GitHub and Atom highlighters would work as expected, no need for extra repositories! |
Awesome! Thanks for this.
…On Tue, Apr 17, 2018 at 9:57 AM Artyom ***@***.***> wrote:
Just tested the new grammar in *Atom* editor by using atom --dev and apm
develop language-csharp. I simply replaced an old JSON grammar with a
newer one that does not contain hyphens in group names and that uses CSON
format. This is the output:
[image: image]
<https://user-images.githubusercontent.com/6759207/38884785-4b0cf120-4279-11e8-88da-e13737b51c33.png>
This means an old grammar can be simply replaced with a newer one from
this pull request and both GitHub and Atom highlighters would work as
expected, no need for extra repositories!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#116 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHQp_iSFkeiE_472CD6fow9u4LxLW_cks5tph7ygaJpZM4TXP8c>
.
|
@worldbeater, thank you! Would it make sense that we add this script to upstream |
I was going to suggest to Dustin that perhaps we just run it one-time upstream to convert the names to not have dashes and maintain it like that going forward so it continues to work for github.com as well as all the other editors. The regex named groups are purely internal so it shouldn't have any affect on anyone else. |
@damieng very nice! The only thing left that bothers me is that for function or constructor parameters type names and variable names are highlighted using the same color now. Is there anything we can do with this? Maybe for parameter names black color can be used, not sure exactly. But also I don't think this is very important :) |
I'll take a look at that tonight. I think I know what's causing it and it will be another tweak on our side. |
Maybe this can help. There are four lines in this grammar that are responsible for parameters highlighting. Each line uses entity.name.variable.parameter.cs name: method parameters, named arguments, anonymous method expressions and lambda parameters. In language-java repository they use variable.parameter.java, so we can use variable.parameter.cs. I'll test it to see what will happen, please hold on. |
Well, if we use language-java approach, we will get this fancy highlighting. |
We finally did this! This CSON grammar is PCRE compatible and so can be used both in Atom and in GitHub web interfaces. An old JSON-based grammar is less readable and less maintainable, so I decided to switch to CSON. Sources were taken from here: https://github.com/dotnet/csharp-tmLanguage/tree/master/grammars
GitHub's highlighter was not highlighting source code correctly while PCRE does not support special characters in named group's names, such as a hyphen. So I got rid of them all using a simple Python script.
This pull request closes these issues while GitHub highlighting now works as expected:
#114
#113
#112
Special thanks to @hacklex for a great help with figuring out what was causing RegEx compatibility issues. It would be almost impossible to implement all these things without his assistance.
Thanks!