...

Source file src/github.com/alecthomas/chroma/lexers/z/zed.go

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

     1  package z
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "github.com/alecthomas/chroma" // nolint
     7  	"github.com/alecthomas/chroma/lexers/internal"
     8  )
     9  
    10  // Zed lexer.
    11  var Zed = internal.Register(MustNewLazyLexer(
    12  	&Config{
    13  		Name:      "Zed",
    14  		Aliases:   []string{"zed"},
    15  		Filenames: []string{"*.zed"},
    16  		MimeTypes: []string{"text/zed"},
    17  	},
    18  	zedRules,
    19  ).SetAnalyser(func(text string) float32 {
    20  	if strings.Contains(text, "definition ") && strings.Contains(text, "relation ") && strings.Contains(text, "permission ") {
    21  		return 0.9
    22  	}
    23  	if strings.Contains(text, "definition ") {
    24  		return 0.5
    25  	}
    26  	if strings.Contains(text, "relation ") {
    27  		return 0.5
    28  	}
    29  	if strings.Contains(text, "permission ") {
    30  		return 0.25
    31  	}
    32  	return 0.0
    33  }))
    34  
    35  func zedRules() Rules {
    36  	return Rules{
    37  		"root": {
    38  			{`\n`, TextWhitespace, nil},
    39  			{`\s+`, TextWhitespace, nil},
    40  			{`//.*?\n`, CommentSingle, nil},
    41  			{`/(\\\n)?[*][\w\W]*?[*](\\\n)?/`, CommentMultiline, nil},
    42  			{`/(\\\n)?[*][\w\W]*`, CommentMultiline, nil},
    43  			{Words(``, `\b`, `definition`), KeywordType, nil},
    44  			{Words(``, `\b`, `relation`), KeywordNamespace, nil},
    45  			{Words(``, `\b`, `permission`), KeywordDeclaration, nil},
    46  			{`[a-zA-Z_]\w*/`, NameNamespace, nil},
    47  			{`[a-zA-Z_]\w*`, Name, nil},
    48  			{`#[a-zA-Z_]\w*`, NameVariable, nil},
    49  			{`[+%=><|^!?/\-*&~:]`, Operator, nil},
    50  			{`[{}()\[\],.;]`, Punctuation, nil},
    51  		},
    52  	}
    53  }
    54  

View as plain text