Language Support
The following languages are supported out of the box:
- C++
- Groovy
- Java
- Javascript
- Lua
- Python
Bouhou, my favorite language is not in this list? Don't worry, we got you covered. You have two possible solutions:
The nice way
There is extremely little language-specific code in stupidgen. The easiest way to add support for a language is to start by cloning the stupidgen repository:
Then add a new class into /src/stupidgen/languages.py to support your language (get some inspiration from the code for the other languages).Install the modified version of stupidgen on your machine with
Finally share your changes with the rest of the world by sending the new code via a pull request, opening an issue, sending me an email, or writing it on a nice postcard. Don't forget to claim your chocolate reward for contributing to the project.The experimental way
Note: this method requires less setup than the one above, but relies on stupidgen internals, which might change between versions of stupidgen.
There is also a way to manually setup the stupidgen processor without modifying it. If you run stupidgen with the --language meta argument, then every line that starts with ~ is treated a 'configuration' line. These lines are executed as python code, and allow to setup how the processor will handle the rest of the file by calling methods on a global proc variable.
Here is an example below:
~# test.mylanguage.multi
~from stupidgen.stringprocessing import string_interpolation
~proc.set_line_handler(".", lambda l : l) # Leave lines starting with a . unmodified
~proc.set_line_handler("!", lambda l : None) # Drop lines starting with a '!'
~proc.set_line_handler("%", lambda l :
~ "superPrint(" + " + ".join(string_interpolation(l,
~ start_symbol = "{{", end_symbol = "}}",
~ code_map = lambda code : "escape_string(" + code + ")",
~ string_delimiters = ("\'")
~ )) + ");\n")
~#End of processor setup
~
.fun main() {
!This line will be ignored in the output
.var s = "toto";
.var i = 15;
%Hello {{ s }}, how are {{ i * i + 3 }} you?
.}
Processing this file with stupidgen --language meta test.mylanguage.multi will create a test.mylanguage file as output, containing the following:
fun main() {
var s = "toto";
var i = 15;
superPrint("Hello s" + escape_string( s ) + ", how are " + escape_string( i * i + 3) + " you?");
}
Neat right?