YANG Compiler provides necessary tooling to enable runtime JavaScript execution based on YANG schema modeling language as defined in IETF drafts and standards (RFC 6020).
It is written primarily using CoffeeScript and runs on node.
- Parse YANG schema files and generate runtime JavaScript meta-class semantic tree hierarchy
- Import/Export capabilities to load modules using customizable importers based on regular expressions and custom import routines. Ability to serialize module meta data into JSON format that is portable across systems. Also exports serialized JS functions as part of export meta data.
- Runtime Generation allows compiler to directly create a live JS
class object definition so that it can be instantiated via
new
keyword and used immediately - Dynamic Extensions enable compiler to be configured with
alternative
resolver
functions to change the behavior of produced output
The yang-compiler itself is also a YANG
schema (yang-compiler.yang) compiled
module. It is compiled by the
yang-meta-compiler and dynamically
include
yang-v1-extensions.yang schema
for supporting the version 1.0 YANG RFC specifications. It serves as a
good reference for writing new compilers, custom extensions, custom
importers, among other things.
$ npm install yang-compiler
YangCompiler = require 'yang-compiler'
compiler = new YangCompiler
schema = """
module test {
description 'hello';
leaf works { type string; }
}
"""
Test = compiler.compile schema
test = new Test
test.set 'works', 'very well'
test.get 'works'
The below examples can be executed using CoffeeScript REPL by running
coffee
at the command-line from the top-directory of this repo.
- Importing a local YANG schema file (such as importing itself...)
yc = compiler.import source: 'schema:./yang-compiler.yang'
- Exporting a known YANG module into JSON
json = compiler.export name: 'yang-compiler'
- Importing from serialized JSON export
A = compiler.import json
- Instantiating a newly imported module with configurations
hello = new A map: 'foo': 'schema:./yang-compiler.yang'
- Various operations to get/set different configurations
hello.get()
hello.get 'map'
hello.set 'map', bar: 'whatever'
hello.get 'map.bar'
hello.set 'map.bar', 'good bye'
hello.get 'map'
There are many other ways of interacting with the module's class
object as well as the instantiated class. Please refer to the
meta-class
for additional information.
The source code is documented in Markdown format. It's code combined with documentation all-in-one.