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

Go lexer: single line comment without consuming endline, disable EnsureNL #984

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lexers/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion lexers/testdata/go.actual
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ func hello(a int) {

type Int interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
} // The very last comment w/o LF
7 changes: 4 additions & 3 deletions lexers/testdata/go.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"}
]