Commit 442d0b4f

442d0b4f2363Merged

Ryan Seys <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

feat(parse): rewrite .send same as .send

send is CRuby's overrides-resistant alias of send; semantically identical for Spinel's static dispatch (the public/private visibility distinction is not modelled). Add the two .send arms to rewrite_syntax_sugar so .send(:foo, args) and .send("foo", args) lower to .foo(args) at parse time.

  • spinel_parse.c: add .send(: and .send(" arms, sharing the same rewrite path as the .send arms (quote-tracking for parens inside string args, digit-leading name guard, [ / ] for operator-method rewriting).

Test: send_double_underscore.rb exercises both symbol- and string-form send calls with mixed arities.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
442d0b4f2363
Parent
1b54a7ef4eab

spinel_parse.cmodifiedView file

@@ -1551,6 +1551,17 @@
15511551 REWRITE_SEND_CALL(".send(\"", 7, 1);
15521552 continue;
15531553 }
1554+ /* .__send__(:foo, args) → .foo(args). CRuby's overrides-resistant
1555+ alias of send; semantically identical for Spinel's static dispatch. */
1556+ if (i + 11 < len && strncmp(source + i, ".__send__(:", 11) == 0) {
1557+ REWRITE_SEND_CALL(".__send__(:", 11, 0);
1558+ continue;
1559+ }
1560+ /* .__send__("foo", args) → .foo(args). String-form variant. */
1561+ if (i + 11 < len && strncmp(source + i, ".__send__(\"", 11) == 0) {
1562+ REWRITE_SEND_CALL(".__send__(\"", 11, 1);
1563+ continue;
1564+ }
15541565 /* (&:symbol) → { |_spx| _spx.symbol } — also remove enclosing parens */
15551566 if (i + 2 < len && source[i] == '&' && source[i + 1] == ':') {
15561567 /* Check if preceded by ( and remove it */