Aha: visualizing code generation

24 views
Skip to first unread message

Edward K. Ream

unread,
Nov 25, 2021, 5:47:53 AM11/25/21
to leo-editor
When I awoke this morning I knew it was time to start work again on the code generator. Sitting in meditation would have no chance of being helpful.

But as I was making coffee I realized that a table of the expected results is the long-sought missing piece of the puzzle. I wasn't sure what form that table would take. Happily, a few minutes of experimentation showed that a slight modification of the MORE representation of an outline would likely do the trick.

As usual, lines starting with '-' denote nodes, with the indentation of those lines denoting outline level. All other lines denote the unindented body text. But headlines must also denote the type of expected node. For example: org:Declarations denotes a node whose headline is "Declarations" and whose vnode_info "kind" is "org". At present, the valid types are outer, org, class, def. I might add 'method'.

The line "# Expect:" separates the input lines from the MORE representation of the output nodes.

Here are the first three cases I created. They are just Leo nodes:

Node 1: (headline: docstring, vars, body follows):

"""A docstring"""
switch = 1

# Expect:
    
- outer:root
@others
  - org:Declarations
"""A docstring"""
switch = 1


Node 2: docstring, vars, outer def

"""A docstring"""
switch = 1

def d1:
    pass

# Expect:
    
- outer:root
  - org:Declarations
"""A docstring"""
switch = 1
  - def:function: d1
def d1:
    pass

Node 3: docstring, vars, class

"""A docstring"""
switch = 1

class Class1:
    def method1(self):
        pass

# Expect:
    
- outer:root
  - Declarations
"""A docstring"""
switch = 1
  - class:class Class1
class Class1:
    @others
    - def: method1:
def method1(self):
    pass


I think you get the idea. I expect to create dozens of such nodes.

Now, for the first time, there is an organizable table (a Leo outline) of cases. Clearly, this table corresponds to unit tests.  Even better, a simple Leo script could create the corresponding unit tests!

I think this qualifies as a conceptual and operational breakthrough.

Edward

Edward K. Ream

unread,
Nov 25, 2021, 5:52:51 AM11/25/21
to leo-editor
On Thursday, November 25, 2021 at 4:47:53 AM UTC-6 Edward K. Ream wrote:

Here are the first three cases I created. They are just Leo nodes:

The second and third nodes should have @others as the body text of the root node. And the tests themselves could be a bit more varied :-) No matter, I now have a way of organizing test cases!

Edward

Edward K. Ream

unread,
Nov 25, 2021, 5:58:18 AM11/25/21
to leo-editor
On Thursday, November 25, 2021 at 4:52:51 AM UTC-6 Edward K. Ream wrote:

> The second and third nodes should have @others as the body text of the root node...No matter, I now have a way of organizing test cases!

Furthermore, the second and third nodes should indicate a blank line after the line `switch = 1`.  Do you see how cool this is?  It will be far easier to tweak the nodes of the "table" than to tweak the unit tests themselves!

Alternatively, the unit tests could be driven directly from the entries in the table!  This corresponds to building the "conversion script" into the TestPython class!

Edward
Reply all
Reply to author
Forward
0 new messages