YANG parser and compiler to produce Go language objects

Go Coverage Status

Current support for goyang is for the latest 3 Go releases.

goyang

YANG parser and compiler for Go programs.

The yang package (pkg/yang) is used to convert a YANG schema into either an in memory abstract syntax trees (ast) or more fully resolved, in memory, "Entry" trees. An Entry tree consists only of Entry structures and has had augmentation, imports, and includes all applied.

goyang is a sample program that uses the yang (pkg/yang) package.

goyang uses the yang package to create an in-memory tree representation of schemas defined in YANG and then dumps out the contents in several forms. The forms include:

  • tree - a simple tree representation
  • types - list understood types extracted from the schema

The yang package, and the goyang program, are not complete and are a work in progress.

For more complex output types, such as Go structs, and protobuf messages please use the openconfig/ygot package, which uses this package as its backend.

Getting started

To build goyang, ensure you have go language tools installed (available at golang.org) and that the GOPATH environment variable is set to your Go workspace.

  1. go get github.com/openconfig/goyang

    • This will download goyang code and dependencies into the src subdirectory in your workspace.
  2. cd <workspace>/src/github.com/openconfig/goyang

  3. go build

    • This will build the goyang binary and place it in the bin subdirectory in your workspace.

Contributing to goyang

goyang is still a work-in-progress and we welcome contributions. Please see the CONTRIBUTING file for information about how to contribute to the codebase.

Disclaimer

This is not an official Google product.

Comments
  • Add support for

    Add support for "if-feature" statements as a child of "bit", "enum", …

    …"identity", and "refine"

    Also add support for notifications to be tied to data nodes.

    See https://tools.ietf.org/html/rfc7950#section-1.1

  • Augment-ed *Entry and Use'd *Entry stored in parent *Entry's new Augmented and Uses fields.

    Augment-ed *Entry and Use'd *Entry stored in parent *Entry's new Augmented and Uses fields.

    This perserves the Augment *Entry and Uses *Entry so their when statements can be enforced, among other things.

    This is my attempt at fixing issue #89

  • 'extensions' are not copied into 'uses''s 'grouping'

    'extensions' are not copied into 'uses''s 'grouping'

    extension keyword is not currently implemented, but extension statements found in YANG files are stored in *yang.Entry.Exts field. ygot can retrieve extension statements from this field and perform further processing.

    However, because uses's grouping are returned as a deep-copy in ToEntry() (https://github.com/openconfig/goyang/blob/master/pkg/yang/entry.go#L584), and that the deep-copying function does not copy the Exts field (https://github.com/openconfig/goyang/blob/master/pkg/yang/entry.go#L1278), extension statements defined within a uses's grouping are effectively lost. This impacts downstream ygot and protogen usage.

    The comment at https://github.com/openconfig/goyang/blob/master/pkg/yang/entry.go#L1281 said there wasn't a clear use case of copying the Ext field, but I believe we do now.

    What's your opinion on this matter?

  • Adding Extras to JSON - fixes #211

    Adding Extras to JSON - fixes #211

    In this Patch I'm doing 2 things

    1. Removing the exclusion of Extras from JSON, and excluding down the line the Parent and Source of Extra elements

    2. Improving how items are added to the Extras slice. When the item is a Slice add its elements individually.

    I can break this up in to 2 separate patches if necessary

  • issues with resolving import-by-revision statements

    issues with resolving import-by-revision statements

    Hi @robshakir @wenovus,

    I am struggling to make goyang parse the modules which have import statements with a specified revision.

    To keep things real, lets take an example of Juniper yang modules, which come in the form of YANG files with [email protected] pattern - https://github.com/Juniper/yang/tree/master/20.2/20.2R1/junos/conf

    1. If the module imports another module with a specified revision (example)
      import junos-common-types {
       prefix jt;
       revision-date 2019-01-01;
      }
      

      the goyang doesn't seem to use the specified revision when it tries processes the imports. Instead it uses the "bare" name. In the linked code snippet name is the bare module name, without revision suffix.

    2. this results in ms.Read to operate on junos-common-types instead of junos-common-types@2019-01-01 name.
    3. The ms.Read in its turn uses findFile that promises to pick the latest revision found, which is not what the import statement wanted.

    Shoudn't we instead read the module by revision by doing:

    	// Try to read it in.
    	if err := ms.Read(rev); err != nil {
    		return nil
    	}
    
  • releases builds and semantic versioning

    releases builds and semantic versioning

    Hi team, thank you all for making goyang a reality.

    I would like to know if the maintainers are up to adopt the semantic versioning for goyang? I think the common benefits of a versioned package are well-known. Aside from the common versioning benefits the adoption will also make it possible to create an automatic release pipeline powered by goreleaser and github actions (like we did for gnmic).

    Having pre-built goyang binaries ready available and downloadable (via github releases) will help users to leverage one of the best yang compilers out there. I am willing to contribute the release pipeline if the OC community is up for maintaining the versioning.

  • Add support for the 'reference' statement under import.

    Add support for the 'reference' statement under import.

    This change adds support for the YANG 1.1 construct:

    import foo {
      prefix "bar";
      reference "bat";
    }
    

    to goyang. The test added provides an extensible way to add tests for the contents of opaque Node structures to the goyang pkg.

  • Flag-control whether new 'Uses' field is populated.

    Flag-control whether new 'Uses' field is populated.

     * (M) pkg/yang/{entry,entry_test,options}.go
      - Control whether Uses is populated based on an input flag. With
        large sets of schemas, the Uses data can cause a significant increase
        in the output size of the Entry data - which has memory footprint
        implications. Flag control the population of such fields.
    
  • Detect missing closing brace from input

    Detect missing closing brace from input

    Consider the case of the following yang that is missing the final closing brace for module foo

    module foo {
      namespace foo;
      prefix f;
    
      container top {
         leaf f1 {
            type string;
         }
      }
    
    

    parsing that with ./goyang -f tree test.yang results in no error and no output.

    With this patch we output an error that says we are missing a closing brace.

  • panic if the lexer items channel (would) overflow

    panic if the lexer items channel (would) overflow

    To avoid a deadlock when sending a *token to the lexer's items channel - which can occur if too many errors occur within a single token - instead panic when the items channel fills up.

    Non-error items (i.e., normal tokens) should not overflow the channel, so use a different panic message (indicating a library bug) if this occurs.

    Avoids a deadlock and addresses #116 .

  • Memory issue due to github.com/openconfig/goyang/pkg/yang#typeDictionary

    Memory issue due to github.com/openconfig/goyang/pkg/yang#typeDictionary

    Hello,

    I am using your great library while working on an implementation of a library that is parsing yang files and does some processing with them (in relation to this). Recently I realized parsing many models makes my library leak memory. After some debugging I discovered that it should be because of the use of typeDict that is growing with each model parsing. I would be willing to work on resolving this issue, but as I saw that there is already a TODO comment around it, I imagine you already have an idea what would be a good solution for you. The best solution for me would be to have reference to the typeDict in the Modules type, but it seems that some initialization is done for the default types, which would make that more difficult (we can have separate typeDict for the built-in types and the parsed ones). Do you have better ideas and would you be willing to review and possibly merge such a change?

    Thank you in advance!

  • support for yang 1.1 `modifier` pattern substatement

    support for yang 1.1 `modifier` pattern substatement

    Hi all, this issues is a feature request to add support for modifier pattern substatement as per https://datatracker.ietf.org/doc/html/rfc7950#section-9.4.6

  • Cross-Module deviation statement doesn't properly check module prefixes?

    Cross-Module deviation statement doesn't properly check module prefixes?

    Need to write a reproducing YANG file first, but the reported problem is that a deviation without the proper prefix for an element in the path still compiles but shouldn't.

  • allow multiple default substatements for leaf-list types (YANG1.1)

    allow multiple default substatements for leaf-list types (YANG1.1)

    deviate statement and refine statement should allow multiple default substatements for leaf-list types (YANG1.1).

    Some examples at https://github.com/mbj4668/pyang/issues/756

Related tags
Godbolt console wrapper for easily execute local file without any security risk and compiler.

Godbolt CLI Godbolt console wrapper for easily execute local file without any security risk and compiler. Install Compile the source code and add to y

May 22, 2022
Tool to capture C/C++ compiler command lines for use by Sonargraph

ccspy Tool to capture C/C++ compiler command lines for use by Sonargraph-Architect. Purpose of the Tool When Sonargraph analyzes C/C++ code it must kn

Dec 7, 2021
The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine
The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine

The runner project is to create an interface for users to run their code remotely without having to have any compiler on their machine. This is a work in progress project for TCSS 401X :)

