#macro #cli

bin+lib r4d

面向文本的宏处理器

68 个版本 (17 个稳定版)

3.2.0-beta.1 2023 年 12 月 22 日
3.1.0 2022 年 10 月 17 日
3.0.1 2022 年 8 月 5 日
3.0.0-rc.62022 年 7 月 31 日
0.11.5 2021 年 10 月 18 日

#147 in 文本处理

Download history 22/week @ 2024-03-09 8/week @ 2024-03-16 19/week @ 2024-03-30 2/week @ 2024-04-06

每月 212 次下载
用于 gdengine

MIT/Apache 许可

555KB
13K SLoC

R4d (Rad)

R4d 是一个现代、易用且表达力强的面向文本的宏处理器。

变更

3.0 版本变更

注意

请使用 3.0.1 版本的 rad 而不是 3.0 版本。请参考 md 了解原因。

内容表

演示

原始文本

$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 )

处理后的文本

使用以下命令运行: 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

安装

安装 rust 工具链进行构建

我建议使用 cargo install,直到我准备好合适的 CD 管道。

# Binary with full macros support
cargo install r4d --features binary --locked

# Only include macros that doesnt't require external crates
cargo install r4d --features basic --locked

# Refer docs.rs or usage section for detailed feature usage

简单用法

二进制文件

每个 radrado 都有两个二进制文件。Rad 是主要处理器,rado 是包装二进制文件。

# rad
# 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
# Get a simple manual for a macro
rad --man ifdef

# rado
# Edit a source file
rado edit file_name.txt
# Read a processed file
rado read file_name.txt
# Print environment variables
rado env

use r4d::RadError;
use r4d::Processor;

let processor = Processor::new()
    .write_to_file(PathBuf::from("cache.txt"))?;

processor.process_file(Path::new("input.txt"))?;
processor.print_result()?;

文档

索引

已知问题

问题

依赖项

~5–16MB
~156K SLoC