feat(markup): bracket-marked calls with pre_modifiers

Stabilize `mod… [callee] args` (modifiers → name=True) alongside link-index
disambiguation; expand in interp/bytecode, show in view, and document lib/view
code-as-docs waves before stdlib rewrite.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-14 11:33:11 +08:00
1 parent 5058f5ddcf
commit 0e0655b316
17 files changed
+676 -56

No files matched your search

+35
View File
@@ -118,6 +118,41 @@ pub struct CallExpr {
/// When set, `` `recv`.callee `` method call; receiver is a variable name.
pub receiver: Option<String>,
pub args: Vec<Arg>,
/// Pre-bracket modifiers: `礼貌 [问候] x` → `["礼貌"]`, expanded to `礼貌=True` at eval.
/// See [bracket-call-modifiers.md](../../doc/design/bracket-call-modifiers.md).
pub pre_modifiers: Vec<String>,
}
impl CallExpr {
/// Fold `pre_modifiers` into leading `name=True` named args (conflicts → Err).
pub fn with_modifiers_expanded(&self) -> Result<CallExpr, String> {
let mut call = self.clone();
for m in &call.pre_modifiers {
if call
.args
.iter()
.any(|a| matches!(a, Arg::Named { name, .. } if name == m))
{
return Err(format!(
"pre-bracket modifier `{m}` conflicts with named argument `{m}`"
));
}
}
if call.pre_modifiers.is_empty() {
return Ok(call);
}
let mut args = Vec::with_capacity(call.pre_modifiers.len() + call.args.len());
for m in &call.pre_modifiers {
args.push(Arg::Named {
name: m.clone(),
value: Expr::Literal(Literal::Bool(true)),
});
}
args.append(&mut call.args);
call.args = args;
call.pre_modifiers.clear();
Ok(call)
}
}
#[derive(Debug, Clone)]