/
cpp.go
36 lines (30 loc) · 798 Bytes
/
cpp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
})