aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: b7e684b16ccae47a2bee119aa68238a513e77d7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# metac: A table-driven preprocessor for C

## Overview
`metac` is my attempt at a C preprocessor that adds the features I would like C to have. It is
inspired by Ryan Fleury's article, see resources below.

### Features
- `@table` keyword for specifying data, eg.
```
@table(name, str) MyEnumTable
{
    { A "A" }
    { B "B" }
    { C "C" }
}
```
- `@expand` keyword for using data from a table, eg.
```
typedef enum
{
@expand(MyEnumTable t)
`    MyEnum_$a(a.name),`
    MyEnum_Count
} MyEnum;
```

## Build
Run the build script.
```sh
./source/build.sh
```

## Try it out
To chek the usage you can run withuot arguments.
```
./build/metac
Usage: ./build/metac filename [output_filename]
```
Run the program on the example file.
```sh
./build/metac examples/table.c
```
Checkout the newly created `table.meta.c`.  This is your metaprogram!

# Resources
- [Ryan Fleury - table-driven code generation](https://www.rfleury.com/p/table-driven-code-generation)