| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Iorgen is a multi languages code generator to parse a predefined input template. The user writes a YAML describing the input, and Iorgen will generate the code to read this input from stdin, in all supported languages.
The list of currently supported languages is: C, C++, C#, D, Go, Haskell, Java, Javascript, Julia, Kotlin, Lua, Ocaml, Pascal, Perl, PHP, Prolog, Python, Ruby, Rust, Scheme, Zig. A Markdown description of the input in English and French can also be generated.
You can install iorgen in a virtual environment like this:
git clone git@gitlab.com:prologin/tech/tools/iorgen.git cd iorgen python3 -m venv .venv source .venv/bin/activate pip3 install poetry poetry install
You can then run it with the iorgen command.
You should be able to trust that Iorgen will generate valid files. But if you want to be sure that those files are valid, and want to generate the test suite for instance, you will have to install lots of compilers.
The complete dependencies for Archlinux are:
pacman -S --needed python-yaml fpc gambit-c gcc gdc ghc go jdk-openjdk julia \
kotlin lua mono nodejs ocaml perl php ruby rust swi-prologFor Debian based distros (tested on Debian 10, 11, 12 and Ubuntu 18.04, 20.04, 22.04) (see limitations below):
sudo apt install python3-yaml default-jdk-headless fp-compiler g++ gambc gcc \
gdc ghc golang-go julia kotlin lua5.3 mono-mcs nodejs ocaml-nox perl \
php-cli ruby rustc swi-prolog-noxIssues with some Debian/Ubuntu versions:
Make sure python (version 3.10 and above) and python-yaml are installed on your computer and run python3 -m iorgen gen-stubs input.yaml. This will generate all languages parsers in a skeleton folder, and a input-subject-io-stub.md describing the input (in French by default).
Iorgen functionalities are separated in the following subcommands:
This subcommand allows you to generate languages parsers (skeletons) and a markdown subject stub.
You are able to generate these for a single YAML input file or multiple files at once.
By default, the languages parsers will be generated in the skeleton directory. However, you can change the output directory with the --output_dir option.
You can also chose to generate all files in the parent directory of the YAML input file with the --same_dir flag, by default it will generate the files in the current working directory. Note that the generated markdown stub will be named subject-io-stub.md when using --same_dir flag, otherwise it will be prefixed with the YAML input file name like this: <prefix>-subject-io-stub.md.
iorgen gen-stubs 42.yamliorgen gen-stubs 42/42.iorgen loueur/loueur.yamlYou can also use your shell globs!
iorgen gen-stubs **/*.yamliorgen gen-stubs --same_dir **/*.yamlThis subcommand allows you to generate a valid raw input based on your YAML input file.
You can specify a value, the minimum value or the maximum value of a variable for the generated raw input with the --specify option. NAME VALUE will set the value. NAME_max VALUE the maximum value and NAME_min VALUE the minimum value.
You can also treat raw input as in performance mode by using the --perf_mode flag. The performance mode is a mode where the constraints are different, usually the integers are bigger.
iorgen gen-input -s N_max 10 i 42 -- example.yamlThis subcommand allows you to check raw input files against a YAML input file.
You can also check raw inputs made generated for performance tests by using the --perf_mode flag.
iorgen validate 42.iorgen test/01.iniorgen validate 42.iorgen test/01.in test/02.in test/03.inor using globs
iorgen validate 42.iorgen 'test/*.in'or using shell globs
iorgen validate 42.iorgen test/*.inThis subcommand allows you to check that the parsers generated by iorgen properly parse and print the input they are fed with.
You may want to use the --languages option to specify the list of tested languages if you don't have all of them installed. See this section to know how to test against all languages.
iorgen run 42.iorgen test/test01.inIorgen can use the following types:
Iorgen supports floating-point numbers, but beware they are not as easy to use as integers. Here are the constrains when using floats:
The input is described in YAML, and must have the following format:
Any "name" field (or "function_name") can hold any alphanumic character or spaces, but must start with a letter, and can not have trailing whitespaces. You do not have to worry about the name beeing a language’s keyword: it will automatically be modified if that is the case, usually by adding a trailing underscore.
A "comment" field can hold any character other than a newline. For now, strings that end comments in some languages, such as */ should be avoided. A protection against this will be added in a later version.
A "type" field must have one of the following format int, float, char, str(size), List[type](size), @structname. You must replace size, type and structname following this guidelines:
Iorgen is supposed to choose how the input should be. For instance, each integer variable stands on its own line. Lists of integers however put them all on the same line. There are reasons for this: one variable per line is easier to parse on most languages; putting integers on the same line keeps inputs shorter. Anyway, even if you don't agree with those choices, you should not really care and just go with how Iorgen does things.
If you have the choice, don't try to change the defaults, just go with the flow: it is how Iorgen was meant to work and it is well tested with those defaults. However if your input is already set is stone and you can not change it, Iorgen provides a few options to tweak the input layout.
function_name: example
subject: This input is an example for Iorgen's README
structs:
- name: a struct
comment: A struct for the example
fields:
- type: int
name: integer
comment: an integer
choices: [-4, 42, 1337]
- type: char
name: character
comment: a char
choices: [a, b, c]
input:
- type: int
name: N
comment: a number, used as a size
min: 1
max: 10
max_perf: 10000
- type: List[@a struct](N)
name: list
comment: a list of structs
output: In a real life scenario, you will describe here what you want the end
user to do with this generated codeIf you want to generate the C code for parsing this kind of input, run python3 -m iorgen gen-stubs -l c example.yaml, and you will get the following skeleton/example.c:
#include <stdio.h>
#include <stdlib.h>
/// A struct for the example
struct a_struct {
int integer; ///< an integer
char character; ///< a char
};
/// \param n a number, used as a size
/// \param list a list of structs
void example(int n, struct a_struct* list) {
/* TODO In a real life scenario, you will describe here what you want the
end user to do with this generated code */
}
int main() {
int n;
scanf("%d", &n);
struct a_struct* list = (struct a_struct*)malloc(n * sizeof(struct a_struct));
for (int i = 0; i < n; ++i) {
scanf("%d %c", &list[i].integer, &list[i].character);
}
example(n, list);
return 0;
}You can see every other thing that Iorgen can generate in the test samples; you can find parsers for lots of languages, and also a generated description of the input in Markdown.
| Back | FazBrowse Home | New Git URL |