May 29, 2022
CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser

CONTRIBUTIONS ONLY What does this mean? I do not have time to fix issues myself. The only way fixes or new features will be added is by people submitt

Dec 29, 2022
Brigodier is a command parser & dispatcher, designed and developed for command lines such as for Discord bots or Minecraft chat commands. It is a complete port from Mojang's "brigadier" into Go.

brigodier Brigodier is a command parser & dispatcher, designed and developed to provide a simple and flexible command framework. It can be used in man

Dec 15, 2022
go command line option parser

go-flags: a go library for parsing command line arguments This library provides similar functionality to the builtin flag library of go, but provides

Jan 4, 2023
Fully featured Go (golang) command line option parser with built-in auto-completion support.

go-getoptions Go option parser inspired on the flexibility of Perl’s GetOpt::Long. Table of Contents Quick overview Examples Simple script Program wit

Dec 14, 2022
Kong is a command-line parser for Go
Kong is a command-line parser for Go

Kong is a command-line parser for Go Introduction Help Help as a user of a Kong application Defining help in Kong Command handling Switch on the comma

Dec 27, 2022
HAProxy configuration parser
HAProxy configuration parser

HAProxy configuration parser autogenerated code if you change types/types.go you need to run go run generate/go-generate.go $(pwd) Contributing For co

Dec 14, 2022
A simple command line time description parser

Zeit Zeit is an extremely simple command line application to read a natural language time description and output it as a timestamp. The main usecase f

Aug 21, 2021
APFS parser written in pure Go

[WIP] go-apfs ?? APFS parser written in pure Go Originally from this ipsw branch Install go get github.com/blacktop/go-apfs apfs cli Install go instal

Dec 24, 2022
A golang tag key value parser

tag_parser A golang tag key value parser Installation go get github.com/gvassili/tag_parser Example package main import ( "fmt" "github.com/gvass

Nov 24, 2021
A Protobuf parser

A Protobuf parser for Go This package contains a cleanroom Protobuf parser for Go using Participle. This was originally an example within Participle.

Nov 9, 2022
Config File Parser

Config File Parser Speed It was Implemented by binary tree and only suitable for small project. Ignore Any line starting with specific prefix will be

May 20, 2022
Golisp-wtf - A lisp interpreter (still just a parser) implementation in golang. You may yell "What the fuck!?.." when you see the shitty code.

R6RS Scheme Lisp dialect interpreter This is an implementation of a subset of R6RS Scheme Lisp dialect in golang. The work is still in progress. At th

Jan 7, 2022
Ghissue - This repo contains a github issue parser, that is useful for Enterprise Github accounts.

Ghissue - This repo contains a github issue parser, that is useful for Enterprise Github accounts. Sometimes is needed to parse the content of the issue for some data extraction or statistics purposes.

Feb 6, 2022
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it

news-parser-cli Simple CLI which allows you to receive news depending on the par

Jan 4, 2022
Golang parser for Intuit Interchange Format (.IIF) files

Intuit Interchange Format (.IIF) Parser Install go get github.com/joshuaslate/iif Usage iiifile, err := os.Open("./transactions.iif") if err != nil {

Jan 15, 2022
minigli is a tiny command argument parser for Go.

minigli is a tiny command argument parser for Go.

Jan 29, 2022