A pretty decent macro processor in less than 300 lines of Hare.
This is still a work in progress, and there are some bugs and features still being worked on; in particular, nested macros.
$ make hare build $ cat input1.txt Hi there, ``upper!(everyone)''! $ ./eaton < input1.txt Hi there, EVERYONE!
eaton is meant to vendored and extended, not installed like most other
programs. Simply clone this repository where you wish, run
you're ready to go. If you are incorporating eaton into an existing
repository, you may prefer to use
$ git subtree --squash -P eaton/ add https://git.sr.ht/~smlavine/eaton master
To add new macros, simply add a new Hare source file to the
module. Use the existing macro definitions as examples. Even complex
macros shouldn't take more than ten or twenty lines of your own code.
All of the macros provided with eaton are named like
But this is just a convention; any macros you write yourself do not have
to follow it.
Take care when writing the regular expressions used to match your
macros. Writing a regular expression that always matches (such as
(.*)) will crash the program. The Hare regex engine is greedy, so if
matching for text within parens, don't match closing parens in your
capture. Consider a simple, correct regular expression, as defined in
def UPPER_RE = `upper!\(([^)]*)\)`;
The contents of the capture group is what will be provided to the macro
for formatting. Instead of capturing
.*, we capture
preventing the expression from matching beyond what is intended.
There is no method of modifying state (i.e. defining macros or setting
variables) from the input of a macro itself; this would increase
implementation complexity considerably. However, the provided macros
system! are enough to interact with the environment
and state can be stored and retrieved from it however you like.
Copyright (C) 2023 Sebastian LaVine <email@example.com>
Licensed under the terms of the GNU GPL, version 3 or later.
Patches? Feedback? Send them to ~firstname.lastname@example.org.