I'm looking for a tool, preferrably with a FLOSS license, which can do something like the following:
thetool --template mytemplate.c.someformat --data mydata.json --schema myschema.json --out myoutput.c
where thetool
is the executable tool I'm looking for, mytemplate.c.someformat
is my template file looking like a C file but with template style markup for data replacement, mydata.json
contains data for populating the template, myschema.json
is a schema explaining connections between data elements (nice to have, but not strictly mandatory) and myoutput.c
is the generated C file.
Is there such a tool out there? Native json support is a key here, where error messages can highlight problematic areas in the json source. Xml is not an option. It does not need to have explicit support for C. It must be able to generate files in generic ASCII/UTF-8 format.
It must be able to run as a command line tool on both Windows and GNU/Linux. Also good if it can be linked as a library from python or C.
Example
syntax has not been verified, as I need the tool to do it.
mytemplate.c.someformat
#include <stdio.h>
int main(void) {
#{{ for person in persons }}
#{{ if person.likes.length > 0 }}
printf("#{{ person.name }} likes:\n");
#{{ for liked in person.likes }}
printf(" * #{{ likes.name }}\n");
#{{ endfor }}
#{{ else }}
printf("#{{ person.name }} doesn't like anyone.");
#{{ endif }}
printf("\n");
#{{ endfor }}
return(0);
}
mydata.json
{
"persons": {
{
"id": "10",
"name": "Mr Mister",
"likes": {
"20",
"22"
}
},
{
"id": "20",
"name": "Ms Missy",
"likes": {
"10",
}
},
{
"id": "22",
"name": "No Body",
"likes":
{}
}
},
"schema": "personSchema"
}
myschema.json
{
"personSchema": {
{
"id": {
"type": "integer",
"attrib": "unique"
}
"name": {
"type": "string"
}
"likes":
{
"type": "integer",
"connection": "personSchema.id"
}
}
}
}
myoutput.c
#include <stdio.h>
int main(void) {
printf("Mr Mister likes:\n");
printf(" * Ms Missy\n");
printf(" * No Body\n");
printf("\n");
printf("Ms Missy likes:\n");
printf(" * Mr Mister\n");
printf("\n");
printf("No Body doesn't like anyone.");
printf("\n");
return(0);
}