{"id":20644222,"url":"https://github.com/senselogic/generis","last_synced_at":"2025-04-16T02:07:47.984Z","repository":{"id":57496835,"uuid":"174871202","full_name":"SenseLogic/GENERIS","owner":"SenseLogic","description":"Versatile Go code generator.","archived":false,"fork":false,"pushed_at":"2022-02-22T21:26:01.000Z","size":318,"stargazers_count":45,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-16T02:07:23.888Z","etag":null,"topics":["code-generator","conditional-compilation","conversion","generics","golang","html-templating","style"],"latest_commit_sha":null,"homepage":"","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SenseLogic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-10T19:33:31.000Z","updated_at":"2025-02-26T03:00:11.000Z","dependencies_parsed_at":"2022-09-03T02:30:49.728Z","dependency_job_id":null,"html_url":"https://github.com/SenseLogic/GENERIS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenseLogic%2FGENERIS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenseLogic%2FGENERIS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenseLogic%2FGENERIS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SenseLogic%2FGENERIS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SenseLogic","download_url":"https://codeload.github.com/SenseLogic/GENERIS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249183104,"owners_count":21226142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generator","conditional-compilation","conversion","generics","golang","html-templating","style"],"created_at":"2024-11-16T16:15:26.913Z","updated_at":"2025-04-16T02:07:47.724Z","avatar_url":"https://github.com/SenseLogic.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://github.com/senselogic/GENERIS/blob/master/LOGO/generis.png)\n\n# Generis\n\nVersatile Go code generator.\n\n## Description\n\nGeneris is a lightweight code preprocessor adding the following features to the Go language :\n\n*   Generics.\n*   Free-form macros.\n*   Conditional compilation.\n*   HTML templating.\n*   Allman style conversion.\n\n## Sample\n\n```go\npackage main;\n\n// -- IMPORTS\n\nimport (\n    \"html\"\n    \"io\"\n    \"log\"\n    \"net/http\"\n    \"net/url\"\n    \"strconv\"\n    );\n\n// -- DEFINITIONS\n\n#define DebugMode\n#as true\n\n// ~~\n\n#define HttpPort\n#as 8080\n\n// ~~\n\n#define WriteLine( {{text}} )\n#as log.Println( {{text}} )\n\n// ~~\n\n#define local {{variable}} : {{type}};\n#as var {{variable}} {{type}};\n\n// ~~\n\n#define DeclareStack( {{type}}, {{name}} )\n#as\n    // -- TYPES\n\n    type {{name}}Stack struct\n    {\n        ElementArray []{{type}};\n    }\n\n    // -- INQUIRIES\n\n    func ( stack * {{name}}Stack ) IsEmpty(\n        ) bool\n    {\n        return len( stack.ElementArray ) == 0;\n    }\n\n    // -- OPERATIONS\n\n    func ( stack * {{name}}Stack ) Push(\n        element {{type}}\n        )\n    {\n        stack.ElementArray = append( stack.ElementArray, element );\n    }\n\n    // ~~\n\n    func ( stack * {{name}}Stack ) Pop(\n        ) {{type}}\n    {\n        local\n            element : {{type}};\n\n        element = stack.ElementArray[ len( stack.ElementArray ) - 1 ];\n\n        stack.ElementArray = stack.ElementArray[ : len( stack.ElementArray ) - 1 ];\n\n        return element;\n    }\n#end\n\n// ~~\n\n#define DeclareStack( {{type}} )\n#as DeclareStack( {{type}}, {{type:PascalCase}} )\n\n// -- TYPES\n\nDeclareStack( string )\nDeclareStack( int32 )\n\n// -- FUNCTIONS\n\nfunc HandleRootPage(\n    response_writer http.ResponseWriter,\n    request * http.Request\n    )\n{\n    local\n        boolean : bool;\n    local\n        natural : uint;\n    local\n        integer : int;\n    local\n        real : float64;\n    local\n        escaped_html_text,\n        escaped_url_text,\n        text : string;\n    local\n        integer_stack : Int32Stack;\n\n    boolean = true;\n    natural = 10;\n    integer = 20;\n    real = 30.0;\n    text = \"text\";\n    escaped_url_text = \"\u0026escaped text?\";\n    escaped_html_text = \"\u003cescaped text/\u003e\";\n\n    integer_stack.Push( 10 );\n    integer_stack.Push( 20 );\n    integer_stack.Push( 30 );\n\n    #write response_writer\n        \u003c!DOCTYPE html\u003e\n        \u003chtml lang=\"en\"\u003e\n            \u003chead\u003e\n                \u003cmeta charset=\"utf-8\"\u003e\n                \u003ctitle\u003e\u003c%= request.URL.Path %\u003e\u003c/title\u003e\n            \u003c/head\u003e\n            \u003cbody\u003e\n                \u003c% if ( boolean ) { %\u003e\n                    \u003c%= \"URL : \" + request.URL.Path %\u003e\n                    \u003cbr/\u003e\n                    \u003c%@ natural %\u003e\n                    \u003c%# integer %\u003e\n                    \u003c%\u0026 real %\u003e\n                    \u003cbr/\u003e\n                    \u003c%~ text %\u003e\n                    \u003c%^ escaped_url_text %\u003e\n                    \u003c%= escaped_html_text %\u003e\n                    \u003c%= \"\u003c%% ignored %%\u003e\" %\u003e\n                    \u003c%% ignored %%\u003e\n                \u003c% } %\u003e\n                \u003cbr/\u003e\n                Stack :\n                \u003cbr/\u003e\n                \u003c% for !integer_stack.IsEmpty() { %\u003e\n                    \u003c%# integer_stack.Pop() %\u003e\n                \u003c% } %\u003e\n            \u003c/body\u003e\n        \u003c/html\u003e\n    #end\n}\n\n// ~~\n\nfunc main()\n{\n    http.HandleFunc( \"/\", HandleRootPage );\n\n    #if DebugMode\n        WriteLine( \"Listening on http://localhost:HttpPort\" );\n    #end\n\n    log.Fatal(\n        http.ListenAndServe( \":HttpPort\", nil )\n        );\n}\n```\n\n## Syntax\n\n### #define directive\n\nConstants and generic code can be defined with the following syntax :\n\n```go\n#define old code\n#as new code\n\n#define old code\n#as\n    new\n    code\n#end\n\n#define\n    old\n    code\n#as new code\n\n#define\n    old\n    code\n#as\n    new\n    code\n#end\n```\n\n#### #define parameter\n\nThe `#define` directive can contain one or several parameters :\n\n```go\n{{variable name}} : hierarchical code (with properly matching brackets and parentheses)\n{{variable name#}} : statement code (hierarchical code without semicolon)\n{{variable name$}} : plain code\n{{variable name:boolean expression}} : conditional hierarchical code\n{{variable name#:boolean expression}} : conditional statement code\n{{variable name$:boolean expression}} : conditional plain code\n```\n\nThey can have a boolean expression to require they match specific conditions :\n\n```go\nHasText text\nHasPrefix prefix\nHasSuffix suffix\nHasIdentifier text\nfalse\ntrue\n!expression\nexpression \u0026\u0026 expression\nexpression || expression\n( expression )\n```\n\nThe `#define` directive must not start or end with a parameter.\n\n#### #as parameter\n\nThe `#as` directive can use the value of the `#define` parameters :\n\n```go\n{{variable name}}\n{{variable name:filter function}}\n{{variable name:filter function:filter function:...}}\n```\n\nTheir value can be changed through one or several filter functions :\n\n```go\nLowerCase\nUpperCase\nMinorCase\nMajorCase\nSnakeCase\nPascalCase\nCamelCase\nRemoveComments\nRemoveBlanks\nPackStrings\nPackIdentifiers\nReplacePrefix old_prefix new_prefix\nReplaceSuffix old_suffix new_suffix\nReplaceText old_text new_text\nReplaceIdentifier old_identifier new_identifier\nAddPrefix prefix\nAddSuffix suffix\nRemovePrefix prefix\nRemoveSuffix suffix\nRemoveText text\nRemoveIdentifier identifier\n```\n\n### #if directive\n\nConditional code can be defined with the following syntax :\n\n```go\n#if boolean expression\n    #if boolean expression\n        ...\n    #else\n        ...\n    #end\n#else\n    #if boolean expression\n        ...\n    #else\n        ...\n    #end\n#end\n```\n\nThe boolean expression can use the following operators :\n\n```go\nfalse\ntrue\n!expression\nexpression \u0026\u0026 expression\nexpression || expression\n( expression )\n```\n\n### #write directive\n\nTemplated HTML code can be sent to a stream writer using the following syntax :\n\n```html\n#write writer expression\n    \u003c% code %\u003e\n    \u003c%@ natural expression %\u003e\n    \u003c%# integer expression %\u003e\n    \u003c%\u0026 real expression %\u003e\n    \u003c%~ text expression %\u003e\n    \u003c%= escaped text expression %\u003e\n    \u003c%! removed content %\u003e\n    \u003c%% ignored tags %%\u003e\n#end\n```\n\n## Limitations\n\n*   There is no operator precedence in boolean expressions.\n*   The `--join` option requires to end the statements with a semicolon.\n*   The `#writer` directive is only available for the Go language.\n\n## Installation\n\nInstall the [DMD 2 compiler](https://dlang.org/download.html) (using the MinGW setup option on Windows).\n\nBuild the executable with the following command line :\n\n```bash\ndmd -m64 generis.d\n```\n\n## Command line\n\n```\ngeneris [options]\n```\n\n### Options\n\n```\n--prefix # : set the command prefix\n--parse INPUT_FOLDER/ : parse the definitions of the Generis files in the input folder\n--process INPUT_FOLDER/ OUTPUT_FOLDER/ : reads the Generis files in the input folder and writes the processed files in the output folder\n--trim : trim the HTML templates\n--join : join the split statements\n--create : create the output folders if needed\n--watch : watch the Generis files for modifications\n--pause 500 : time to wait before checking the Generis files again\n--tabulation 4 : set the tabulation space count\n--extension .go : generate files with this extension\n```\n\n### Examples\n\n```bash\ngeneris --process GS/ GO/\n```\n\nReads the Generis files in the `GS/` folder and writes Go files in the `GO/` folder.\n\n```bash\ngeneris --process GS/ GO/ --create\n```\n\nReads the Generis files in the `GS/` folder and writes Go files in the `GO/` folder,\ncreating the output folders if needed.\n\n```bash\ngeneris --process GS/ GO/ --create --watch\n```\n\nReads the Generis files in the `GS/` folder and writes Go files in the `GO/` folder,\ncreating the output folders if needed and watching the Generis files for modifications.\n\n```bash\ngeneris --process GS/ GO/ --trim --join --create --watch\n```\n\nReads the Generis files in the `GS/` folder and writes Go files in the `GO/` folder,\ntrimming the HTML templates, joining the split statements, creating the output folders if needed\nand watching the Generis files for modifications.\n\n## Version\n\n2.0\n\n## Author\n\nEric Pelzer (ecstatic.coder@gmail.com).\n\n## License\n\nThis project is licensed under the GNU General Public License version 3.\n\nSee the [LICENSE.md](LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenselogic%2Fgeneris","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsenselogic%2Fgeneris","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenselogic%2Fgeneris/lists"}