...

Source file src/github.com/alecthomas/chroma/lexers/y/yang.go

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

     1  package y
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  var YANG = internal.Register(MustNewLazyLexer(
     9  	&Config{
    10  		Name:      "YANG",
    11  		Aliases:   []string{"yang"},
    12  		Filenames: []string{"*.yang"},
    13  		MimeTypes: []string{"application/yang"},
    14  	},
    15  	yangRules,
    16  ))
    17  
    18  func yangRules() Rules {
    19  	return Rules{
    20  		"root": {
    21  			{`\s+`, Whitespace, nil},
    22  			{`[\{\}\;]+`, Punctuation, nil},
    23  			{`(?<![\-\w])(and|or|not|\+|\.)(?![\-\w])`, Operator, nil},
    24  
    25  			{`"(?:\\"|[^"])*?"`, StringDouble, nil},
    26  			{`'(?:\\'|[^'])*?'`, StringSingle, nil},
    27  
    28  			{`/\*`, CommentMultiline, Push("comments")},
    29  			{`//.*?$`, CommentSingle, nil},
    30  
    31  			// match BNF stmt for `node-identifier` with [ prefix ":"]
    32  			{`(?:^|(?<=[\s{};]))([\w.-]+)(:)([\w.-]+)(?=[\s{};])`, ByGroups(KeywordNamespace, Punctuation, Text), nil},
    33  
    34  			// match BNF stmt `date-arg-str`
    35  			{`([0-9]{4}\-[0-9]{2}\-[0-9]{2})(?=[\s\{\}\;])`, LiteralDate, nil},
    36  			{`([0-9]+\.[0-9]+)(?=[\s\{\}\;])`, NumberFloat, nil},
    37  			{`([0-9]+)(?=[\s\{\}\;])`, NumberInteger, nil},
    38  
    39  			// TOP_STMTS_KEYWORDS
    40  			{Words(``, `(?=[^\w\-\:])`, `module`, `submodule`), Keyword, nil},
    41  			// MODULE_HEADER_STMT_KEYWORDS
    42  			{Words(``, `(?=[^\w\-\:])`, `belongs-to`, `namespace`, `prefix`, `yang-version`), Keyword, nil},
    43  			// META_STMT_KEYWORDS
    44  			{Words(``, `(?=[^\w\-\:])`, `contact`, `description`, `organization`, `reference`, `revision`), Keyword, nil},
    45  			// LINKAGE_STMTS_KEYWORDS
    46  			{Words(``, `(?=[^\w\-\:])`, `import`, `include`, `revision-date`), Keyword, nil},
    47  			// BODY_STMT_KEYWORDS
    48  			{Words(``, `(?=[^\w\-\:])`, `action`, `argument`, `augment`, `deviation`, `extension`, `feature`, `grouping`, `identity`, `if-feature`, `input`, `notification`, `output`, `rpc`, `typedef`), Keyword, nil},
    49  			// DATA_DEF_STMT_KEYWORDS
    50  			{Words(``, `(?=[^\w\-\:])`, `anydata`, `anyxml`, `case`, `choice`, `config`, `container`, `deviate`, `leaf`, `leaf-list`, `list`, `must`, `presence`, `refine`, `uses`, `when`), Keyword, nil},
    51  			// TYPE_STMT_KEYWORDS
    52  			{Words(``, `(?=[^\w\-\:])`, `base`, `bit`, `default`, `enum`, `error-app-tag`, `error-message`, `fraction-digits`, `length`, `max-elements`, `min-elements`, `modifier`, `ordered-by`, `path`, `pattern`, `position`, `range`, `require-instance`, `status`, `type`, `units`, `value`, `yin-element`), Keyword, nil},
    53  			// LIST_STMT_KEYWORDS
    54  			{Words(``, `(?=[^\w\-\:])`, `key`, `mandatory`, `unique`), Keyword, nil},
    55  
    56  			// CONSTANTS_KEYWORDS - RFC7950 other keywords
    57  			{Words(``, `(?=[^\w\-\:])`, `add`, `current`, `delete`, `deprecated`, `false`, `invert-match`, `max`, `min`, `not-supported`, `obsolete`, `replace`, `true`, `unbounded`, `user`), NameClass, nil},
    58  
    59  			// RFC7950 Built-In Types
    60  			{Words(``, `(?=[^\w\-\:])`, `binary`, `bits`, `boolean`, `decimal64`, `empty`, `enumeration`, `identityref`, `instance-identifier`, `int16`, `int32`, `int64`, `int8`, `leafref`, `string`, `uint16`, `uint32`, `uint64`, `uint8`, `union`), NameClass, nil},
    61  
    62  			{`[^;{}\s\'\"]+`, Text, nil},
    63  		},
    64  		"comments": {
    65  			{`[^*/]`, CommentMultiline, nil},
    66  			{`/\*`, CommentMultiline, Push("comment")},
    67  			{`\*/`, CommentMultiline, Pop(1)},
    68  			{`[*/]`, CommentMultiline, nil},
    69  		},
    70  	}
    71  }
    72  

View as plain text