Bounded example-guided string and table program synthesis, conditional expressions, regex captures and portable pipelines in MoonBit.

moon check --deny-warn
moon test --deny-warn
moon run cmd/demo
node scripts/build.mjs
node scripts/serve.mjsnode scripts/build.mjs
node scripts/advanced-test.mjs
python scripts/import-foofah.py
node scripts/benchmark.mjs
node scripts/serve.mjs| 使用者与问题 | 输入与操作 | 输出与验证 |
|---|---|---|
| 小商家/运营整理供应商复合编码 | examples/products/input.csv;提供两个型号/颜色样例,分别选择规则 | 型号 0012、123456 等保留前导零,颜色转大写;另外两行不参与训练,逐值检查 |
| 活动组织者生成名单标签 | examples/labels/input.csv;用姓名、班级示范 A1 / 陈雨,另外复制编号字段 | 新行生成 C20 / 赵晨,编号不变;测试重排列后重用配方仍一致 |
| 内容创作者整理音视频文件 | examples/media/input.csv;标注两个日期和 take 编号 | 未见的 20240229 正确变为 2024-02-29;invalid.csv 中 20260229 报错并停止 CSV 导出 |
node scripts/integration.mjs| 数据与使用者 | 操作与结果 | 验证范围 |
|---|---|---|
| IANA tzdb 2025b:应用设置页开发者 | 312 个时区标识,示范区域、末级地点,生成可按区域查询的目录 | 3 个字段,每字段 3 条训练,其余 309 条逐值验证 |
| Unicode CLDR 48:国际化开发者 | 766 个 locale,生成语言分组、资源路径和原始标识 | 3 个字段,每字段 3 条训练,其余 763 条逐值验证 |
| github/gitignore:IDE 模板目录开发者 | 312 个多层路径,生成文件名、去扩展名的模板名称和原路径 | 模板名称先有 3 条训练,按分歧提示补 C 和 C++ 两条;其余 307 条验证 |
python scripts/import-public-data.py
node scripts/public-data-test.mjs
python scripts/verify-sqlite.pynode bin/exampleloom.mjs learn --data examples/products/input.csv --examples examples/products/model-labels.json --out candidates.json
node bin/exampleloom.mjs recipe --report candidates.json --choose 0 --name model --out product.recipe.json
node bin/exampleloom.mjs apply --data examples/products/input.csv --recipe product.recipe.json --out product.result.csvlet report = @loom.synthesize([
{ input: ["订单-0012"], output: "0012" },
{ input: ["订单-123456"], output: "123456" },
])
// 先检查 report.truncated、候选表达式和 disagreements,再选择。
let output = @loom.evaluate(report.candidates[0].expression, ["订单-00987"])moon fmt --check
moon check --deny-warn --target all
moon test --deny-warn --target wasm-gc
moon test --deny-warn --target js
moon test --deny-warn --target wasm
moon infopub(all) enum Expr {
Field(Int)
Literal(String)
Slice(Expr, Position, Position)
Token(Expr, String, Int)
Run(Expr, RunKind, Int)
Trim(Expr)
Lower(Expr)
Upper(Expr)
Concat(Array[Expr])
DateText(Expr, String, String)
If(Condition, Expr, Expr)
RegexCapture(Expr, String, Int, Int)
RegexReplace(Expr, String, String)
} derive(Eq, Debug)pub(all) enum GroupMetric {
RowCount
SumInt64(String)
MinInt64(String)
MaxInt64(String)
}pub(all) struct SearchOptions {
max_candidates : Int
max_parts : Int
max_atom_evaluations : Int
max_steps : Int
max_frontier : Int
}pub(all) struct TableSearchOptions {
max_depth : Int
max_states : Int
max_evaluations : Int
max_candidates : Int
}pub(all) enum TableStep {
Select(Array[String], Array[String])
Filter(Condition)
MapRows(Recipe)
SplitColumn(String, String, Array[String])
Explode(String, String)
Unpivot(Array[String], Array[String], String, String)
Fold(Array[String], Array[String], String)
Melt(Array[String], Array[String], String, String, Bool)
PackRows(Int, Bool)
GroupRows(Array[String], Array[String])
Aggregate(Array[String], Array[Measure])
Pivot(Array[String], String, String, Array[String])
PivotGrid(Array[String], String, String)
CombineColumns(Array[String], String, String)
SegmentRows(Condition, Bool)
CarryContext(Condition, Array[String])
Transpose
PromoteHeaders
DemoteHeaders
FillDown(Array[String])
Deduplicate(Array[String])
DropRows(Int)
}fn handle(request : String) -> Stringfn synthesize(examples : Array[Example], options? : SearchOptions, separators? : Array[String], patterns? : Array[String], branch_depth? : Int) -> SearchReport raise LoomErrorfn synthesize_table(examples : Array[TableExample], options? : TableSearchOptions, separators? : Array[String], patterns? : Array[String]) -> TableSearchReport raise LoomErrorInstall
Download zipBounded example-guided string and table program synthesis, conditional expressions, regex captures and portable pipelines in MoonBit.