mirror of
https://github.com/alecthomas/chroma.git
synced 2025-01-28 03:29:41 +02:00
Add CPP lexer (#813)
This commit is contained in:
parent
68d976f00b
commit
e6de3d1f1a
36
lexers/cpp.go
Normal file
36
lexers/cpp.go
Normal file
@ -0,0 +1,36 @@
|
||||
package lexers
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
. "github.com/alecthomas/chroma/v2" // nolint
|
||||
)
|
||||
|
||||
var (
|
||||
cppAnalyserIncludeRe = regexp.MustCompile(`#include <[a-z_]+>`)
|
||||
cppAnalyserNamespaceRe = regexp.MustCompile(`using namespace `)
|
||||
)
|
||||
|
||||
var CPP = Register(MustNewXMLLexer(
|
||||
embedded,
|
||||
"embedded/c++.xml",
|
||||
).SetConfig(
|
||||
&Config{
|
||||
Name: "C++",
|
||||
Aliases: []string{"cpp", "c++"},
|
||||
Filenames: []string{"*.cpp", "*.hpp", "*.c++", "*.h++", "*.cc", "*.hh", "*.cxx", "*.hxx", "*.C", "*.H", "*.cp", "*.CPP", "*.cppm", "*.ixx"},
|
||||
MimeTypes: []string{"text/x-c++hdr", "text/x-c++src"},
|
||||
Priority: 0.1,
|
||||
EnsureNL: true,
|
||||
},
|
||||
)).SetAnalyser(func(text string) float32 {
|
||||
if cppAnalyserIncludeRe.MatchString(text) {
|
||||
return 0.2
|
||||
}
|
||||
|
||||
if cppAnalyserNamespaceRe.MatchString(text) {
|
||||
return 0.4
|
||||
}
|
||||
|
||||
return 0
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user