Parse `` `var`[^key] `` in `` *…* `` segments and quoted strings as an Index part (chained `` [^a][^b] `` folds into one part) in both the tree-walk interpreter and the bytecode compiler, and render it back in `view`. Also make bytecode `_type` stamping always overwrite like the interpreter does, so child constructors yield the most specific type. Adds gold/unit tests for interp footnote indexing and a bytecode inherit-explicit-super case. Co-authored-by: Cursor <cursoragent@cursor.com>
2.5 KiB
2.5 KiB
调用实参:具名与位置
| 状态 | 已定(v0.1 增补) |
| 日期 | 2026-08-07 |
| 相关 | markdown-mapping.md · keywords.md · module-namespace.md |
1. 目标
> 调用同时支持:
| 形式 | 示例 | 说明 |
|---|---|---|
| 具名(保留) | > 问候 谁=Marqdo |
名=值;值可含空格(至下一 名=) |
| 位置(新增) | > 问候 Marqdo |
按形参声明顺序绑定 |
二者可混用:位置实参按「尚未被具名绑定的形参」从左到右填充。具名不可绑定同一形参两次;位置实参不得出现在「已出现具名实参」之后(对齐常见「位置在前、关键字在后」习惯)。
2. 文法(调用尾部)
call_tail ::= callee arg*
arg ::= named | positional
named ::= ident '=' value
positional ::= value_token
value(具名右侧):可含空格与`var`插值,直到下一个ident=边界。value_token(位置):空白分隔的一个词法单元——数字、`名`、标识/文本词;不含空格。多词字符串请用具名,例如> print text=Hello World!。- 实参值中
`变量`后紧跟[^…]时按脚注取元解析(可链式),而非文本:> print text=苹果单价:水果价格[^苹果]、> print text=订单[^2][^品名]。 - 独立
>调用:裸词 = 文本字面量。 *…*/**…**段内的调用(如*x = > text.split value=src sep=","*):裸词 = 变量(Python 统一命名空间),文本字面量必须加引号(value="a,b");`名`变量形式仍合法。- 内置
print/打印形参:text≡内容。 input/输入:prompt≡提示。len/长度、str/文本、int/整数:value≡值。- 完整中英双名见 keywords-i18n.md。
3. 绑定算法
- 收集具名 → 映射;冲突则报错。
- 按函数形参表顺序:若具名已提供则用之,否则取下一个位置实参。
- 位置实参有余、或必填形参仍缺 → 报错(内置
input的prompt可缺省)。 - 用户函数:额外具名键仍写入调用环境(便于扩展);位置实参不可超过形参数目。
4. 金样例
见 tests/structure/positional-call.mq.md、tests/structure/ns/(点号路径 / use)与 tests/structure/import/(导入解析)。