1 package lexers
2
3 import (
4 . "github.com/alecthomas/chroma/v2"
5 )
6
7
8 var Makefile = Register(MustNewLexer(
9 &Config{
10 Name: "Makefile",
11 Aliases: []string{"make", "makefile", "mf", "bsdmake"},
12 Filenames: []string{"*.mak", "*.mk", "Makefile", "makefile", "Makefile.*", "GNUmakefile", "BSDmakefile"},
13 MimeTypes: []string{"text/x-makefile"},
14 EnsureNL: true,
15 },
16 makefileRules,
17 ))
18
19 func makefileRules() Rules {
20 return Rules{
21 "root": {
22 {`^(?:[\t ]+.*\n|\n)+`, Using("Bash"), nil},
23 {`\$[<@$+%?|*]`, Keyword, nil},
24 {`\s+`, Text, nil},
25 {`#.*?\n`, Comment, nil},
26 {`(export)(\s+)(?=[\w${}\t -]+\n)`, ByGroups(Keyword, Text), Push("export")},
27 {`export\s+`, Keyword, nil},
28 {`([\w${}().-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n)+|.*\n)`, ByGroups(NameVariable, Text, Operator, Text, Using("Bash")), nil},
29 {`(?s)"(\\\\|\\.|[^"\\])*"`, LiteralStringDouble, nil},
30 {`(?s)'(\\\\|\\.|[^'\\])*'`, LiteralStringSingle, nil},
31 {`([^\n:]+)(:+)([ \t]*)`, ByGroups(NameFunction, Operator, Text), Push("block-header")},
32 {`\$\(`, Keyword, Push("expansion")},
33 },
34 "expansion": {
35 {`[^$a-zA-Z_()]+`, Text, nil},
36 {`[a-zA-Z_]+`, NameVariable, nil},
37 {`\$`, Keyword, nil},
38 {`\(`, Keyword, Push()},
39 {`\)`, Keyword, Pop(1)},
40 },
41 "export": {
42 {`[\w${}-]+`, NameVariable, nil},
43 {`\n`, Text, Pop(1)},
44 {`\s+`, Text, nil},
45 },
46 "block-header": {
47 {`[,|]`, Punctuation, nil},
48 {`#.*?\n`, Comment, Pop(1)},
49 {`\\\n`, Text, nil},
50 {`\$\(`, Keyword, Push("expansion")},
51 {`[a-zA-Z_]+`, Name, nil},
52 {`\n`, Text, Pop(1)},
53 {`.`, Text, nil},
54 },
55 }
56 }
57
View as plain text