2018-03-19 17:08:44 +01:00
|
|
|
package m
|
2017-10-22 05:37:38 +02:00
|
|
|
|
|
|
|
import (
|
2018-03-19 17:08:44 +01:00
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
|
|
. "github.com/alecthomas/chroma/lexers/b" // nolint
|
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
2017-10-22 05:37:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Makefile lexer.
|
2018-03-19 17:08:44 +01:00
|
|
|
var Makefile = internal.Register(MustNewLexer(
|
2017-10-22 05:37:38 +02:00
|
|
|
&Config{
|
|
|
|
Name: "Base Makefile",
|
|
|
|
Aliases: []string{"make", "makefile", "mf", "bsdmake"},
|
|
|
|
Filenames: []string{"*.mak", "*.mk", "Makefile", "makefile", "Makefile.*", "GNUmakefile"},
|
|
|
|
MimeTypes: []string{"text/x-makefile"},
|
|
|
|
EnsureNL: true,
|
|
|
|
},
|
|
|
|
Rules{
|
|
|
|
"root": {
|
2018-03-19 17:08:44 +01:00
|
|
|
{`^(?:[\t ]+.*\n|\n)+`, Using(Bash), nil},
|
2017-10-22 05:37:38 +02:00
|
|
|
{`\$[<@$+%?|*]`, Keyword, nil},
|
|
|
|
{`\s+`, Text, nil},
|
|
|
|
{`#.*?\n`, Comment, nil},
|
|
|
|
{`(export)(\s+)(?=[\w${}\t -]+\n)`, ByGroups(Keyword, Text), Push("export")},
|
|
|
|
{`export\s+`, Keyword, nil},
|
2018-03-19 17:08:44 +01:00
|
|
|
{`([\w${}().-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n)+|.*\n)`, ByGroups(NameVariable, Text, Operator, Text, Using(Bash)), nil},
|
2017-10-22 05:37:38 +02:00
|
|
|
{`(?s)"(\\\\|\\.|[^"\\])*"`, LiteralStringDouble, nil},
|
|
|
|
{`(?s)'(\\\\|\\.|[^'\\])*'`, LiteralStringSingle, nil},
|
|
|
|
{`([^\n:]+)(:+)([ \t]*)`, ByGroups(NameFunction, Operator, Text), Push("block-header")},
|
|
|
|
{`\$\(`, Keyword, Push("expansion")},
|
|
|
|
},
|
|
|
|
"expansion": {
|
|
|
|
{`[^$a-zA-Z_()]+`, Text, nil},
|
|
|
|
{`[a-zA-Z_]+`, NameVariable, nil},
|
|
|
|
{`\$`, Keyword, nil},
|
|
|
|
{`\(`, Keyword, Push()},
|
|
|
|
{`\)`, Keyword, Pop(1)},
|
|
|
|
},
|
|
|
|
"export": {
|
|
|
|
{`[\w${}-]+`, NameVariable, nil},
|
|
|
|
{`\n`, Text, Pop(1)},
|
|
|
|
{`\s+`, Text, nil},
|
|
|
|
},
|
|
|
|
"block-header": {
|
|
|
|
{`[,|]`, Punctuation, nil},
|
|
|
|
{`#.*?\n`, Comment, Pop(1)},
|
|
|
|
{`\\\n`, Text, nil},
|
|
|
|
{`\$\(`, Keyword, Push("expansion")},
|
|
|
|
{`[a-zA-Z_]+`, Name, nil},
|
|
|
|
{`\n`, Text, Pop(1)},
|
|
|
|
{`.`, Text, nil},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|