1
0
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:
Carlos Henrique Guardão Gandarez 2023-08-17 23:54:52 -03:00 committed by GitHub
parent 68d976f00b
commit e6de3d1f1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

36
lexers/cpp.go Normal file
View 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
})