sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 585 forks source link

[Go] Syntax highlighting picks up commented code #126

Closed stevekuznetsov closed 8 years ago

stevekuznetsov commented 8 years ago

Using base16.monokai-dark color scheme, I see the following if I create a Go source file as such:

    //  var userKey key = 0
    //  func NewContext(ctx context.Context, u *User) context.Context {

commentshighlighted

If I add a package declaration to the file, as such:

package test

//  var userKey key = 0
//  func NewContext(ctx context.Context, u *User) context.Context {

I see this: comment

ottob commented 8 years ago

Yes, something is fishy with the var keyword. I have this:

v := "var f"
fmt.Println(v)

resulting in:

screen shot 2016-01-29 at 08 35 14

Notice that fmt.Println(v) is highlighted as a comment, as is the rest of the file after the var keyword. If I edit the string to be just "var" or "varf" the highlighting doesn't break.

ottob commented 8 years ago

Adding a string with comment slashes seem to reset the highlighting:

works

If I remove the slashes, the comment highlighting continues:

nope
wbond commented 8 years ago

There is a bug in Sublime Text's sregex engine that is treating the [[:blank:]] posix range as all of ascii. Should be fixed in the next dev build.

FichteFoll commented 8 years ago

I see that the Go syntax definition uses [[:blank:]] twice and \s everywhere else. Any particular reason?

From what I can tell, they differ in that \s also matches 000A, 000B, 000C, 000D, 0085(NEL), 2028 and 2029 characters, so mostly characters separating lines. Regular expressions are never applied on "multiple lines" though, except for when ST does not implement a unicode line separator character as an actual line separator (which is anything but 000A and 000D; see https://github.com/SublimeTextIssues/Core/issues/548).

wbond commented 8 years ago

@FichteFoll I believe the reason, in this case, is that someone wrote the .tmLanguage version and it was converted to .sublime-syntax. I have noticed that in general the syntax tends to handle unicode better than many, such as by using [[:alpha:]] and [[:alnum:]] instead of just [a-zA-Z] and [a-zA-Z0-9]. My guess is that they used [[:blank:]] for such a reason.

wbond commented 8 years ago

In the process of testing the fixes in ST for `[[:blank:]] I fixed a few small issues with the syntax in 380a68ea807d65ae45acf2b4a268286c9a09843b.

stevekuznetsov commented 8 years ago

@wbond thanks so much for doing this work. If I'm trying to pick up your changes, is there a faster way than waiting for a new beta build?

FichteFoll commented 8 years ago

@stevekuznetsov follow the 'Installation' guide in the readme.

ottob commented 8 years ago

My issues are fixed now. Thanks @wbond!