osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Indented multi-line strings (was: "Data blocks" syntax specification draft)


> 
> > Personally though, I would not hard code it to knock out 4 leading
> > spaces.   I would have it handle spaces the same was that the existing
> > parser does, if there are 4 spaces indending the next line, then it
> > removes 4 spaces, if there are 6 spaces, it removes 6 spaces, etc...
> > ignoring additional spaces within the data-string object.  Once it
> > hits a line that has the same number if indenting spaces as the
> > initial token, the data-string object is finished.
> 
> How about this?
> 
>     x = ''''
>         Here is a multi-line string
>             with
>           indentation.
>         ''''
> 
> This would be equivalent to
> 
>     x = 'Here is a multi-line string\n    with\n  indentation.'
> 

Looks right to me, I don't know if the quad quote overloads the ' and " character too much, but I'm not against it.


> Rules:
> 
>  * The leading and trailing '''' must be aligned vertically.
>  * The contents of the string must be indented at least as far as the
>    delimiters (and with consistent tabs/spaces).
>    This leading white space is ignored.
>  * All the leading white space beyond this 'left edge' is preserved.
>  * The newlines after the leading '''' and before the trailing '''' are
>    ignored, all the others preserved. (I thought about preserving the
>    trailing newline, but it is easier to add one than remove one.)
> 
>         hp
> 
> 


These sound good to me.