MCPInstall

yaklang-syntax

Yaklang DSL 语法案例。当用户需要写或读懂 Yaklang (.yak) 代码时使用:变量与类型、切片/map、控制流、函数(func/箭头/闭包/可变参数/多返回值)、字符串模板 f-string、以及错误处理三板斧( 波浪号 / if err / defer recover)。包含可直接运行的语法巡览与错误处理示例。

Installs
120
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/yaklang/yak-skills --skill yaklang-syntax
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads yaklang-syntax automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

SKILL: Yaklang DSL 语法案例

AI LOAD INSTRUCTION: Yaklang 是为安全研究设计的 DSL,语法接近 Go 但更动态。本页给出可直接运行的语法案例与几个真实存在的"坑"(见第 5 节)。两个示例 examples/syntax-tour.yak / examples/error-handling.yak 都可用 yak <file> 自测通过。写 Yaklang 时优先参考这里而非凭空臆测语法。

0. 相关路由

  • 总入口:yak
  • 数据库操作语法:yaklang-database
  • 把语法用于实战(热加载 hook):mitm-hotpatch / webfuzzer-hotpatch

1. 变量、类型与集合

a = 10              // int, 整数除法截断: 10/3 == 3
name = "yaklang"    // string
ok = true           // bool
pi = 3.14           // float

nums = [1, 2, 3]            // 切片 (动态数组)
nums = append(nums, 4, 5)   // append 可追加多个
sub = nums[1:3]            // 切片表达式 -> [2, 3]

m = {"host": "a.com", "port": 443}  // map
v = m["port"]                        // 取值
exist = "host" in m                  // in 判断 key 是否存在
delete(m, "port")                    // 删除 key

2. 控制流

for i := 0; i < 5; i++ { sum += i }   // 经典三段式 for

for v in [10, 20, 30] { total += v }  // for-in: 单变量 = 元素值 (推荐)

if score >= 90 {
    grade = "A"
} else if score >= 60 {
    grade = "B"
} else {
    grade = "C"
}

3. 函数(核心,热加载全靠它)

Yaklang 里函数是"值",推荐用字面量赋值给变量:

add = func(a, b) { return a + b }     // func 字面量
add = fn(a, b) { return a + b }       // fn / def 等价于 func
func named(a, b) { return a + b }     // 命名函数

twice = (x) => { return x * 2 }       // 箭头函数 (热加载 hook 常用写法)

addsub = func(a, b) { return a + b, a - b }   // 多返回值
s, d = addsub(7, 3)                            // 多重赋值

makeCounter = func() {                 // 闭包: 捕获并保持状态
    n = 0
    return func() { n++; return n }
}

sumAll = func(args...) {               // 可变参数
    t = 0
    for v in args { t += v }
    return t
}

热加载 hook 正是"把函数赋值给约定名字的变量",例如:

beforeRequest = func(https, originReq, req) { return req }
hijackHTTPRequest = (isHttps, url, req, forward, drop) => { forward(req) }

完整可运行示例:examples/syntax-tour.yak

4. 字符串模板与错误处理

f-string 插值

line = f"user=${user} port=${port}"   // -> "user=admin port=8080"
msg = sprintf("%d-%s", 7, "x")        // -> "7-x"

错误处理三板斧(重点)

Yaklang 库函数普遍把最后一个返回值约定为 error。三种等价处理:

// 1) 手动判断 (最显式, 可自定义降级)
ret, err = codec.DecodeBase64(s)
if err != nil { /* 降级或 return */ }

// 2) die: err 非 nil 才 panic
ret, err = codec.DecodeBase64(s)
die(err)

// 3) ~ 波浪号 (WavyCall): 出错即自动 panic, "出错就该终止"时最简洁
ret = codec.DecodeBase64(s)~

崩溃捕获用 defer + recover:

defer func {
    e = recover()
    if e != nil { log.error("caught: %v", e) }
}

完整可运行示例:examples/error-handling.yak

5. 真实存在的"坑"(写 Yaklang 前必读)

这些是实测踩出来的,AI 写 Yaklang 时极易出错:

坑错误写法正确写法
for-range 用 _ 占位会让值变 undefinedfor _, v in slice { total += v }for v in slice { ... }(单变量即元素值)或 for i, v in slice 用真实索引名
箭头函数表达式体不被解析f = (x) => x * 2f = (x) => { return x * 2 }
double 等可能是内置标识符double = ... 触发 compile error换名,如 twice / dbl
内置随机字节函数不叫 RandomBytescodec.RandomBytes(n)用 codec.Md5(sprintf("%d", time.Now().UnixNano())) 等替代或自行构造
recover 后想返回值,但 panic 已跳过 return在外层 defer recover 再 return result(不会执行)把易崩逻辑放进内层 run(),recover 在内层捕获,外层照常 return

不确定某个 API/语法时,用 desc(对象) 在脚本里查看其方法,或 go run common/yak/cmd/yak.go xxx.yak 直接试。以认真查阅为荣,以暗猜接口为耻。

