On Nov 16, 5:01 am, "Edward K. Ream" <[email protected]> wrote:

> As I write this, I see that the problem is to create a "query
> language" that can be translated into specific AST traversals.  By
> "query language" I mean any mechanism that could produce specific
> searches.  API might be a better word for what I imagine.  In any
> case, creating queries of AST trees creates a new world of
> invention...

Here is the first draft of a design.  Feel free to skip, but if you
are interested, don't miss the last line of this post.

The inspiration will be Mathematica's language: simple and task
oriented. All details in the background. In fact, there won't be any
special query language, just a simple api.

AST trees are part of the plumbing.  Queries will be made against the
**query objects** representing the semantic data created when parsing
AST trees. The present new-lint code is already pretty much what we
need.

Getter functions return query objects, o, or lists of query objects::

    o = module(file_name) # Parses the file into a query object, o.
    aList = assignments(o)
    aList = classes(o)
    aList = defs(o)
    aList = statements(o)
    ast_tree = tree(o)

Assignments are especially important.  Two more getters deliver the
right-hand-side and left-hand-side of an assignment a::

    o = lhs(a)
    o = rhs(a)

The "assignments" getter will split composite assignments a,b = x,y
into separate assignments.

Finally, we'll need a way to view query objects, that is, the
underlying AST.  We'll want a rich set of options so that we can
customize the view::

    aString = format(o,options)

Other bells and whistles may become useful or necessary, but this is a
good start, imo.

Aha!  With these getters, *Python* becomes the query language!  So
simple.  So powerful.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to