...

Source file src/github.com/alecthomas/chroma/lexers/n/nginx.go

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

     1  package n
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Nginx Configuration File lexer.
     9  var Nginx = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Nginx configuration file",
    12  		Aliases:   []string{"nginx"},
    13  		Filenames: []string{"nginx.conf"},
    14  		MimeTypes: []string{"text/x-nginx-conf"},
    15  	},
    16  	nginxRules,
    17  ))
    18  
    19  func nginxRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`(include)(\s+)([^\s;]+)`, ByGroups(Keyword, Text, Name), nil},
    23  			{`[^\s;#]+`, Keyword, Push("stmt")},
    24  			Include("base"),
    25  		},
    26  		"block": {
    27  			{`\}`, Punctuation, Pop(2)},
    28  			{`[^\s;#]+`, KeywordNamespace, Push("stmt")},
    29  			Include("base"),
    30  		},
    31  		"stmt": {
    32  			{`\{`, Punctuation, Push("block")},
    33  			{`;`, Punctuation, Pop(1)},
    34  			Include("base"),
    35  		},
    36  		"base": {
    37  			{`#.*\n`, CommentSingle, nil},
    38  			{`on|off`, NameConstant, nil},
    39  			{`\$[^\s;#()]+`, NameVariable, nil},
    40  			{`([a-z0-9.-]+)(:)([0-9]+)`, ByGroups(Name, Punctuation, LiteralNumberInteger), nil},
    41  			{`[a-z-]+/[a-z-+]+`, LiteralString, nil},
    42  			{`[0-9]+[km]?\b`, LiteralNumberInteger, nil},
    43  			{`(~)(\s*)([^\s{]+)`, ByGroups(Punctuation, Text, LiteralStringRegex), nil},
    44  			{`[:=~]`, Punctuation, nil},
    45  			{`[^\s;#{}$]+`, LiteralString, nil},
    46  			{`/[^\s;#]*`, Name, nil},
    47  			{`\s+`, Text, nil},
    48  			{`[$;]`, Text, nil},
    49  		},
    50  	}
    51  }
    52  

View as plain text