jsonnet-docblock-parser

Simple, powerfull jsonnet docblock parser that returns a JSON representation to work with.


Keywords
jsonnet, docblock, json, parser
License
MIT
Install
pip install jsonnet-docblock-parser==0.1.3

Documentation

Jsonnet Docblock Parser

JDP is a simple, powerfull jsonnet docblock parser that returns a JSON representation to work with.

Build Status PyPI status PyPI version shields.io PyPI license PyPI pyversions

This parser will extract docblocks from your .jsonnet or .libsonnet files. This package includes a generator that allows you to output the parsed information into JSON format.

The parser assumes that the documentation inside these files is written in a syntax that is similar to JavaScript, Java and many C++ scripts:

{
  /**
   * Returns whether the string a is prefixed by the string b.
   *
   * @param a The input string.
   * @param b The prefix.
   * @return true if string a is prefixed by the string b or false otherwise.
   */
  startsWith(a, b):
    if std.length(a) < std.length(b) then
      false
    else
      std.substr(a, 0, std.length(b)) == b,
}

Installation

You can install the tool via pip:

pip install jsonnet-docblock-parser

Module Usage

#!/usr/bin/env python
# encoding: utf-8

from jsonnet_docblock_parser import parseFile, Generator

# Load a jsonnet or libsonnet file.
TEST_FILE = "some.jsonnet"

# Parse the file.
docblocks = parseFile(TEST_FILE)

# Load the generator.
generator = Generator()

# Parse Json based on the results.
json = generator.parse_json(results)

# Print the json
print(json)

CLI Usage

jdp --file some.jsonnet

Development

Testing

pytest

PyLint

pylint jsonnet_docblock_parser

Deploying to PyPi

python3 setup.py sdist
twine upload dist/*

License

The MIT License (MIT). Please see License File for more information.