• Stars
    star
    22
  • Rank 1,048,934 (Top 21 %)
  • Language
    Crystal
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Realizes to write macros in any scripts into any languages.

zir

Build Status Dependency Status devDependency Status

zir is a command line tool that realizes to write macros in any scripts into any languages.
See an example. (The macro is written in Ruby)

#include<stdio.h>

int main(){
  <-@macro puts "double a = #{Math::PI};" ->
  printf("PI is %f!\n", a);
  return 0;
}

This file will be expanded by zir like

#include<stdio.h>

int main(){
  double a = 3.141592653589793;
  printf("PI is %f!\n", a);
  return 0;
}

The result is PI is 3.141593!. πŸ˜„ You can find other samples at here.

Installation

zir is written in Crystal. So you need the environment. After that, clone this project and build by

shards build

Now you can find an executable binary at zir/bin/zir

Usage

Flow of the expandation

  1. Search zir files (such as sample.c.z)
  2. Collect macros from the files
  3. Create temporary files to be executed
  4. Execute the scripts
  5. Embed the result into the files (such as sample.c)

zir.yaml

zir.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.

Specify 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.

targets: # An example
  - sample.c.z

Tell me how to execute the macros in ids. It need identifier and command line sample. @file will be replaced to a temporary executable.

# 'macro' is an identifier and `ruby some_temporary_executable` will be executed
ids:
  macro: ruby @file

What to execute at finally?

finally:
  gcc -o a.out sample.c

Here is a fully example.

targets:
  - sample.c.z
  
ids:
  macro: ruby @file

finally:
  gcc -o a.out sample.c  

Write macros

The structure of macros is here.

<-@id your_code_here ->

All macros are sandwiched by <- ->. 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.

There are 2 types of macros and each of them has their mark.

First 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.

<-@id puts "a" ->

Second 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.

<-%id0 a = 10 ->
<-%id1 a += 1 ->
<-@id0 puts a ->

So the result of this will be 10. See sample projects to know how to write these macros.

command line

Basically, 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.

-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.)

zir -h will show you more options.

Contributing

  1. Fork it ( https://github.com/tbrand/zir/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • tbrand Taichiro Suzuki - creator, maintainer

More Repositories

1

router.cr

Minimum High Performance Middleware for Crystal Web Server.
Crystal
258
star
2

neph

A modern command line job processor, similar with make command
Crystal
203
star
3

dystopia

Anonymity on the Internet by Transparent way.
Rust
93
star
4

mssh

Simple and powerful job executor on remote nodes. πŸš€
Crystal
40
star
5

cargo-tomlfmt

Formatting Cargo.toml
Rust
25
star
6

iemon

Crystal
19
star
7

OneItem

Simple implementation for one item selected RecyclerView. This makes it easier to use arbitrary VideoView (such as MediaPlayer) in RecyclerView. This library includes RecyclerView.LayoutManager and Recyclerview.OnScrollListener.
Java
17
star
8

fastlane-plugin-bluepill

Fastlane plugin to use Bluepill powered by LinkedIn
Ruby
15
star
9

awesome-logger

πŸ‘‘ Awesome Logger is SIMPLE and FLEXIBLE logger for Crystal applications. πŸ‘‘
Crystal
14
star
10

byzan

Distributed blockchain KVS with high availability written in Rust
Rust
10
star
11

tokoroten

Using multiple processes in Crystal
Crystal
8
star
12

OutOfMemory

The developers community of Q and A.
Rust
8
star
13

pixvas

Create pixel image in your terminal
Crystal
7
star
14

roulette

Simulate, Analyze and Play Roulette with Algorithms
Crystal
6
star
15

cdk-lambda-log

"tail" the latest Lambda function's log by one line
TypeScript
4
star
16

famo

Command line tool for caching builds on S3
Rust
2
star
17

gaga

Rust
1
star
18

slack-logger

Crystal
1
star
19

ncpu.cr

Get number of cpus in Crystal
Crystal
1
star
20

rp

Experimental implementation aims to be substitute for `cp` command.
Rust
1
star
21

MobileCUDA

C
1
star
22

helnet

Practice about network stuff
Rust
1
star