{"id":13692151,"url":"https://github.com/tbrand/zir","last_synced_at":"2025-05-12T22:02:12.684Z","repository":{"id":75519290,"uuid":"85443632","full_name":"tbrand/zir","owner":"tbrand","description":"Realizes to write macros in any scripts into any languages.","archived":false,"fork":false,"pushed_at":"2017-03-20T00:57:56.000Z","size":12,"stargazers_count":22,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-20T18:40:28.375Z","etag":null,"topics":["command","command-line","command-line-tool","command-line-tools","commandline","crystal","macro","macros"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tbrand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-19T01:37:01.000Z","updated_at":"2022-11-18T20:59:35.000Z","dependencies_parsed_at":"2023-06-06T17:45:38.139Z","dependency_job_id":null,"html_url":"https://github.com/tbrand/zir","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/tbrand%2Fzir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbrand%2Fzir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbrand%2Fzir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbrand%2Fzir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbrand","download_url":"https://codeload.github.com/tbrand/zir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253830925,"owners_count":21971001,"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":["command","command-line","command-line-tool","command-line-tools","commandline","crystal","macro","macros"],"created_at":"2024-08-02T17:00:54.178Z","updated_at":"2025-05-12T22:02:12.608Z","avatar_url":"https://github.com/tbrand.png","language":"Crystal","funding_links":[],"categories":["Implementations/Compilers"],"sub_categories":[],"readme":"# zir\n\n[![Build Status](https://travis-ci.org/tbrand/zir.svg?branch=master)](https://travis-ci.org/tbrand/zir)\n[![Dependency Status](https://shards.rocks/badge/github/tbrand/zir/status.svg)](https://shards.rocks/github/tbrand/zir)\n[![devDependency Status](https://shards.rocks/badge/github/tbrand/zir/dev_status.svg)](https://shards.rocks/github/tbrand/zir)\n\n**zir** is a command line tool that realizes to write macros in any scripts into any languages.  \nSee an example. (The macro is written in Ruby)\n```c\n#include\u003cstdio.h\u003e\n\nint main(){\n  \u003c-@macro puts \"double a = #{Math::PI};\" -\u003e\n  printf(\"PI is %f!\\n\", a);\n  return 0;\n}\n```\nThis file will be expanded by zir like\n```c\n#include\u003cstdio.h\u003e\n\nint main(){\n  double a = 3.141592653589793;\n  printf(\"PI is %f!\\n\", a);\n  return 0;\n}\n```\n\nThe result is `PI is 3.141593!`. :smile:\nYou can find other samples at [here](https://github.com/tbrand/zir/tree/master/spec/projs).\n\n## Installation\n\nzir is written in Crystal. So you need the environment. After that, clone this project and build by\n```\nshards build\n```\nNow you can find an executable binary at `zir/bin/zir`\n\n## Usage\n\n### Flow of the expandation\n\n1. Search zir files (such as sample.c.z)\n2. Collect macros from the files\n3. Create temporary files to be executed\n4. Execute the scripts\n5. Embed the result into the files (such as sample.c)\n\n### zir.yaml\n\nzir.yaml is a configuration file to execute zir. You must put it on a root of your project. zir.yaml is consists of 3 parts.\n\nSpecify files to be expanded in **targets**. The files must end with **.z**. **.z** will be removed from the name of expanded files. So sample.c.z will be sample.c.\n```yaml\ntargets: # An example\n  - sample.c.z\n```\n\nTell me how to execute the macros in **ids**. It need identifier and command line sample. **@file** will be replaced to a temporary executable.\n```yaml\n# 'macro' is an identifier and `ruby some_temporary_executable` will be executed\nids:\n  macro: ruby @file\n```\n\nWhat to execute at finally?\n```yaml\nfinally:\n  gcc -o a.out sample.c\n```\n\nHere is a fully example.\n```yaml\ntargets:\n  - sample.c.z\n  \nids:\n  macro: ruby @file\n\nfinally:\n  gcc -o a.out sample.c  \n```\n\n### Write macros\n\nThe structure of macros is here.\n```\n\u003c-@id your_code_here -\u003e\n```\n\nAll macros are sandwiched by `\u003c- -\u003e`. In the above example, `@` is called **mark** and it can be `%` as well. `id` is an identifier which is defined in zir.yaml. Puts your code at `your_code_here`.\n\nThere are 2 types of macros and each of them has their mark.\n\nFirst one is **print macro** that will be embeded into a source code. The mark of the print macro is **@**. Print macro shouldn't contain any logics but just print out variables. Here is an example of it.\n```\n\u003c-@id puts \"a\" -\u003e\n```\n\nSecond one is **logic macro** that contains logics only. So This will print out nothing. Logic macros affect to the print macros which have same id with it.\n```\n\u003c-%id0 a = 10 -\u003e\n\u003c-%id1 a += 1 -\u003e\n\u003c-@id0 puts a -\u003e\n```\nSo the result of this will be 10.\nSee [sample projects](https://github.com/tbrand/zir/tree/master/spec/projs) to know how to write these macros.\n\n### command line\n\nBasically, you just run `zir run` at root of your project. If you want to clean all temporary files, you can do it by `zir clean`. If you need a sample of zir.yaml, you can get it by `zir init`.\n\n`-c DEPTH` or `--cealn=DEPTH` options help you to debug. You can specify which files to keep or to delete. DEPTH can be 0 to 2. If you specify 0, zir will keep all temporary files. Intermediate executable scripts are in .zir directory. 1 is default value that delete .zir directory but keep expanded files. So when you expand sample.c.z, expanded sample.c will remain. 2 will delete all files created by zir. (Delete sample.c in the previous case.)\n\n`zir -h` will show you more options.\n\n## Contributing\n\n1. Fork it ( https://github.com/tbrand/zir/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Push to the branch (git push origin my-new-feature)\n5. Create a new Pull Request\n\n## Contributors\n\n- [tbrand](https://github.com/tbrand) Taichiro Suzuki - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbrand%2Fzir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbrand%2Fzir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbrand%2Fzir/lists"}