472,121 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

embedded function body

Hi,
I need to embed an user-supplied python function body in a C program.
That is, the user has no control over the function definition:

def afunction():
<here goes user code>

Now, the problem is that I can't just append the supplied string,
because I need to properly indent it which isn't trivial - just adding
a tab in front of every line won't do. I'm considering two approaches:
1) write an indent function which is more aware of python syntax;
2) use the python lexxer and work with parse trees.

I've done some experiments with 2). The idea was to parse the following
program:

def afunction():
pass

and the user supplied string (as a complete program) separately, then
replace the <suite> node in the function definition with one including
the statements from the user program.

I've got something that seems to work (but getting
allocation/deallocation right requires some work), but it seems to me
it's a bit awkward. Is the PyNode_* interface public and stable? Is it
ok to use it?

Any advice? Am I missing something? Should I try approach 1)?

TIA,
..TM.

Jul 19 '05 #1
0 883

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Pretty woman | last post: by
14 posts views Thread by Alex Molochnikov | last post: by
1 post views Thread by Jim Hammond | last post: by
2 posts views Thread by Owen.Leibman | last post: by
1 post views Thread by John Smith | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.