Support footnote indexing inside interpolated call args and strings
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>
This commit is contained in:
1 parent
d7924ea8c7
commit
b84e82eb56
10 files changed
+247
-6
No files matched your search
@@ -830,6 +830,19 @@ impl<'a> FnCompiler<'a> {
|
||||
.ok_or_else(|| self.err(format!("undefined variable `{n}`")))?;
|
||||
self.emit(Op::GetLocal(slot));
|
||||
}
|
||||
InterpPart::Index { base, labels } => {
|
||||
let slot = self
|
||||
.locals
|
||||
.get(base)
|
||||
.copied()
|
||||
.ok_or_else(|| self.err(format!("undefined variable `{base}`")))?;
|
||||
self.emit(Op::GetLocal(slot));
|
||||
for label in labels {
|
||||
let li = self.add_const(Value::Text(label.clone()));
|
||||
self.emit(Op::Constant(li));
|
||||
self.emit(Op::FootnoteGet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if idx > 0 {
|
||||
self.emit(Op::Add);
|
||||
|
||||
+4
-3
@@ -658,9 +658,10 @@ fn instance_type_name_bc(v: &Value) -> Result<String, String> {
|
||||
fn tag_instance_value(type_name: &str, value: Value) -> Value {
|
||||
match value {
|
||||
Value::Map(mut entries) => {
|
||||
if !entries.iter().any(|(k, _)| k == "_type") {
|
||||
entries.insert(0, ("_type".into(), Value::Text(type_name.into())));
|
||||
}
|
||||
// Always stamp the constructed type so an explicit `` `self` = > Parent ``
|
||||
// inside a child constructor still yields the most specific `_type`.
|
||||
entries.retain(|(k, _)| k != "_type");
|
||||
entries.insert(0, ("_type".into(), Value::Text(type_name.into())));
|
||||
Value::Map(entries)
|
||||
}
|
||||
Value::None => Value::Map(vec![("_type".into(), Value::Text(type_name.into()))]),
|
||||
|
||||
Reference in new issue
Block a user