On Wed, Nov 24, 2021 at 9:20 AM [email protected] <[email protected]>
wrote:

> On Wednesday, November 24, 2021 at 9:06:21 AM UTC-5 Edward K. Ream wrote:
>
>> *Note*: The leading whitespace (lws) of the @others line will be the lws
>> of the first inner class or def contained in TheClass.
>>
>
> After a class() line, there are two other non-comment, non-blank lines
> that could happen before the first *def* line:
>
> 1. A docstring;
> 2. A class variable assignment
>
> I think the code generator should not overlook these kinds of lines by
> only looking for a *def* line.
>

I agree.  Decorators are another common construct that should determine
indentation.

Your comment gives me the opportunity to point out several things that I
omitted in this post.

1. The two rules will be applied recursively. All the constructs you
mention will create an organizer node *(a node with 'org' kind) without* an
@others directive. The @others in class node would apply to the entire
organizer node.

2. There are special cases that I haven't mentioned. In particular, each
file will start with a *prefix node* (an organizer node without an @others
directive) for all leading lines of the file.  This prefix will include the
module's docstring, imports, and other initial lines. The post pass will
prepend the lines of the prefix node to the start of the root node,
providing the size of the prefix node is less than some threshold.

But as I say, all rules (and special cases?) will be applied recursively,
so class nodes and def nodes could also have prefix nodes.

3. The main code generator's primary focus must be to ensure that all files
are imported perfectly, except possibly for "promoted" under indented
comment lines. The post-pass will then optimize the nodes:

- Move decorators at the end of preceding organizer nodes to the start of
the next class or def node.
- Move tail lines from one node to another.
- Delete nodes that become empty during the post-pass, or nodes that
otherwise would have no effect, such as childless nodes containing only an
@others directive.

4. At the code level, the challenge is to avoid an explosion of cases.
There are at least two "interlocking" sets of tests: one set is a switch on
the preceding node type; the other set is a switch on the relation between
the indentation of the present line and the (cumulative) indentation of the
(parent) node that contains the "ruling" @others directive. Like I said,
the code is tricky.

5. I am using several fairly simple unit tests as development test beds.
These tests allow me to try various ways of untangling the interactions
between previously generated nodes and indentation levels.  As a side
effect, the unit tests should ensure that I have not forgotten the kinds of
special cases you mention.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS1_n1sAEbtzAAnVOZfwBeE2TGjewZH81u_NdFQRDZ7TaQ%40mail.gmail.com.

Reply via email to