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:
parent
f4788c0e9e
commit
506e36f9e0
@ -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},
|
||||
},
|
||||
}
|
||||
|
6
lexers/testdata/go.actual
vendored
6
lexers/testdata/go.actual
vendored
@ -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
|
||||
}
|
||||
|
36
lexers/testdata/go.expected
vendored
36
lexers/testdata/go.expected
vendored
@ -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"}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user