Skip to content
stack-based macro processor extensible with guile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
Makefile
README.md
mro.1
mro.c
mro.expand.c
mro.mro.1

README.md

<style type="text/css"> p { margin-top: 0; margin-bottom: 0; vertical-align: top } pre { margin-top: 0; margin-bottom: 0; vertical-align: top } table { margin-top: 0; margin-bottom: 0; vertical-align: top } h1 { text-align: center } </style> <title>mro</title>

mro

NAME
SYNOPSIS
DESCRIPTION
COMMANDS
GUILE FUNCTIONS
EXAMPLES
SEE ALSO
BUGS
AUTHOR


NAME

mro − a stack-based macro processor that can form macros based on results returned by scheme functions

SYNOPSIS

mro

DESCRIPTION

mro is a stack-based macro processor. It reads from standard input, evaluates the macros provided to standard input, and writes the processed text to standard output. The macros can be constructed by evaluating Guile Scheme code. The macro language is parsed by reading one character at a time from left to right in a single pass.

The macro language is centered around a stack. When you are on the bottom of the stack, characters typed in are echoed to standard output until a command is reached. You can move up a level in the stack by using the PUSH command (by default: #). Text you enter at higher levels of the stack will not be put to standard output but can be accessed by mro commands.

Macro processing languages are used for text generation whether that text is code, a website, or writing.

COMMANDS

The following are the mro commands

#

PUSH command. All text written after the command is the next level up on the stack.

@

DEFINE command. Pops the text off the top two levels of the stack and assigns the text at the top of the text to the macro name at the second level from the top.

~

REFERENCE command. Pops the text from the top of the stack, looks up the name of the macro specified there, and puts that text’s value to the next level down in the stack.

$

EXPAND command. Expands the macros in the text on the top level of the stack.

|

SHELL command. Evalutes the text on the top level of the stack as a shell command, and outputs the output of the command to the next level down on the stack.

!

CODE command. Evaluates the text on the top level of the stack as Guile Scheme code, converts the result to a string using Guile’s

display function, and puts the text to the next buffer down in the stack.

’=’

PUSH2 command.

%

COMMENT. Ignore any text following the command until a newline character is reached.

‘text’

QUOTE text. Put the literal text to the current level of the stack. This is how you escape the command characters.

GUILE FUNCTIONS

The following Guile functions are built into mro
(source filename)

treats the file as if it were actually written to standard input. In other words, mro
parses the contents of the file. To include the file without parsing it, use #cat filename|.

(add_to_dnp char)

adds the character to the "do not print list". mro will ignore this character while parsing.

(printall)

removes all characters from the "do not print list".

EXAMPLES

Section counter
The mro commands in

#i=1@%
#sec=‘Section #i~#i##(+ #i~ 1);@’@%
##sec~$
##sec~$

are expanded to

Section 1
Section 2

Boilerplate Guile Code in mro itself

Guile functions in C have to be registered. mro makes this process easy to generate. It uses these macros in its own source.

#register=
void*
register_guile_functions (void* data)
{@
#gfunc=‘#register##register~
scm_c_define_gsubr("#name~", #argnum~, 0, 0, &guile_#name~);@%
SCM
guile_#name~’@
#regbuild=‘#register~
return NULL;
}’@

Then, we can create guile functions like:

#name=source@
#argnum=1@
##gfunc~$ (SCM file) { ... }

And then type ##regbuild~$ to output the register_guile_functions function that can be used with Guile’s scm_with_guile function.

SEE ALSO

BUGS

Please report as an issue to https://github.com/flynnzac/mro

AUTHOR

Zach Flynn <zlflynn@gmail.com> 0.0.1


You can’t perform that action at this time.