feat(lang): implement RFC-LANG-0002 unified semantics (breaking)
One Markdown-to-program mapping, no version selector or legacy mapper. Frontend/runtime: - resolve @exec/@knowledge heading declarations with nearest-ancestor inheritance; only an Exec H2 is callable; add UnitKind::Knowledge and sem.* diagnostics (mode marker, unit name, exec-without-function, payload nesting/empty, syntax, control stack, params position, version directive, inferred-signature lint) - extract Strong/Emph/inline Code as one-statement carriers, refuse nested carriers, and honour heading segment boundaries so an if/while cannot be closed across a heading - lower if/else/while/end to the existing Branch/Loop/Return IR with a compile-time control stack; keep payload-relative source spans through expression parsing and rewrite them onto the file - accept params(...) only as the first direct Exec H2 payload; keep the existing free-variable inference and named-only rule for inferred signatures; fix duplicate-mode/else/end and Knowledge-body inertness - reject marqdo_semantics/syntax front matter directives Data and tests: - migrate stdlib/**/*.mq.md, regenerate stdlib.json digest - migrate examples and the full semantics/negative/runtime corpus to the only current syntax; expected values/runtime codes preserved - migrate Rust-embedded .mq.md fixtures, init template, CLI help and security-lane fixtures Verified: cargo fmt --check, cargo clippy -D warnings and cargo test --workspace --locked (green).
This commit is contained in:
1 parent
49835424ee
commit
e029853e32
375 files changed
+6591
-4790
No files matched your search
+264
-181
@@ -1,224 +1,260 @@
|
||||
|
||||
# @exec regex
|
||||
## 成功
|
||||
|
||||
`(值)`
|
||||
`params(值)`
|
||||
|
||||
*{ok: true, value: 值}*
|
||||
`return {ok: true, value: 值}`
|
||||
|
||||
## 失败
|
||||
|
||||
`(代码, 消息)`
|
||||
`params(代码, 消息)`
|
||||
|
||||
*{ok: false, code: 代码, message: 消息}*
|
||||
`return {ok: false, code: 代码, message: 消息}`
|
||||
|
||||
## 包含
|
||||
|
||||
`(列表, 值)`
|
||||
`params(列表, 值)`
|
||||
|
||||
**结果 = false**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(列表) and not 结果`
|
||||
`while 下标 < 长度(列表) and not 结果`
|
||||
|
||||
1. `列表[下标] == 值`
|
||||
`if 列表[下标] == 值`
|
||||
|
||||
**结果 = true**
|
||||
**结果 = true**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 去头
|
||||
|
||||
`(列表)`
|
||||
`params(列表)`
|
||||
|
||||
**结果 = []**
|
||||
|
||||
**下标 = 1**
|
||||
|
||||
- `下标 < 长度(列表)`
|
||||
`while 下标 < 长度(列表)`
|
||||
|
||||
**结果 = list.append(结果, 列表[下标])**
|
||||
**结果 = list.append(结果, 列表[下标])**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 设置最后
|
||||
|
||||
`(列表, 值)`
|
||||
`params(列表, 值)`
|
||||
|
||||
**结果 = []**
|
||||
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 长度(列表)`
|
||||
`while 下标 < 长度(列表)`
|
||||
|
||||
1. `下标 + 1 == 长度(列表)`
|
||||
`if 下标 + 1 == 长度(列表)`
|
||||
|
||||
**结果 = list.append(结果, 值)**
|
||||
**结果 = list.append(结果, 值)**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**结果 = list.append(结果, 列表[下标])**
|
||||
**结果 = list.append(结果, 列表[下标])**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 片段
|
||||
|
||||
`(点, 起点, 终点)`
|
||||
`params(点, 起点, 终点)`
|
||||
|
||||
**结果 = ""**
|
||||
|
||||
**下标 = 起点**
|
||||
|
||||
- `下标 < 终点`
|
||||
`while 下标 < 终点`
|
||||
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
**结果 = 结果 + text.from_codepoint(点[下标])**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*结果*
|
||||
`end`
|
||||
`return 结果`
|
||||
|
||||
## 是数字
|
||||
|
||||
`(码点)`
|
||||
`params(码点)`
|
||||
|
||||
*码点 >= 48 and 码点 <= 57*
|
||||
`return 码点 >= 48 and 码点 <= 57`
|
||||
|
||||
## 字面令牌
|
||||
|
||||
`(码点)`
|
||||
`params(码点)`
|
||||
|
||||
包含数量词,默认恰好一次。
|
||||
|
||||
*{kind: "literal", value: 码点, neg: false, min: 1, max: 1}*
|
||||
`return {kind: "literal", value: 码点, neg: false, min: 1, max: 1}`
|
||||
|
||||
## 任意令牌
|
||||
|
||||
`()`
|
||||
`params()`
|
||||
|
||||
*{kind: "any", value: 0, neg: false, min: 1, max: 1}*
|
||||
`return {kind: "any", value: 0, neg: false, min: 1, max: 1}`
|
||||
|
||||
## 类令牌
|
||||
|
||||
`(集合, 否定)`
|
||||
`params(集合, 否定)`
|
||||
|
||||
*{kind: "class", value: 集合, neg: 否定, min: 1, max: 1}*
|
||||
`return {kind: "class", value: 集合, neg: 否定, min: 1, max: 1}`
|
||||
|
||||
## 锚点令牌
|
||||
|
||||
`(方向)`
|
||||
`params(方向)`
|
||||
|
||||
*{kind: "anchor", value: 方向, neg: false, min: 1, max: 1}*
|
||||
`return {kind: "anchor", value: 方向, neg: false, min: 1, max: 1}`
|
||||
|
||||
## 设置量词
|
||||
|
||||
`(令牌, 码点)`
|
||||
`params(令牌, 码点)`
|
||||
|
||||
1. `码点 == 42`
|
||||
`if 码点 == 42`
|
||||
|
||||
*{kind: 令牌.kind, value: 令牌.value, neg: 令牌.neg, min: 0, max: -1}*
|
||||
`return {kind: 令牌.kind, value: 令牌.value, neg: 令牌.neg, min: 0, max: -1}`
|
||||
|
||||
2. `码点 == 43`
|
||||
`else`
|
||||
`if 码点 == 43`
|
||||
|
||||
*{kind: 令牌.kind, value: 令牌.value, neg: 令牌.neg, min: 1, max: -1}*
|
||||
`return {kind: 令牌.kind, value: 令牌.value, neg: 令牌.neg, min: 1, max: -1}`
|
||||
|
||||
*{kind: 令牌.kind, value: 令牌.value, neg: 令牌.neg, min: 0, max: 1}*
|
||||
`end`
|
||||
`end`
|
||||
`return {kind: 令牌.kind, value: 令牌.value, neg: 令牌.neg, min: 0, max: 1}`
|
||||
|
||||
## 编译类
|
||||
|
||||
`(点, 位置)`
|
||||
`params(点, 位置)`
|
||||
|
||||
**当前 = 位置 + 1**
|
||||
|
||||
**否定 = false**
|
||||
|
||||
1. `当前 < 长度(点) and 点[当前] == 94`
|
||||
`if 当前 < 长度(点) and 点[当前] == 94`
|
||||
|
||||
**否定 = true**
|
||||
**否定 = true**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略否定 = 0**
|
||||
**忽略否定 = 0**
|
||||
|
||||
`end`
|
||||
`end`
|
||||
**集合 = []**
|
||||
|
||||
**完成 = false**
|
||||
|
||||
**错误 = ""**
|
||||
|
||||
- `当前 < 长度(点) and not 完成 and 错误 == ""`
|
||||
`while 当前 < 长度(点) and not 完成 and 错误 == ""`
|
||||
|
||||
**码点 = 点[当前]**
|
||||
**码点 = 点[当前]**
|
||||
|
||||
1. `码点 == 93`
|
||||
`if 码点 == 93`
|
||||
|
||||
**完成 = true**
|
||||
**完成 = true**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
2. `码点 == 92`
|
||||
`else`
|
||||
`if 码点 == 92`
|
||||
|
||||
1. `当前 + 1 >= 长度(点)`
|
||||
`if 当前 + 1 >= 长度(点)`
|
||||
|
||||
**错误 = "regex.invalid"**
|
||||
**错误 = "regex.invalid"**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**集合 = list.append(集合, 点[当前 + 1])**
|
||||
**集合 = list.append(集合, 点[当前 + 1])**
|
||||
|
||||
**当前 = 当前 + 2**
|
||||
**当前 = 当前 + 2**
|
||||
|
||||
3. `当前 + 2 < 长度(点) and 点[当前 + 1] == 45 and 点[当前 + 2] != 93`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 当前 + 2 < 长度(点) and 点[当前 + 1] == 45 and 点[当前 + 2] != 93`
|
||||
|
||||
**开始 = 码点**
|
||||
**开始 = 码点**
|
||||
|
||||
**结束 = 点[当前 + 2]**
|
||||
**结束 = 点[当前 + 2]**
|
||||
|
||||
1. `开始 > 结束`
|
||||
`if 开始 > 结束`
|
||||
|
||||
**错误 = "regex.invalid"**
|
||||
**错误 = "regex.invalid"**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**值 = 开始**
|
||||
**值 = 开始**
|
||||
|
||||
- `值 <= 结束`
|
||||
`while 值 <= 结束`
|
||||
|
||||
**集合 = list.append(集合, 值)**
|
||||
**集合 = list.append(集合, 值)**
|
||||
|
||||
**值 = 值 + 1**
|
||||
**值 = 值 + 1**
|
||||
|
||||
**当前 = 当前 + 3**
|
||||
`end`
|
||||
**当前 = 当前 + 3**
|
||||
|
||||
4. `true`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**集合 = list.append(集合, 码点)**
|
||||
**集合 = list.append(集合, 码点)**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
1. `not 完成`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`if not 完成`
|
||||
|
||||
*失败("regex.invalid", "字符类未闭合")*
|
||||
`return 失败("regex.invalid", "字符类未闭合")`
|
||||
|
||||
1. `错误 != ""`
|
||||
`else`
|
||||
`if 错误 != ""`
|
||||
|
||||
*失败(错误, "字符类范围无效")*
|
||||
`return 失败(错误, "字符类范围无效")`
|
||||
|
||||
*成功({set: 集合, neg: 否定, next: 当前})*
|
||||
`end`
|
||||
`end`
|
||||
`return 成功({set: 集合, neg: 否定, next: 当前})`
|
||||
|
||||
## 编译
|
||||
|
||||
`(点, 位置)`
|
||||
`params(点, 位置)`
|
||||
|
||||
**令牌表 = []**
|
||||
|
||||
@@ -228,189 +264,232 @@
|
||||
|
||||
**代码 = ""**
|
||||
|
||||
- `当前 < 长度(点) and 错误 == ""`
|
||||
`while 当前 < 长度(点) and 错误 == ""`
|
||||
|
||||
**码点 = 点[当前]**
|
||||
**码点 = 点[当前]**
|
||||
|
||||
1. `码点 == 94`
|
||||
`if 码点 == 94`
|
||||
|
||||
**令牌表 = list.append(令牌表, 锚点令牌("start"))**
|
||||
**令牌表 = list.append(令牌表, 锚点令牌("start"))**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
2. `码点 == 36`
|
||||
`else`
|
||||
`if 码点 == 36`
|
||||
|
||||
**令牌表 = list.append(令牌表, 锚点令牌("end"))**
|
||||
**令牌表 = list.append(令牌表, 锚点令牌("end"))**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
3. `码点 == 91`
|
||||
`else`
|
||||
`if 码点 == 91`
|
||||
|
||||
**类结果 = 编译类(点, 当前)**
|
||||
**类结果 = 编译类(点, 当前)**
|
||||
|
||||
1. `not 类结果.ok`
|
||||
`if not 类结果.ok`
|
||||
|
||||
**错误 = 类结果.code**
|
||||
**错误 = 类结果.code**
|
||||
|
||||
**代码 = 类结果.message**
|
||||
**代码 = 类结果.message**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**令牌表 = list.append(令牌表, 类令牌(类结果.value.set, 类结果.value.neg))**
|
||||
**令牌表 = list.append(令牌表, 类令牌(类结果.value.set, 类结果.value.neg))**
|
||||
|
||||
**当前 = 类结果.value.next**
|
||||
**当前 = 类结果.value.next**
|
||||
|
||||
4. `码点 == 92`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 码点 == 92`
|
||||
|
||||
1. `当前 + 1 >= 长度(点)`
|
||||
`if 当前 + 1 >= 长度(点)`
|
||||
|
||||
**错误 = "regex.invalid"**
|
||||
**错误 = "regex.invalid"**
|
||||
|
||||
**代码 = "转义缺少字符"**
|
||||
**代码 = "转义缺少字符"**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**令牌表 = list.append(令牌表, 字面令牌(点[当前 + 1]))**
|
||||
**令牌表 = list.append(令牌表, 字面令牌(点[当前 + 1]))**
|
||||
|
||||
**当前 = 当前 + 2**
|
||||
**当前 = 当前 + 2**
|
||||
|
||||
5. `码点 == 46`
|
||||
`end`
|
||||
`end`
|
||||
`else`
|
||||
`if 码点 == 46`
|
||||
|
||||
**令牌表 = list.append(令牌表, 任意令牌())**
|
||||
**令牌表 = list.append(令牌表, 任意令牌())**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
6. `码点 == 40 or 码点 == 41 or 码点 == 124`
|
||||
`else`
|
||||
`if 码点 == 40 or 码点 == 41 or 码点 == 124`
|
||||
|
||||
**错误 = "regex.unsupported"**
|
||||
**错误 = "regex.unsupported"**
|
||||
|
||||
**代码 = "不支持分组或选择"**
|
||||
**代码 = "不支持分组或选择"**
|
||||
|
||||
7. `码点 == 42 or 码点 == 43 or 码点 == 63`
|
||||
`else`
|
||||
`if 码点 == 42 or 码点 == 43 or 码点 == 63`
|
||||
|
||||
**错误 = "regex.invalid"**
|
||||
**错误 = "regex.invalid"**
|
||||
|
||||
**代码 = "量词没有前一项"**
|
||||
**代码 = "量词没有前一项"**
|
||||
|
||||
8. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**令牌表 = list.append(令牌表, 字面令牌(码点))**
|
||||
**令牌表 = list.append(令牌表, 字面令牌(码点))**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
- `错误 == "" and 当前 < 长度(点) and (点[当前] == 42 or 点[当前] == 43 or 点[当前] == 63)`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`while 错误 == "" and 当前 < 长度(点) and (点[当前] == 42 or 点[当前] == 43 or 点[当前] == 63)`
|
||||
|
||||
**令牌表 = 设置最后(令牌表, 设置量词(令牌表[长度(令牌表) - 1], 点[当前]))**
|
||||
**令牌表 = 设置最后(令牌表, 设置量词(令牌表[长度(令牌表) - 1], 点[当前]))**
|
||||
|
||||
**当前 = 当前 + 1**
|
||||
**当前 = 当前 + 1**
|
||||
|
||||
- `当前 < 长度(点) and (点[当前] == 42 or 点[当前] == 43 or 点[当前] == 63)`
|
||||
`while 当前 < 长度(点) and (点[当前] == 42 or 点[当前] == 43 or 点[当前] == 63)`
|
||||
|
||||
**错误 = "regex.invalid"**
|
||||
**错误 = "regex.invalid"**
|
||||
|
||||
**代码 = "连续量词无效"**
|
||||
**代码 = "连续量词无效"**
|
||||
|
||||
1. `错误 != ""`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`if 错误 != ""`
|
||||
|
||||
*失败(错误, 代码)*
|
||||
`return 失败(错误, 代码)`
|
||||
|
||||
*成功(令牌表)*
|
||||
`end`
|
||||
`return 成功(令牌表)`
|
||||
|
||||
## 单字符匹配
|
||||
|
||||
`(令牌, 码点)`
|
||||
`params(令牌, 码点)`
|
||||
|
||||
**类别 = 令牌.kind**
|
||||
|
||||
1. `类别 == "any"`
|
||||
`if 类别 == "any"`
|
||||
|
||||
*true*
|
||||
`return true`
|
||||
|
||||
2. `类别 == "literal"`
|
||||
`else`
|
||||
`if 类别 == "literal"`
|
||||
|
||||
*令牌.value == 码点*
|
||||
`return 令牌.value == 码点`
|
||||
|
||||
3. `类别 == "class"`
|
||||
`else`
|
||||
`if 类别 == "class"`
|
||||
|
||||
*包含(令牌.value, 码点) != 令牌.neg*
|
||||
`return 包含(令牌.value, 码点) != 令牌.neg`
|
||||
|
||||
*false*
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`return false`
|
||||
|
||||
## 尝试匹配
|
||||
|
||||
`(令牌, 下标, 当前, 点, 位置, 次数, 要求结束)`
|
||||
`params(令牌, 下标, 当前, 点, 位置, 次数, 要求结束)`
|
||||
|
||||
**下限 = 当前.min**
|
||||
|
||||
**上限 = 当前.max**
|
||||
|
||||
1. `次数 >= 下限 and 匹配序列(令牌, 下标 + 1, 点, 位置, 要求结束)`
|
||||
`if 次数 >= 下限 and 匹配序列(令牌, 下标 + 1, 点, 位置, 要求结束)`
|
||||
|
||||
*true*
|
||||
`return true`
|
||||
|
||||
1. `上限 >= 0 and 次数 >= 上限`
|
||||
`else`
|
||||
`if 上限 >= 0 and 次数 >= 上限`
|
||||
|
||||
*false*
|
||||
`return false`
|
||||
|
||||
1. `位置 < 长度(点) and 单字符匹配(当前, 点[位置])`
|
||||
`else`
|
||||
`if 位置 < 长度(点) and 单字符匹配(当前, 点[位置])`
|
||||
|
||||
*尝试匹配(令牌, 下标, 当前, 点, 位置 + 1, 次数 + 1, 要求结束)*
|
||||
`return 尝试匹配(令牌, 下标, 当前, 点, 位置 + 1, 次数 + 1, 要求结束)`
|
||||
|
||||
*false*
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`return false`
|
||||
|
||||
## 匹配序列
|
||||
|
||||
`(令牌, 下标, 点, 位置, 要求结束)`
|
||||
`params(令牌, 下标, 点, 位置, 要求结束)`
|
||||
|
||||
1. `下标 >= 长度(令牌)`
|
||||
`if 下标 >= 长度(令牌)`
|
||||
|
||||
1. `要求结束`
|
||||
`if 要求结束`
|
||||
|
||||
*位置 == 长度(点)*
|
||||
`return 位置 == 长度(点)`
|
||||
|
||||
*true*
|
||||
`end`
|
||||
`return true`
|
||||
|
||||
`end`
|
||||
**当前 = 令牌[下标]**
|
||||
|
||||
1. `当前.kind == "anchor"`
|
||||
`if 当前.kind == "anchor"`
|
||||
|
||||
1. `当前.value == "start" and 位置 == 0`
|
||||
`if 当前.value == "start" and 位置 == 0`
|
||||
|
||||
*匹配序列(令牌, 下标 + 1, 点, 位置, 要求结束)*
|
||||
`return 匹配序列(令牌, 下标 + 1, 点, 位置, 要求结束)`
|
||||
|
||||
2. `当前.value == "end" and 位置 == 长度(点)`
|
||||
`else`
|
||||
`if 当前.value == "end" and 位置 == 长度(点)`
|
||||
|
||||
*匹配序列(令牌, 下标 + 1, 点, 位置, 要求结束)*
|
||||
`return 匹配序列(令牌, 下标 + 1, 点, 位置, 要求结束)`
|
||||
|
||||
*false*
|
||||
`end`
|
||||
`end`
|
||||
`return false`
|
||||
|
||||
*尝试匹配(令牌, 下标, 当前, 点, 位置, 0, 要求结束)*
|
||||
`end`
|
||||
`return 尝试匹配(令牌, 下标, 当前, 点, 位置, 0, 要求结束)`
|
||||
|
||||
## 匹配
|
||||
|
||||
`(模式, 文本)`
|
||||
`params(模式, 文本)`
|
||||
|
||||
编译后要求整个文本匹配。支持 `^`、`$`、`.`、`*`、`+`、`?`、
|
||||
`[...]` 和 `\\` 转义;不支持分组和选择。
|
||||
编译后要求整个文本匹配。支持 ^、$、.、*、+、?、
|
||||
[...] 和 \\ 转义;不支持分组和选择。
|
||||
|
||||
**编译结果 = 编译(text.codepoints(模式), 0)**
|
||||
|
||||
1. `not 编译结果.ok`
|
||||
`if not 编译结果.ok`
|
||||
|
||||
*编译结果*
|
||||
`return 编译结果`
|
||||
|
||||
*{ok: true, value: 匹配序列(编译结果.value, 0, text.codepoints(文本), 0, true)}*
|
||||
`end`
|
||||
`return {ok: true, value: 匹配序列(编译结果.value, 0, text.codepoints(文本), 0, true)}`
|
||||
|
||||
## 搜索
|
||||
|
||||
`(模式, 文本)`
|
||||
`params(模式, 文本)`
|
||||
|
||||
**编译结果 = 编译(text.codepoints(模式), 0)**
|
||||
|
||||
1. `not 编译结果.ok`
|
||||
`if not 编译结果.ok`
|
||||
|
||||
*编译结果*
|
||||
`return 编译结果`
|
||||
|
||||
`end`
|
||||
**令牌 = 编译结果.value**
|
||||
|
||||
**点 = text.codepoints(文本)**
|
||||
@@ -419,40 +498,44 @@
|
||||
|
||||
**结果 = false**
|
||||
|
||||
- `下标 <= 长度(点) and not 结果`
|
||||
`while 下标 <= 长度(点) and not 结果`
|
||||
|
||||
1. `匹配序列(令牌, 0, 点, 下标, false)`
|
||||
`if 匹配序列(令牌, 0, 点, 下标, false)`
|
||||
|
||||
**结果 = true**
|
||||
**结果 = true**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`end`
|
||||
`end`
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
*成功(结果)*
|
||||
`end`
|
||||
`return 成功(结果)`
|
||||
|
||||
## 扩展匹配
|
||||
|
||||
`(模式, 文本)`
|
||||
`params(模式, 文本)`
|
||||
|
||||
使用宿主正则引擎(支持分组、选择、`\\d` 等)判断是否匹配。模式无效时
|
||||
返回 `regex.invalid`。仅项目模式;纯 `.mq.md` 子集仍由 `匹配`/`搜索` 提供。
|
||||
使用宿主正则引擎(支持分组、选择、\\d 等)判断是否匹配。模式无效时
|
||||
返回 regex.invalid。仅项目模式;纯 .mq.md 子集仍由 匹配/搜索 提供。
|
||||
|
||||
*resource.request("regex.match", [模式, 文本])*
|
||||
`return resource.request("regex.match", [模式, 文本])`
|
||||
|
||||
## 扩展搜索
|
||||
|
||||
`(模式, 文本)`
|
||||
`params(模式, 文本)`
|
||||
|
||||
*resource.request("regex.match", [模式, 文本])*
|
||||
`return resource.request("regex.match", [模式, 文本])`
|
||||
|
||||
## 捕获
|
||||
|
||||
`(模式, 文本)`
|
||||
`params(模式, 文本)`
|
||||
|
||||
返回 `{ok:true, value:{matched:Bool, groups:List<Text|None>}}`。下标 0 是
|
||||
完整匹配;未参与匹配的分组是 `None`。
|
||||
返回 {ok:true, value:{matched:Bool, groups:List<Text|None>}}。下标 0 是
|
||||
完整匹配;未参与匹配的分组是 None。
|
||||
|
||||
*resource.request("regex.captures", [模式, 文本])*
|
||||
`return resource.request("regex.captures", [模式, 文本])`
|
||||
Reference in new issue
Block a user