6. 验证

cd /Users/v1ll4n/Projects/yaklang
go run common/yak/cmd/yak.go skills/yaklang-syntax/examples/syntax-tour.yak
go run common/yak/cmd/yak.go skills/yaklang-syntax/examples/error-handling.yak

每个示例应:assert 全过、log 全英文、出现 ... self test passed。

参考来源

  • yaklang-ai-training-materials/basic-syntax: cap3 变量与表达式 / cap4 控制流 / cap5 函数 / cap6-2 错误处理 / cap6-5 fuzztag
  • yaklang.github.io 官方语法文档

FAQ

What does the yaklang-syntax skill do?

Yaklang DSL 语法案例。当用户需要写或读懂 Yaklang (.yak) 代码时使用:变量与类型、切片/map、控制流、函数(func/箭头/闭包/可变参数/多返回值)、字符串模板 f-string、以及错误处理三板斧( 波浪号 / if err / defer recover)。包含可直接运行的语法巡览与错误处理示例。

How do I install yaklang-syntax?

Run npx skills add https://github.com/yaklang/yak-skills --skill yaklang-syntax in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/yaklang-syntax/ (personal) or .claude/skills/yaklang-syntax/ (project).

Which AI agents can use yaklang-syntax?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is yaklang-syntax safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains yaklang-syntax?

It is published by yaklang in yaklang/yak-skills. It has 120 recorded installs.

More from yaklang/yak-skills

View all →

mitm-hotpatch

yaklang/yak-skills

Yakit MITM 热加载 (Hot Patch) 专题。当用户需要在 MITM 中间人代理中用代码动态劫持/修改请求与响应、镜像分析流量、入库前打标签染色、或对危险操作做 mock 护栏时使用。覆盖 hijackHTTPRequest / hijackHTTPResponseEx / mirror 系列 / hijackSaveHTTPFlow / mockHTTPRequest 全部 Hook 与 forward/drop 语义。

125 installs

global-hotpatch

yaklang/yak-skills

Yakit 全局热加载 (Global Hot Patch) 专题。当用户需要一处配置、让 MITM 与所有 Web Fuzzer Tab 共享同一套 hook 时使用:全站透明加解密、统一签名/认证注入、动态 challenge 应答、全站染色脱敏、危险操作护栏。全局 hook 先于模块 hook 执行,同时只能启用一个。复用 beforeRequest / afterRequest / hijackHTTPRequest / hijackSaveHTTPFlow / mockHTTPRequest。

124 installs

yak

yaklang/yak-skills

Open the skill to read its SKILL.md instructions.

124 installs

webfuzzer-hotpatch

yaklang/yak-skills

Yakit Web Fuzzer 热加载 (Hot Patch) 专题。当用户需要在 Web Fuzzer 单 Tab 发包时用代码自动加解密请求/响应、注入签名、智能重试、自定义业务失败判定、用 fuzztag 动态生成 payload、或从响应提取参数做关联测试时使用。覆盖 beforeRequest / afterRequest / retryHandler / customFailureChecker / mirrorHTTPFlow / mockHTTPRequest 与 {{yak(...)}} fuzztag。

123 installs

yaklang-database

yaklang/yak-skills

Yaklang 数据库操作 (db 库) 专题。当用户需要在脚本/插件里持久化或查询数据时使用:临时 SQLite 建表与增删改查 (db.OpenTempSqliteDatabase / db.ScanResult / Exec)、跨脚本共享配置的键值存储 (db.SetKey/GetKey/DelKey/SetKeyWithTTL)、爆破字典统一管理 (db.SavePayload/YieldPayload)、以及项目级配置 (db.SetProjectKey/GetProjectKey)。

Data & Databases121 installs

yakit-data-extract-plugin

yaklang/yak-skills

解决一个高频实战痛点:在 Yakit History 里积累了某站点大量流量后,如何一键按域名捞取所有唯一 路径、拿到登录 Cookie,并把这些路径沉淀成可复用的 Payload 字典,再带着登录态逐路径发包扫描/Fuzz。 覆盖 db.QueryHTTPFlowsByKeyword 捞 History、URI 去重、Cookie 提取、db.SavePayload/YieldPayload 字典管理、poc.HTTP 登录态发包。当用户想"从历史流量提取数据驱动后续扫描"时使用。

121 installs

Popular other skills

View category →

hyperframes-cli

heygen-com/hyperframes

The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.

1.3M installs

triage

mattpocock/skills

Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.

1M installs

ask-matt

mattpocock/skills

Ask which skill or flow fits your situation. A router over the skills in this repo.

778.4K installs

to-questionnaire

mattpocock/skills

Turn a decision you can't fully answer into a questionnaire for someone else to fill in.

508.9K installs

wait-what

mattpocock/skills

Stop. That last message did not land: re-pitch it.

459.7K installs

loop-me

mattpocock/skills

Grill me about specs for the workflows I want to build, within this workspace.

447.9K installs