JDP is a simple, powerfull jsonnet docblock parser that returns a JSON representation to work with.
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,
}
You can install the tool via pip:
pip install jsonnet-docblock-parser
#!/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)
jdp --file some.jsonnet
pytest
pylint jsonnet_docblock_parser
python3 setup.py sdist
twine upload dist/*
The MIT License (MIT). Please see License File for more information.