...

Source file src/github.com/alecthomas/chroma/lexers/m/make.go

Documentation: github.com/alecthomas/chroma/lexers/m

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

View as plain text