diff --git a/lexers/go.go b/lexers/go.go index 266289b7c..a9849d69f 100644 --- a/lexers/go.go +++ b/lexers/go.go @@ -13,7 +13,6 @@ var Go = Register(MustNewLexer( Aliases: []string{"go", "golang"}, Filenames: []string{"*.go"}, MimeTypes: []string{"text/x-gosrc"}, - EnsureNL: true, }, goRules, ).SetAnalyser(func(text string) float32 { @@ -32,7 +31,7 @@ func goRules() Rules { {`\n`, Text, nil}, {`\s+`, Text, nil}, {`\\\n`, Text, nil}, - {`//(.*?)\n`, CommentSingle, nil}, + {`//[^\n\r]*`, CommentSingle, nil}, {`/(\\\n)?[*](.|\n)*?[*](\\\n)?/`, CommentMultiline, nil}, {`(import|package)\b`, KeywordNamespace, nil}, {`(var|func|struct|map|chan|type|interface|const)\b`, KeywordDeclaration, nil}, diff --git a/lexers/testdata/go.actual b/lexers/testdata/go.actual index ea33e6cc9..22f227c94 100644 --- a/lexers/testdata/go.actual +++ b/lexers/testdata/go.actual @@ -19,4 +19,4 @@ func hello(a int) { type Int interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 -} +} // The very last comment w/o LF \ No newline at end of file diff --git a/lexers/testdata/go.expected b/lexers/testdata/go.expected index 9860d43e8..c09108220 100644 --- a/lexers/testdata/go.expected +++ b/lexers/testdata/go.expected @@ -84,8 +84,8 @@ {"type":"Text","value":"\n"}, {"type":"Punctuation","value":"}"}, {"type":"Text","value":" "}, - {"type":"CommentSingle","value":"// One last thing\n"}, - {"type":"Text","value":"\n"}, + {"type":"CommentSingle","value":"// One last thing"}, + {"type":"Text","value":"\n\n"}, {"type":"KeywordDeclaration","value":"type"}, {"type":"Text","value":" "}, {"type":"NameOther","value":"Int"}, @@ -118,5 +118,6 @@ {"type":"KeywordType","value":"int64"}, {"type":"Text","value":"\n"}, {"type":"Punctuation","value":"}"}, - {"type":"Text","value":"\n"} + {"type":"Text","value":" "}, + {"type":"CommentSingle","value":"// The very last comment w/o LF"} ]