Skip to content

A YANG module/compiler which parses YANG text schema into JS class hierarchy for fun and profit

License

Notifications You must be signed in to change notification settings

OnVelocity/yang-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ba1ba65 · Jun 4, 2015

History

47 Commits
Jun 4, 2015
Jun 4, 2015
May 6, 2015
Feb 26, 2015
Feb 24, 2015
Jun 4, 2015
Jun 4, 2015
May 28, 2015
May 16, 2015

Repository files navigation

YANG Compiler

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.

NPM Version NPM Downloads

Key Features

  • 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.

Installation

$ npm install yang-compiler

Quick Example

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'

Common Usage Examples

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.

Literate CoffeeScript Documentation

The source code is documented in Markdown format. It's code combined with documentation all-in-one.

External Dependencies

License

MIT

About

A YANG module/compiler which parses YANG text schema into JS class hierarchy for fun and profit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published