| Home | Trees | Indices | Help |
|---|
|
|
Support for S-expression ASTs using subclasses of Python's list class.
The general support works with any nested iterables (except strings).
|
|||
|
List Extend a list for use in ASTs. |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
clone_sexpr = sexpr_fold()Clone a set of listed iterables. |
|||
count_sexpr = sexpr_fold(per_list= lambda type_, items: sum(itCount the number of value nodes in an AST. |
|||
join = lambda items:Flatten a list of lists by one level, so [[1],[2, [3]]] becomes [1,2,[3]]. |
|||
sexpr_flatten = sexpr_fold(per_list= lambda type_, items: joinFlatten a list completely, so [[1],[2, [3]]] becomes [1,2,3] |
|||
_fmt = {}
|
|||
sexpr_to_str = sexpr_fold(per_list= lambda type_, items: fmt(_A flat representation of nested lists (a set of constructors). |
|||
|
|||
We need some kind of fold-like procedure for generalising operations on arbitrarily nested iterables. We can't use a normal fold because Python doesn't have the equivalent of cons, etc; this tries to be more Pythonic (see comments later). We divide everything into iterables ("lists") and atomic values ("items"). per_list is called with a generator over the (transformed) top-most list, in order. Items (ie atomic values) in that list, when requested from the generator, will be processed by per_item; iterables will be processed by a separate call to per_list (ie recursively). So this is more like a recursive map than a fold, but with Python's mutable state and lack of typing it appears to be equally powerful. Note that per_list is passed the previous type, which can be used for dispatching operations. |
Generate a tree using the same "trick" as GraphStr. The initial fold returns a function (str, str) -> list(str) at each level. |
|
|
|||
count_sexprCount the number of value nodes in an AST. (Note that size(List) gives the number of entries in that list, counting each sublist as "1", while this descends embedded lists, counting their non-iterable contents.
|
joinFlatten a list of lists by one level, so [[1],[2, [3]]] becomes [1,2,[3]]. Note: this will only work correctly if all entries are lists.
|
sexpr_flattenFlatten a list completely, so [[1],[2, [3]]] becomes [1,2,3]
|
sexpr_to_strA flat representation of nested lists (a set of constructors).
|
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Jun 9 21:50:50 2012 | http://epydoc.sourceforge.net |