Here is a function that generates tuples from the xml content:
def nodes_from_leo_xml(contents):
    '''
    Parses contents as xml Leo document and returns
    a generator of the tuples
    
        (parent_gnx, gnx, childIndex, h, b, ua, descendentUas)

    suitable to be piped to the build_tree function.
    '''
    xroot = read_xml(contents)
    v_elements = xroot.find('vnodes')
    t_elements = xroot.find('tnodes')
    bodies, uas = get_bodies_and_uas(t_elements)
    heads = {}
    def viter(parent_gnx, i, xv):
        gnx = xv.attrib.get('t')
        d_uas = xv.attrib.get('descendentVnodeUnknownAttributes')
        d_uas = d_uas and resolve_ua('xxx', d_uas) # key is not important 
here
        h = heads.get(gnx)
        if not h:
            h = xv[0].text or ''
            heads[gnx] = h
            yield parent_gnx, gnx, i, h, bodies[gnx], uas[gnx], d_uas
            for j, ch in enumerate(xv[1:]):
                yield from viter(gnx, j, ch)
        else:
            yield parent_gnx, gnx, i, heads[gnx], bodies[gnx], uas[gnx], 
d_uas

    for i, xv in enumerate(v_elements):
        yield from viter('hidden-root-vnode-gnx', i, xv)



Now all three paste commands: (paste-node, paste-retaining-clones and 
paste-as-template) can reuse these functions. Each of them will use 
nodes_from_leo_xml to generate tuples and then paste-node will reassign 
on-the-fly all indices, paste-retaining-clones will pass the generated 
tuples without change, and paste-as-template will change some of the 
indices on-the-fly.

The next thing I am going to do is to write a function for generating 
tuples from the external @file files. I hope this function can be used 
inside nodes_from_leo_xml to include tuples from the @file files 
on-the-fly. That way we would have a function to fully load Leo document 
along with all the external files. The same need to be done with the 
importers: create a function which generates tuples from the @auto files. 
Handling the descendentVnodeUnknownAttributes will be the next goal after 
all kinds of external files can generate tuples.

This is far from being production ready, but it shows great potential so 
far.

Vitalije

-- 
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/bd1f535f-9402-4ace-8c40-6ac13635369d%40googlegroups.com.

Reply via email to