PETAR is a DSL used to produce annotated representation from tree-like data.
This document explains how to use the CLI for the java interpreter.
This tool is distributed as a JAR file and is executed via java -jar.
If you want to understand more about the Petar language go to the Petar language specification.
- Java 17+ recommended
- A valid PETAR
.jarfile
java -jar petar.jar --spec <spec-files> -r <root type> [options]At minimum, you must provide at least one specification file using --spec or -s.
Provide one or more specification files.
-s file1.petar file2.petar
--spec file1.petar file2.petar
- Type:
List<File> - Required: ✅ Yes
Root type to use for interpretation. This defines the entry point type used when interpreting the input tree.
-r Expression
- Type:
String - Required: ✅ Yes
Input file to process.
-i input.json
- Type:
File
If this is not specified the interpreter will parse and check the specification files provided. This can be used to typecheck or namecheck Petar programs indecently from data.
Output file for results.
-o output.json
- Type:
File
If omitted, output will be printed to standard output.
Print the loaded specification.
-p
- Type:
Boolean - Default:
false
Useful for debugging and verifying that your .petar specification files are correctly loaded.
Displays help information about available commands.
--help
- Type:
Boolean - Default:
false
When enabled, the program will print usage information and exit.
java -jar petar.jar \
--spec rules.petar \
-i input.json \
-o output.json \
-r Expressionjava -jar petar.jar \
--spec base.petar transformations.petar \
-i input.json \
-o output.jsonjava -jar petar.jar \
--spec rules.petar \
-pjava -jar petar.jar \
--spec rules.petar \
-i input.jsonWhen executed, PETAR performs the following steps:
- Loads all specification files (
--spec) and check it - Parses the input tree (
-i) and check the root type (-r) - Applies pattern matching rules
- Generates annotations via production rules
- Writes results to output (
-o) or stdout
- Multiple
--specfiles are merged into a single rule set. - The order of specification files should not the output.
- If no
-ois provided, output defaults to standard output.
Run:
java -jar petar.jar --helpfor built-in usage information.