1 package y
2
3 import (
4 . "github.com/alecthomas/chroma"
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
32 {`(?:^|(?<=[\s{};]))([\w.-]+)(:)([\w.-]+)(?=[\s{};])`, ByGroups(KeywordNamespace, Punctuation, Text), nil},
33
34
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
40 {Words(``, `(?=[^\w\-\:])`, `module`, `submodule`), Keyword, nil},
41
42 {Words(``, `(?=[^\w\-\:])`, `belongs-to`, `namespace`, `prefix`, `yang-version`), Keyword, nil},
43
44 {Words(``, `(?=[^\w\-\:])`, `contact`, `description`, `organization`, `reference`, `revision`), Keyword, nil},
45
46 {Words(``, `(?=[^\w\-\:])`, `import`, `include`, `revision-date`), Keyword, nil},
47
48 {Words(``, `(?=[^\w\-\:])`, `action`, `argument`, `augment`, `deviation`, `extension`, `feature`, `grouping`, `identity`, `if-feature`, `input`, `notification`, `output`, `rpc`, `typedef`), Keyword, nil},
49
50 {Words(``, `(?=[^\w\-\:])`, `anydata`, `anyxml`, `case`, `choice`, `config`, `container`, `deviate`, `leaf`, `leaf-list`, `list`, `must`, `presence`, `refine`, `uses`, `when`), Keyword, nil},
51
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
54 {Words(``, `(?=[^\w\-\:])`, `key`, `mandatory`, `unique`), Keyword, nil},
55
56
57 {Words(``, `(?=[^\w\-\:])`, `add`, `current`, `delete`, `deprecated`, `false`, `invert-match`, `max`, `min`, `not-supported`, `obsolete`, `replace`, `true`, `unbounded`, `user`), NameClass, nil},
58
59
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