1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-14 02:23:16 +02:00

Add CMake.

This commit is contained in:
Alec Thomas 2017-09-18 19:29:14 +10:00
parent afc6c44415
commit 57c8e08560
3 changed files with 45 additions and 1 deletions

View File

@ -9,7 +9,7 @@ var Bash = Register(MustNewLexer(
&Config{
Name: "Bash",
Aliases: []string{"bash", "sh", "ksh", "zsh", "shell"},
Filenames: []string{"*.sh", "*.ksh", "*.bash", "*.ebuild", "*.eclass", "*.exheres-0", "*.exlib", "*.zsh", ".bashrc", "bashrc", ".bash_*", "bash_*", "zshrc", ".zshrc", "PKGBUILD"},
Filenames: []string{"*.sh", "*.ksh", "*.bash", "*.ebuild", "*.eclass", "*.exheres-0", "*.exlib", "*.zsh", "*.zshrc", ".bashrc", "bashrc", ".bash_*", "bash_*", "zshrc", ".zshrc", "PKGBUILD"},
MimeTypes: []string{"application/x-sh", "application/x-shellscript"},
},
Rules{

43
lexers/cmake.go Normal file
View File

@ -0,0 +1,43 @@
package lexers
import (
. "github.com/alecthomas/chroma" // nolint
)
// Cmake lexer.
var Cmake = Register(MustNewLexer(
&Config{
Name: "CMake",
Aliases: []string{"cmake"},
Filenames: []string{"*.cmake", "CMakeLists.txt"},
MimeTypes: []string{"text/x-cmake"},
},
Rules{
"root": {
{`\b(\w+)([ \t]*)(\()`, ByGroups(NameBuiltin, Text, Punctuation), Push("args")},
Include("keywords"),
Include("ws"),
},
"args": {
{`\(`, Punctuation, Push()},
{`\)`, Punctuation, Pop(1)},
{`(\$\{)(.+?)(\})`, ByGroups(Operator, NameVariable, Operator), nil},
{`(\$ENV\{)(.+?)(\})`, ByGroups(Operator, NameVariable, Operator), nil},
{`(\$<)(.+?)(>)`, ByGroups(Operator, NameVariable, Operator), nil},
{`(?s)".*?"`, LiteralStringDouble, nil},
{`\\\S+`, LiteralString, nil},
{`[^)$"# \t\n]+`, LiteralString, nil},
{`\n`, Text, nil},
Include("keywords"),
Include("ws"),
},
"string": {},
"keywords": {
{`\b(WIN32|UNIX|APPLE|CYGWIN|BORLAND|MINGW|MSVC|MSVC_IDE|MSVC60|MSVC70|MSVC71|MSVC80|MSVC90)\b`, Keyword, nil},
},
"ws": {
{`[ \t]+`, Text, nil},
{`#.*\n`, Comment, nil},
},
},
))

View File

@ -18,5 +18,6 @@ var SwapOff = Register(chroma.NewStyle("swapoff", map[chroma.TokenType]string{
chroma.GenericUnderline: "underline",
chroma.NameTag: "bold",
chroma.NameAttribute: "#ansiteal",
chroma.NameVariable: "bold",
chroma.Error: "#ansired",
}))