From 8d92810d9a2545d851d5986715a98fda24bb3c3a Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Tue, 3 Nov 2026 09:34:31 -0800 Subject: Early version of safe using partial construciton --- chapter29/docs/29-grammar.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'chapter29/docs/29-grammar.md') diff --git a/chapter29/docs/29-grammar.md b/chapter29/docs/29-grammar.md index 58c9b30c..cb231ce0 100644 --- a/chapter29/docs/29-grammar.md +++ b/chapter29/docs/29-grammar.md @@ -47,7 +47,13 @@ structDeclaration : 'struct' IDENTIFIER '{' structMember* '}' ';' ; structMember : constructorDeclaration | methodDeclaration | statement ; // The constructor name must match the enclosing struct's name. -constructorDeclaration : 'new' IDENTIFIER '=' functionExpression ';' ; +constructorDeclaration : 'new' IDENTIFIER '=' constructorExpression ';' ; +constructorExpression : '{' constructorParameterList? '->' statement* '}' ; +constructorParameterList : (constructorParameter ','?)+ ; +constructorParameter : type '^'? bindingModifier? IDENTIFIER ; +// ^ accepts an unfinished struct reference; ? independently permits null. +// Only self may be read while incomplete; ^ arguments may be stored/forwarded. +// A new result is incomplete iff an actual argument is. See construction-groups.md. // A method is an ordinary fixed function binding in a struct definition. // The compiler supplies self; it is not written in parameterList. -- cgit v1.2.3