...

Source file src/github.com/alecthomas/chroma/lexers/t/tablegen.go

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

     1  package t
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // TableGen lexer.
     9  var Tablegen = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "TableGen",
    12  		Aliases:   []string{"tablegen"},
    13  		Filenames: []string{"*.td"},
    14  		MimeTypes: []string{"text/x-tablegen"},
    15  	},
    16  	tablegenRules,
    17  ))
    18  
    19  func tablegenRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			Include("macro"),
    23  			Include("whitespace"),
    24  			{`c?"[^"]*?"`, LiteralString, nil},
    25  			Include("keyword"),
    26  			{`\$[_a-zA-Z][_\w]*`, NameVariable, nil},
    27  			{`\d*[_a-zA-Z][_\w]*`, NameVariable, nil},
    28  			{`\[\{[\w\W]*?\}\]`, LiteralString, nil},
    29  			{`[+-]?\d+|0x[\da-fA-F]+|0b[01]+`, LiteralNumber, nil},
    30  			{`[=<>{}\[\]()*.,!:;]`, Punctuation, nil},
    31  		},
    32  		"macro": {
    33  			{`(#include\s+)("[^"]*")`, ByGroups(CommentPreproc, LiteralString), nil},
    34  			{`^\s*#(ifdef|ifndef)\s+[_\w][_\w\d]*`, CommentPreproc, nil},
    35  			{`^\s*#define\s+[_\w][_\w\d]*`, CommentPreproc, nil},
    36  			{`^\s*#endif`, CommentPreproc, nil},
    37  		},
    38  		"whitespace": {
    39  			{`(\n|\s)+`, Text, nil},
    40  			{`//.*?\n`, Comment, nil},
    41  		},
    42  		"keyword": {
    43  			{Words(``, `\b`, `bit`, `bits`, `class`, `code`, `dag`, `def`, `defm`, `field`, `foreach`, `in`, `int`, `let`, `list`, `multiclass`, `string`), Keyword, nil},
    44  		},
    45  	}
    46  }
    47  

View as plain text