Re: plpython function problem workaround

Поиск
Список
Период
Сортировка
От Marco Colombo
Тема Re: plpython function problem workaround
Дата
Msg-id Pine.LNX.4.61.0503181744230.20758@Megathlon.ESI
обсуждение исходный текст
Ответ на Re: plpython function problem workaround  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: plpython function problem workaround  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Fri, 18 Mar 2005, Tom Lane wrote:

> Michael Fuhr <mike@fuhr.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@ESI.it

В списке pgsql-general по дате отправления:

Предыдущее
От: Grzegorz Przeździecki
Дата:
Сообщение: Japanese characters problem
Следующее
От: Tom Lane
Дата:
Сообщение: Re: plpython function problem workaround