Skip to content

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

License

Notifications You must be signed in to change notification settings

legovaer/jsonnet-docblock-parser

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published