Metaxis
The Metaxis mark: a solid block and a wireframe cube, interlocked

Introduction

A file that declares its own language, then uses it

Metaxis is a rewriter. A .mx file has two halves: a header of directives that say what the second half's syntax is and what to turn it into, and a body written in that syntax. The tool reads the header, builds a reader for the language it describes, reads the body with it, and prints what the templates say. Nothing is built in, not +, not if, not that a number is a number, so the file that declares + could have declared anything else, and the tool never quietly prefers the language it was written in.

@token  name   "[A-Za-z_][A-Za-z0-9_]*"
@token  number "[0-9]+"
@comment "#" eol
@separator ";" => ";\n"

@syntax a "=" b   10 right  => "{a} = {b}"
@syntax a "+" b   60        => "add({a}, {b})"
@syntax "twice" e           => "({e} * 2)"
@end
x = 1;              # nothing here is built in
twice x + 2;
run
$ mx examples/first.mx
x = 1;
(add(x, 2) * 2)

One rule

Everything a directive says about foreign text is inside a string. A quoted word in a pattern is text the body must contain; a quoted template is text to write. Everything outside the quotes is Metaxis's own fixed vocabulary, which no file can change: a directive name, a hole, a level, a bracket. That is what lets a directive mention if without being an if statement, and it is why a .mx file can read a language with keywords without ever having a keyword list: then is a word where a rule quoted it and a name everywhere else, by position.

What it has been pointed at

Five translators, each taken far enough to be compiled and run by the test suite, and each picked because it would ask the tool for something:

Where to read

Getting it

git clone https://github.com/hansolovkarlsson/Metaxis
cd Metaxis && make && make check
bin/mx examples/first.mx

C11 and make, plus POSIX <regex.h>. Nothing else. The suite runs on every push, on Linux and macOS.