Basic functionality of string_to_code is to generate
a piece of messy code printing a given string.
For example
def f_1():
print('H', end='')
print('e', end='')
def f_2():
print('l', end='')
print('l', end='')
def f_5():
print(',', end='')
print(' ', end='')
def f_4():
print('o', end='')
f_5()
print('W', end='')
def f_6():
print('o', end='')
print('r', end='')
print('l', end='')
def f_3():
f_4()
f_6()
def f_7():
print('d', end='')
print('!', end='')
def f_0():
f_1()
f_2()
f_3()
f_7()
f_0()is a python program generated with
string_to_code.to_python3
displaying Hello, World!.
This package is available at PyPI. It can be installed using the command
pip install string-to-codeIn order to generate a code in your_favourite_language just call the function
string_to_code.to_your_favourite_language.proc
with the string which you want to display.
examples show some basic usage.
The project is setup using poetry. In order to create a develompent enviroment, after cloning this repository, run the command:
poetry install --with devHave a look at Running tests locally section.
If you just want to see the examples in action, it is enough to clone this repository and run the command:
poetry installAfterwards you can execute the commands like:
poetry run python3 examples/example_to_cpp.pyIf you think that string_to_code is missing some
language, feel free to add it - it is simple.
If you want to add support of let's say turbo_snake,
there are few things which you need to do:
-
create
to_turbo_snake.pyinstring_to_code. This module should define two functionprocandproc_printer_program. Theprocfunction returns aturbo_snakeprogram displaying the input string. Theproc_printer_programreturns aturbo_snakerepresentation of the givencore.PrinterProgramobject.Have a look at the existing modules.
-
create
setup_turbo_snake.pyintests. This file is used for tests. It should contain a functionget_test_data()returning aLanguageobject having fields like:tool_names: a list of program names (compilers, interpreters, linters etc.) used for executing and analysing the generated code,string_to_codebeing the functionstring_to_code.to_turbo_snake.proc,printer_program_to_codebeing the functionstring_to_code.to_turbo_snake.proc_printer_program,run_code: the function, which executes the generated code and returns the standard output,id: the id of the language, most likelyturbo_snake,source_code_file_extension: in case ofturbo_snakesomething likets.
-
create
setup_for_turbo_snake.shorsetup_no_sudo_for_turbo_snake.shinsystem_setup_scripts. These scripts are used by the workflows to install programs needed to execute corresponding tests - cf. stepInstall language dependenciesinpython_test.ymlandgenerate_and_upload_coverage_data.yml, and.gitpod.dockerfile. -
create and populate the
turbo_snakedirectory intests/example_data. These files should contain theturbo_snakesourcecode of some basic programs. Please have a look at the already existing examples.
tests use pytest.
If you do not want to run the tests for all of the languages
(because it takes too long
or you do not want to install all of the required tools)
you can skip some of them by using the --skip option.
For example, in order to skip
bash, C++ and
Lisp run the command
poetry run pytest --skip=bash --skip=cpp --skip=lispYou can also specify the languages which you want to test by using
--select option.
For example to run tests for C++ and
COBOL exclusively execute
poetry run pytest --select=cpp --select=cobolWithout installing any language dependencies from
system_setup_scripts you should be able
to successfully execute the command
poetry run pytest --select=python3This project is setup to be used with gitpod.