Extendable syntaxes
Created by: bopjesvla
Extendable syntaxes would allow for:
- the usage of independently written macros with the same name, provided that they're used in different contexts
- the inline extension of an imported macro without forking a module
- anything that requires backtracking, such as the
macro
syntax
The most natural implementation I can think of would be to allow syntax functions to return null, after which the reader tracks back and tries the previous macro with the same name:
syntax each = ctx => {
let variable = ctx.next("expr").value,
OF = ctx.next().value,
iterable = ctx.next("expr").value,
body = ctx.next().value
if (variable && iterable && OF.isIdentifier("of") && body.isBraces()) {
return #`for (${variable} ${OF} ${iterable}) ${body}`
}
}
syntax each = ctx => {
let iterable = ctx.next("expr").value,
body = ctx.next().value
if (iterable && body.isBraces()) {
return #`for ($_ of ${iterable}) ${body}` // yeah this wouldn't work because of hygiene
}
}
each x of y {
x()
}
each y {
$_()
}
This would cover a lot of the same ground as readtables.