Skip to content

MODLanguage/java-interpreter

Repository files navigation

Minimal Object Description Language (MODL) Interpreter

This Java interpreter is based on the MODL Specification.

There are several ways the interpreter can be used:

  • Using the MODL Playground
  • Writing a Java program
  • Building and running on the command line

Command-line Usage

First clone the repository and build the project using gradle clean customFatJar from the project root directory.

Create a file containing a MODL object, e.g. test.modl with:

a=test;
b=123;
c=Hello World

Run the interpreter using the command:

java -jar ./build/libs/interpreter-<version>.jar test.modl

The result should be:

Processing file: test.modl
{
  "a" : "test",
  "b" : 123,
  "c" : "Hello World"
}
Finished file: test.modl

Multiple file names can be provided if needed, and the value of $? is the number of files that errored, so 0 is success.

Usage In a Java Program

The Interpreter class has several convenience methods, each returning a slightly different result depending on how the result is to be further processed.

JSON String Result

Convert a MODL String to a JSON String:

        final String json = Interpreter.interpretToJsonString("a=b");

Use this method to generate a compact JSON String.

Pretty JSON String Result

Convert a MODL String to a pretty-printed JSON String:

        final String json = Interpreter.interpretToPrettyJsonString("a=b");

Use this method to generate a JSON String for easy reading.

Jackson Core JsonNode Result

Convert a MODL String to a JsonNode:

        final JsonNode jsonNode = Interpreter.interpretToJsonObject("a=b");

Use this method to generate non-proprietary object for further processing.

Modl Object Result

Convert a MODL String to a Modl object:

        final Modl modl = Interpreter.interpret("a=b");

Use this method to generate an object using the core model within the library, i.e. those in the uk.modl.model package.

Other Interpreters

We have a version of the interpreter in Ruby, and a JavaScript version.

Contributing

Bugs and New feature requests should be raised as GitHub issues, and the community is welcome to fork the repository and submit pull requests.