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

"Data blocks" syntax specification draft

On Wed, May 23, 2018 at 2:25 AM, Dan Strohl <D.Strohl at f5.com> wrote:

>> Explanation:
>> [here i'll use same symbol /// for the data entry point, but of course it can be
>> changed if a better idea comes later. Also for now, just for simplicity - the rule
>> is that the contents of a block starts always on the new line.
>> So, e.g. this:
>> data = /// s4
>>     first line
>>     last line
>> the rest python code
>> - will parse the block and knock out leading 4 spaces.
>> i.e. if the first line has 5 leading spaces then 1 space will be left in the string.
>> Block parsing terminates when the next line does not satisfy the indent
>> sequence (4 spaces in this case).
> 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 I understand you correctly, then I think I have this option already
i.e. these:

>> data = /// ts
>> - "any whitespace" (mimic current Python behaviour)
>> data = /// s        # or
>> data = /// t
>> - simply count amount of spaces (tabs) from first
>>   line and proceed, otherwise terminate.

Though hard-coded knock-out is also very useful, e.g. for this:

data = /// s4
        First line indented more (8 spaces)
    second - less (4 spaces)
rest code

So this will preserve formatting.

>> data = /// "???"
>> ??? abc foo bar
>> ???
>> - defines indent character by string: crazy idea but why not.
> Nope, don't like this one... It's far enough from Python normal that it seems
> unlikely to not get through, and (personally at least), I struggle to see the benefit.

Heh, that was merely joke - but OTOH one could use it for hard-coded
indent sequences:

data = /// "    "
        First line indented more (8 spaces)
    second - less (4 spaces)
rest code

A bit sloppy look, but it generalizes some uses. But granted - I don't
see much real applications besides than space and tab indented block
anyway - so it's under question.

>> Language  parameter, e.g.:
>> data = /// t1."yaml"
>> -this can be reserved for future usage by code analysis tools or dynamic
>> syntax highlighting.
> I can see where this might be interesting, but again, I just don't see the need,

I think you're right  - if need a directive for some analysis tool then one
can make for example a consideration to precede the whole statement
with a directive, say in a comment:

# lang "yaml"
data = /// t
    first line
    last line

Also I am thinking about this - there might be one useful 'hack".
One could even allow single-line usage, e.g.;
(with a semicolon)

data = /// s2:  first line

- so this would start parsing just after colon :
"pretending it is block.
This may be not so fat-fingered-proof and 'inconsistent',
but in the end of the day, might be a win actually.