Created
November 28, 2016 18:36
-
-
Save devilholk/ffa1e8dd966e2076941a7f2d67a6ebd5 to your computer and use it in GitHub Desktop.
Example for text manipulation in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T = indented_block | |
program_template = T([ | |
'//Include directives', | |
'¶includes', | |
'', | |
'//Main application', | |
'¶main', | |
]) | |
include_directive = T('#include <file>') | |
includes = 'stdio.h', 'stdlib.h' | |
function = T([ | |
'returns name(args) {', | |
'\tbody', | |
'}', | |
]) | |
program = program_template.replace('¶includes', | |
[include_directive.replace('file', i) for i in includes]) | |
main_body = T([ | |
'printf("Hello World!\\n");' | |
]) | |
program = program.replace('¶main', | |
function.replace_kw( | |
name='main', | |
returns='int', | |
args='int argc, char* argv[]', | |
body=main_body | |
)) | |
print(program.to_text()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment