R4d (Rad)
R4d is a text oriented macro prosessor aims to be an alternative to m4 macro processor.
Note
Because crates.io's readme is tied to version. There might be undocumented readme changes. Please use github for latest information.
Demo
Raw texts
$define(author=Simon Creek)
$define(title=R4d demo)
---
title : $title()
author : $author()
---
My name is $author() and I made r4d to make macros can be used within various
forms of texts. This article was written in $date() $time().
$ifdef(test, This should be only printed when I'm testing not in release)$dnl()
This is some important table automatically formatted according to environment
variable.
$regcsv(addr,$include(addr.csv))$dnl()
$static(
queried,
$query(
SELECT id,first_name,address
FROM addr where first_name = John
)
)$dnl()
% Comments are disabled by default for better compatibility
% TABLE_FORM == github
$table($env(TABLE_FORM),$queried())
$wrap(40,$lipsum(15))
Evaluation : $prec($eval( $num(0.1second) + $num(0.2sekunde)),2)
Evaluation : $evalk( 1 + 2 )
Processed texts
Ran with TABLE_FORM=github rad file_name.md -a env+fin --comment
---
title : R4d demo
author : Simon Creek
---
My name is Simon Creek and I made r4d to make macros can be used within various
forms of texts. This article was written in 2022-01-18 16:38:07.
This is some important table automatically formatted according to environment
variable.
|id|first_name|address|
|-|-|-|
|1|John|111-2222|
|2|John|222-3333|
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore.
Evaluation : 0.30
Evaluation : 1 + 2 = 3
Install
Install rust related tools for build
I recommend using cargo install until I prepare a proper CD
pipeline.
Currently version 3.0 is preparing for release and can be downloaded with specific version flag.
cargo install r4d --features binary,color --locked --version 3.0.0-rc.2
e.g.
# Binary with full macros support
# If you need color prompt, then use features "color"
# Only include macros that doesnt't require external crates
# Refer docs.rs or usage section for detailed feature usage
Simple usage
Binary
There are two binaries each rad and rado. Rad is a main processor and rado is a open+edit binary.
# Read from a file and print to stdout
rad input_file.txt
# Read from standard input and print to a file
printf '...text...' | rad -o out_file.txt
# Edit a source file
rado edit file_name.txt
# Read a processed file
rado read file_name.txt
# Print environment variables
rado env
Library
use RadError;
use Processor;
let processor = new
.write_to_file?;
processor.process_file?;
processor.print_result?;
Usage
Syntax
Built-in macros
About various modes
Macro types
How to extend function macros
Extend processor with storage feature
How to debug
Goal
R4d aims to be a modern alternative to m4 processor, which means
- No trivial m4 quotes
- An explicit rule for macro definition and invocation
- Enable combination of file stream and stdout
- As expressive as current m4 macro processor
- Easier binding to other environments