2020-05-09 22:49:03 +02:00
|
|
|
package y
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
|
|
)
|
|
|
|
|
2021-08-04 20:11:59 +02:00
|
|
|
var YANG = internal.Register(MustNewLazyLexer(
|
2020-05-09 22:49:03 +02:00
|
|
|
&Config{
|
|
|
|
Name: "YANG",
|
|
|
|
Aliases: []string{"yang"},
|
|
|
|
Filenames: []string{"*.yang"},
|
|
|
|
MimeTypes: []string{"application/yang"},
|
|
|
|
},
|
2021-08-04 20:11:59 +02:00
|
|
|
yangRules,
|
|
|
|
))
|
|
|
|
|
|
|
|
func yangRules() Rules {
|
|
|
|
return Rules{
|
2020-05-09 22:49:03 +02:00
|
|
|
"root": {
|
|
|
|
{`\s+`, Whitespace, nil},
|
|
|
|
{`[\{\}\;]+`, Punctuation, nil},
|
|
|
|
{`(?<![\-\w])(and|or|not|\+|\.)(?![\-\w])`, Operator, nil},
|
|
|
|
|
|
|
|
{`"(?:\\"|[^"])*?"`, StringDouble, nil},
|
|
|
|
{`'(?:\\'|[^'])*?'`, StringSingle, nil},
|
|
|
|
|
|
|
|
{`/\*`, CommentMultiline, Push("comments")},
|
|
|
|
{`//.*?$`, CommentSingle, nil},
|
|
|
|
|
2021-08-04 20:11:59 +02:00
|
|
|
// match BNF stmt for `node-identifier` with [ prefix ":"]
|
2020-05-09 22:49:03 +02:00
|
|
|
{`(?:^|(?<=[\s{};]))([\w.-]+)(:)([\w.-]+)(?=[\s{};])`, ByGroups(KeywordNamespace, Punctuation, Text), nil},
|
|
|
|
|
2021-08-04 20:11:59 +02:00
|
|
|
// match BNF stmt `date-arg-str`
|
2020-05-09 22:49:03 +02:00
|
|
|
{`([0-9]{4}\-[0-9]{2}\-[0-9]{2})(?=[\s\{\}\;])`, LiteralDate, nil},
|
|
|
|
{`([0-9]+\.[0-9]+)(?=[\s\{\}\;])`, NumberFloat, nil},
|
|
|
|
{`([0-9]+)(?=[\s\{\}\;])`, NumberInteger, nil},
|
|
|
|
|
2021-08-04 20:11:59 +02:00
|
|
|
// TOP_STMTS_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `module`, `submodule`), Keyword, nil},
|
2021-08-04 20:11:59 +02:00
|
|
|
// MODULE_HEADER_STMT_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `belongs-to`, `namespace`, `prefix`, `yang-version`), Keyword, nil},
|
2021-08-04 20:11:59 +02:00
|
|
|
// META_STMT_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `contact`, `description`, `organization`, `reference`, `revision`), Keyword, nil},
|
2021-08-04 20:11:59 +02:00
|
|
|
// LINKAGE_STMTS_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `import`, `include`, `revision-date`), Keyword, nil},
|
2021-08-04 20:11:59 +02:00
|
|
|
// BODY_STMT_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `action`, `argument`, `augment`, `deviation`, `extension`, `feature`, `grouping`, `identity`, `if-feature`, `input`, `notification`, `output`, `rpc`, `typedef`), Keyword, nil},
|
2021-08-04 20:11:59 +02:00
|
|
|
// DATA_DEF_STMT_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `anydata`, `anyxml`, `case`, `choice`, `config`, `container`, `deviate`, `leaf`, `leaf-list`, `list`, `must`, `presence`, `refine`, `uses`, `when`), Keyword, nil},
|
2021-08-04 20:11:59 +02:00
|
|
|
// TYPE_STMT_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{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},
|
2021-08-04 20:11:59 +02:00
|
|
|
// LIST_STMT_KEYWORDS
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `key`, `mandatory`, `unique`), Keyword, nil},
|
|
|
|
|
2021-08-04 20:11:59 +02:00
|
|
|
// CONSTANTS_KEYWORDS - RFC7950 other keywords
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `add`, `current`, `delete`, `deprecated`, `false`, `invert-match`, `max`, `min`, `not-supported`, `obsolete`, `replace`, `true`, `unbounded`, `user`), NameClass, nil},
|
|
|
|
|
2021-08-04 20:11:59 +02:00
|
|
|
// RFC7950 Built-In Types
|
2020-05-09 22:49:03 +02:00
|
|
|
{Words(``, `(?=[^\w\-\:])`, `binary`, `bits`, `boolean`, `decimal64`, `empty`, `enumeration`, `identityref`, `instance-identifier`, `int16`, `int32`, `int64`, `int8`, `leafref`, `string`, `uint16`, `uint32`, `uint64`, `uint8`, `union`), NameClass, nil},
|
|
|
|
|
|
|
|
{`[^;{}\s\'\"]+`, Text, nil},
|
|
|
|
},
|
|
|
|
"comments": {
|
|
|
|
{`[^*/]`, CommentMultiline, nil},
|
|
|
|
{`/\*`, CommentMultiline, Push("comment")},
|
|
|
|
{`\*/`, CommentMultiline, Pop(1)},
|
|
|
|
{`[*/]`, CommentMultiline, nil},
|
|
|
|
},
|
2021-08-04 20:11:59 +02:00
|
|
|
}
|
|
|
|
}
|