ffi M1.0 (3/3): accept '=>' body in '#objc_class' member methods
Extends parseForeignClassDecl ([src/parser.zig:1262]) with an arrow arm that mirrors the existing parseFnDecl shape — single- expression body wrapped in a one-statement block so downstream lowering sees the same AST as a brace-body method. Closes the M1.0 surface: '=> expr;' is now valid for top-level functions, struct methods, AND '#objc_class' member methods. The sx-defined class lowering (A.7 dispatch gate) is still gated, so 140-expression-bodied-objc-method.sx exercises parse-only — the body is reachable but the method is never invoked. When M1.2 lights up sx-defined class instantiation, the arrow-body form will flow through unchanged. 169 examples pass (+1 from 140 now green); zig build test green.
This commit is contained in:
@@ -1256,11 +1256,19 @@ pub const Parser = struct {
|
||||
}
|
||||
|
||||
// Method body is optional: `;` → declaration (foreign or inherited
|
||||
// method we just want to call); `{ ... }` → sx-side implementation
|
||||
// for sx-defined classes.
|
||||
// method we just want to call); `{ ... }` → sx-side block body
|
||||
// for sx-defined classes; `=> expr;` → expression-body form
|
||||
// (M1.0), lowered as a single-statement block holding `expr`.
|
||||
var body_node: ?*Node = null;
|
||||
if (self.current.tag == .l_brace) {
|
||||
body_node = try self.parseBlock();
|
||||
} else if (self.current.tag == .fat_arrow) {
|
||||
self.advance();
|
||||
const expr = try self.parseExpr();
|
||||
try self.expect(.semicolon);
|
||||
const stmts = try self.allocator.alloc(*Node, 1);
|
||||
stmts[0] = expr;
|
||||
body_node = try self.createNode(expr.span.start, .{ .block = .{ .stmts = stmts } });
|
||||
} else {
|
||||
try self.expect(.semicolon);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
1
|
||||
0
|
||||
|
||||
@@ -1 +1 @@
|
||||
/Users/agra/projects/sx/examples/140-expression-bodied-objc-method.sx:15:35: error: expected ';'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user