Skip to content

Commit

Permalink
Added support for YANG (#2467)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Jul 22, 2020
1 parent 447429f commit ed1df1e
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -1212,6 +1212,10 @@
"alias": "yml",
"owner": "hason"
},
"yang": {
"title": "YANG",
"owner": "RunDevelopment"
},
"zig": {
"title": "Zig",
"owner": "RunDevelopment"
Expand Down
20 changes: 20 additions & 0 deletions components/prism-yang.js
@@ -0,0 +1,20 @@
Prism.languages.yang = {
// https://tools.ietf.org/html/rfc6020#page-34
// http://www.yang-central.org/twiki/bin/view/Main/YangExamples
'comment': /\/\*[\s\S]*?\*\/|\/\/.*/,
'string': {
pattern: /"(?:[^\\"]|\\.)*"|'[^']*'/,
greedy: true
},
'keyword': {
pattern: /(^|[{};\r\n][ \t]*)[a-z_][\w.-]*/i,
lookbehind: true
},
'namespace': {
pattern: /(\s)[a-z_][\w.-]*(?=:)/i,
lookbehind: true
},
'boolean': /\b(?:false|true)\b/,
'operator': /\+/,
'punctuation': /[{};:]/
};
1 change: 1 addition & 0 deletions components/prism-yang.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions examples/prism-yang.html
@@ -0,0 +1,50 @@
<h2>Full example</h2>
<p><a href="http://www.yang-central.org/twiki/bin/view/Main/YangExamplesExecdDns">Source</a></p>
<pre><code>submodule execd-dns {

belongs-to execd { prefix execd; }

import inet-types { prefix inet; }

include execd-types;

description
"The 'dns' component provides support for configuring the DNS resolver.

The 'domain' keyword of /etc/resolv.conf is not supported, since
it is equivalent to 'search' with a single domain. I.e. in terms
of the data model, the domains are always configured as 'search'
elements, even if there is only one. The set of available options
has been limited to those that are generally available across
different resolver implementations, and generally useful.";

revision "2008-11-04" {
description "draft-ietf-netmod-yang-02 compatible.";
}
revision "2007-08-29" {
description "Syntax fixes after pyang validation.";
}
revision "2007-06-08" {
description "Initial revision.";
}

grouping dns {
list search {
key name;
max-elements 3;
leaf name { type int32; }
leaf domain { type inet:host; }
}
list server {
key address;
max-elements 3;
ordered-by user;
leaf address { type inet:ip-address; }
}
container options {
leaf ndots { type uint8; }
leaf timeout { type uint8; }
leaf attempts { type uint8; }
}
}
}</code></pre>
3 changes: 2 additions & 1 deletion plugins/show-language/prism-show-language.js
Expand Up @@ -195,7 +195,8 @@
"xojo": "Xojo (REALbasic)",
"xquery": "XQuery",
"yaml": "YAML",
"yml": "YAML"
"yml": "YAML",
"yang": "YANG"
}/*]*/;

Prism.plugins.toolbar.registerButton('show-language', function (env) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/languages/yang/boolean_feature.test
@@ -0,0 +1,13 @@
true
false

----------------------------------------------------

[
["keyword", "true"],
["keyword", "false"]
]

----------------------------------------------------

Checks for booleans.
15 changes: 15 additions & 0 deletions tests/languages/yang/comment_feature.test
@@ -0,0 +1,15 @@
// comment
/*
comment
*/

----------------------------------------------------

[
["comment", "// comment"],
["comment", "/*\n comment\n*/"]
]

----------------------------------------------------

Checks for comments.
53 changes: 53 additions & 0 deletions tests/languages/yang/keyword_feature.test
@@ -0,0 +1,53 @@
submodule execd-ntp {

key name;

leaf stratum { type ntpStratum; default 10; }

leaf version { type int8 { range "1..4"; } default 4; }

}

----------------------------------------------------

[
["keyword", "submodule"],
" execd-ntp ",
["punctuation", "{"],

["keyword", "key"],
" name",
["punctuation", ";"],

["keyword", "leaf"],
" stratum ",
["punctuation", "{"],
["keyword", "type"],
" ntpStratum",
["punctuation", ";"],
["keyword", "default"],
" 10",
["punctuation", ";"],
["punctuation", "}"],

["keyword", "leaf"],
" version ",
["punctuation", "{"],
["keyword", "type"],
" int8 ",
["punctuation", "{"],
["keyword", "range"],
["string", "\"1..4\""],
["punctuation", ";"],
["punctuation", "}"],
["keyword", "default"],
" 4",
["punctuation", ";"],
["punctuation", "}"],

["punctuation", "}"]
]

----------------------------------------------------

Checks for keywords.
19 changes: 19 additions & 0 deletions tests/languages/yang/namespace_feature.test
@@ -0,0 +1,19 @@
type foo:type
type _foo.-bar:type

----------------------------------------------------

[
["keyword", "type"],
["namespace", "foo"],
["punctuation", ":"],
"type\n",
["keyword", "type"],
["namespace", "_foo.-bar"],
["punctuation", ":"],
"type"
]

----------------------------------------------------

Checks for namespace prefixes.
19 changes: 19 additions & 0 deletions tests/languages/yang/string_feature.test
@@ -0,0 +1,19 @@
"

\"'foo'\"

"
'fo
""
o'

----------------------------------------------------

[
["string", "\"\n\n\\\"'foo'\\\"\n\n\""],
["string", "'fo\n\"\"\no'"]
]

----------------------------------------------------

Checks for string.

0 comments on commit ed1df1e

Please sign in to comment.