c3c icon indicating copy to clipboard operation
c3c copied to clipboard

[Feat] loosen up doc-string syntax

Open BWindey opened this issue 7 months ago • 9 comments

Currently it is not possible to split the expression and/or description of @param, @return and @require over multiple lines.

It would be great if we could do something like:

<*
    @require arg1 <= 0 && arg2 >= 0 : 
        "This function requires arg1 to be negative, and arg2 to be positive"
*>

A more complex example:

<*
    @require argument_1 & 0b1110_0000 == 0b1100_0000
        || argument_2 & 0b1100_0000 == 0b0100_0000 
        : "argument_1 should point to start of UTF8 2-byte character "
          "or argument_2 should point to start of UTF8 1-byte character"
*>

I don't know how much freedom would be possible while staying with C3s goals, but it would be great if this could be looked into.

BWindey avatar Apr 27 '25 12:04 BWindey

<*
 @require arg1 <= 0 && arg2 >= 0 
   :  "This function requires arg1 to be negative, and arg2 to be positive"
   :  "Blah blah"  
*>

This could probably be made to parse correctly

But I think that more complex ones should be moved to macros.

lerno avatar Apr 27 '25 23:04 lerno

I agree that complex logic should be made into a macro.

BWindey avatar May 02 '25 19:05 BWindey

So what syntax would you prefer?

lerno avatar May 04 '25 23:05 lerno

<* @require arg1 <= 0 && arg2 >= 0 : "This function requires arg1 to be negative, and arg2 to be positive" : "Blah blah"
*>

This syntax is fine. Putting a : at the beginning of each line keeps it clear that you're still doing an explanation-string.

BWindey avatar May 05 '25 06:05 BWindey

@BWindey Just continuing with a string like "..." would be equally simple.

lerno avatar May 08 '25 11:05 lerno

How do you mean?

BWindey avatar May 08 '25 12:05 BWindey

Like this:

<*
    @require arg1 <= 0 && arg2 >= 0 : 
        "This function requires arg1 to be negative,"
        " and arg2 to be positive"
*>

lerno avatar May 08 '25 12:05 lerno

That's good for me as well. I'll leave that up to you, as you know your language better then I do.

BWindey avatar May 08 '25 13:05 BWindey

Update from the poll on Discord: the people have decided that the syntax with just 1 : is preferable.

BWindey avatar Jun 02 '25 16:06 BWindey

It's implemented now. Please try it out.

lerno avatar Jul 10 '25 23:07 lerno

Yes, that works now:

<*
    @require @somthing() : 
        "Helo"
        "fiew"
*>

BWindey avatar Jul 11 '25 15:07 BWindey