Re: plpython function problem workaround

From: Marco Colombo <pgsql(at)esiway(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: plpython function problem workaround
Date: 2005-03-18 17:05:16
Message-ID: Pine.LNX.4.61.0503181744230.20758@Megathlon.ESI
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 18 Mar 2005, Tom Lane wrote:

> Michael Fuhr <mike(at)fuhr(dot)org> writes:
>> On Fri, Mar 18, 2005 at 12:35:07AM -0500, Tom Lane wrote:
>>> So that part of it can be solved fairly easily.
>
>> Should I submit a patch? It should be only a few additional lines
>> in PLy_procedure_munge_source(). Would you apply it only to HEAD,
>> or would it be considered a bug fix that REL8_0_STABLE could get
>> as well? It might be nice to have it in 8.0.2, whenever that comes
>> out.
>
> I think it would be reasonable to back-patch a small fix to convert CRLF.
> The sort of rewrite Marco is considering, I wouldn't back-patch.
>
> regards, tom lane

Short update: it isn't possible to get a callable object directly from
the source provided by the user, since 'return' is not valid outside
function definitions in Python.

Right now I'm parsing the string first, changing the resulting
parse tree adding missing nodes (def, INDENT, DEINDENT) and
then compiling it. Grammar definitions for a python function is:

funcdef: [decorators] 'def' NAME parameters ':' suite
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT

What we get from the users is stmt+ (a sequence of stmt). The INDENT
and DEDENT tokens are generated by the parser only when indentation
level _changes_.

My plan is to generate two parse trees, one from this code
(with the right fname of course):

def fname():
pass

and one from the function definition. Then, we "attach" the root
of the second tree where the "pass" node is in the first tree.
We should get a parse tree ready for compilation.

I wish I could "push" the right tokens in the right places,
but it seems it's not possible.

Stay tuned.

.TM.
--
____/ ____/ /
/ / / Marco Colombo
___/ ___ / / Technical Manager
/ / / ESI s.r.l.
_____/ _____/ _/ Colombo(at)ESI(dot)it

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-03-18 17:11:14 Re: plpython function problem workaround
Previous Message Grzegorz Przeździecki 2005-03-18 16:34:17 Japanese characters problem