1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-28 03:29:41 +02:00

fix(lexers/go): "~" is a valid token (#926)

With the introduction of generics,
tilde is a valid punctuation token in Go programs.
https://go.dev/ref/spec#Operators_and_punctuation

This updates the punctuation regex for the Go lexer,
and adds a test to ensure that it's treated as such.
This commit is contained in:
Abhinav Gupta 2024-02-11 19:51:38 -08:00 committed by GitHub
parent f4788c0e9e
commit 506e36f9e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 3 deletions

View File

@ -55,7 +55,7 @@ func goRules() Rules {
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
{`(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\||<-|\+\+|--|==|!=|:=|\.\.\.|[+\-*/%&])`, Operator, nil},
{`([a-zA-Z_]\w*)(\s*)(\()`, ByGroups(NameFunction, UsingSelf("root"), Punctuation), nil},
{`[|^<>=!()\[\]{}.,;:]`, Punctuation, nil},
{`[|^<>=!()\[\]{}.,;:~]`, Punctuation, nil},
{`[^\W\d]\w*`, NameOther, nil},
},
}

View File

@ -15,4 +15,8 @@ func hello(a int) {
return func() int {
return i
}
} // One last thing
} // One last thing
type Int interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}

View File

@ -84,5 +84,39 @@
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":" "},
{"type":"CommentSingle","value":"// One last thing\n"}
{"type":"CommentSingle","value":"// One last thing\n"},
{"type":"Text","value":"\n"},
{"type":"KeywordDeclaration","value":"type"},
{"type":"Text","value":" "},
{"type":"NameOther","value":"Int"},
{"type":"Text","value":" "},
{"type":"KeywordDeclaration","value":"interface"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"Text","value":"\n\t"},
{"type":"Punctuation","value":"~"},
{"type":"KeywordType","value":"int"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"|"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"~"},
{"type":"KeywordType","value":"int8"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"|"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"~"},
{"type":"KeywordType","value":"int16"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"|"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"~"},
{"type":"KeywordType","value":"int32"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"|"},
{"type":"Text","value":" "},
{"type":"Punctuation","value":"~"},
{"type":"KeywordType","value":"int64"},
{"type":"Text","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"Text","value":"\n"}
]