File: make.go

package info (click to toggle)
golang-github-alecthomas-chroma-v2 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 7,980 kB
  • sloc: xml: 33,149; python: 589; javascript: 357; makefile: 36; sh: 36
file content (56 lines) | stat: -rw-r--r-- 1,623 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package lexers

import (
	. "github.com/alecthomas/chroma/v2" // nolint
)

// Makefile lexer.
var Makefile = Register(MustNewLexer(
	&Config{
		Name:      "Makefile",
		Aliases:   []string{"make", "makefile", "mf", "bsdmake"},
		Filenames: []string{"*.mak", "*.mk", "Makefile", "makefile", "Makefile.*", "GNUmakefile", "BSDmakefile"},
		MimeTypes: []string{"text/x-makefile"},
		EnsureNL:  true,
	},
	makefileRules,
))

func makefileRules() Rules {
	return Rules{
		"root": {
			{`^(?:[\t ]+.*\n|\n)+`, Using("Bash"), nil},
			{`\$[<@$+%?|*]`, Keyword, nil},
			{`\s+`, Text, nil},
			{`#.*?\n`, Comment, nil},
			{`(export)(\s+)(?=[\w${}\t -]+\n)`, ByGroups(Keyword, Text), Push("export")},
			{`export\s+`, Keyword, nil},
			{`([\w${}().-]+)(\s*)([!?:+]?=)([ \t]*)((?:.*\\\n)+|.*\n)`, ByGroups(NameVariable, Text, Operator, Text, Using("Bash")), nil},
			{`(?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},
		},
	}
}