pub(super) fn rewrite_gmegabuf_writes(s: &str) -> StringExpand description
Rewrite gmegabuf(<idx>) = <val> (and megabuf) into
gmegabuf_set(<idx>, <val>). evalexpr’s = operator rejects a
function-call LHS with a confusing “Expected String, got Float” error,
which cascades across the rest of the equation. The two-arg call
shape is well-formed; gmegabuf_set / megabuf_set are registered
as buffer-backed functions in math_functions.rs.
Walker-based, replacing an earlier regex-only implementation. Three gains over the regex:
- Nested parens in
<idx>. The old regex’s[^()=]+?class rejected any(/)inside the index expression, sogmegabuf((bd_src*bd_oct+oct)*2) = bd_qualsilently fell through and tripped evalexpr’s “Expected String, got Float” error. - Compound assignments.
gmegabuf(idx) += val/*=/-=//=are common in the corpus and now expand togmegabuf_set(idx, gmegabuf(idx) <op> val). - Allows whitespace between
nameand(. Corpus presets writegmegabuf (n+1)with a space.