Output or serialize ASTs to XML, JSON?

17 views
Skip to first unread message

KPrichard

unread,
Apr 14, 2012, 7:03:58 PM4/14/12
to le...@googlegroups.com
I am curious if LEPL has direct support for serializing ASTs into a corresponding textual representation, such as XML.  If not, how would one go about producing same.

I'd like to run a series of XPath queries against the ASTs.  e.g. to query a repository of source code for usage patterns, best or forbidden practices, and the like.

I prefer something like XPath over node inspection in python, because it has simple, tree-aware relational query capabilities.

Great project, by the way.

Regards,
KPrichard

andrew cooke

unread,
Apr 14, 2012, 9:02:55 PM4/14/12
to le...@googlegroups.com

hi,

at first i was a bit confused by this, because lepl doesn't really enforce any
kind of ast - you can construct whatever you want.

but then i remembered that many of the examples use the List class (and in
older versions used the Node class). so i am guessing you're referring to
that?

if so, then it extends an ordinary python list (the [....] thing) so i expect
the standard json libraries could handle it. however, you will lose the type
(the class name) which is often important.

so i guess (eventually!) what you are asking is: if you're constructing an ast
using List subclasses, how can you convert that into xml in a way that keeps
the class name?

which is a good question (and the short answer is that there is nothing
already available).

i've just tried playing around with some ideas, but it depends very much what
your ast looks like.

so could you reply with an example of an ast and the kind of xml you'd like,
and i can reply with something more helpful?

the reason i can't give a general reply is because often asts contain lists of
values, and i don't see a single obvious way to stick lists of things in xml
(you can use attributes or text or surround them with elements, but i don't
know what would be best, or what attribute or element name you'd want, without
something to guide me).

andrew

ps if json would work then you could perhaps use pytyp
http://www.acooke.org/pytyp/pytyp.s11n.json.html but i get the impression you
would prefer xml and working out how to use pytyp is itself a fair amount of
effort...

> --
> You received this message because you are subscribed to the Google Groups "lepl" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/lepl/-/aqRLl_tkFcYJ.
> To post to this group, send email to le...@googlegroups.com.
> To unsubscribe from this group, send email to lepl+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/lepl?hl=en.
>

andrew cooke

unread,
Apr 17, 2012, 5:01:22 PM4/17/12
to le...@googlegroups.com

my apologies - i sent this reply at the weekend, but google filtered it (from me - i own this group!) and my spam filter then filtered google's email to me about spam (yay!) so i didn't see anything until today.  andrew
Reply all
Reply to author
Forward
0 new messages