bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#386912: errors in the Perl parser of xgettext: invalid variable


From: Guido Flohr
Subject: Re: Bug#386912: errors in the Perl parser of xgettext: invalid variable interpolation at "$"
Date: Tue, 12 Sep 2006 18:17:23 +0200
User-agent: Thunderbird 1.5.0.5 (X11/20060802)

Hi again,

I forgot to answer the Perl question:

Bruno Haible wrote:
Is the following true? (I'm not a Perl programmer.)

   In Perl, parentheses around function arguments can be omitted.  Ambiguities
   are resolved as follows:
     - Some built-ins, such as 'abs', 'sqrt', 'sin', 'cos', ..., take exactly
       one argument:
         foo sin x, y  ==>  foo (sin (x), y)

Functions may be (built-ins are) prototyped, and for prototyped functions Perl knows the number of arguments. But there is nothing special about built-in functions apart from that.

     - Other identifiers, if immediately followed by an opening parenthesis,
       take exactly the specified arguments:
         foo bar (x), y  ==>  foo (bar (x), y)
         foo bar (x, y), z  ==>  foo (bar (x, y), z)

Almost correct:

        foo "bar", ("baz", "bazoo"), "ignored" <==> foo ("bar", "baz", "bazoo");

(read "<==>" as is equivalent to).

The "bar" is consumed, the "ignored" is not.

     - Other identifiers, if not immediately followed by an opening
       parenthesis, consume the entire remaining argument list:
         foo bar x, y  ==> foo (bar (x, y))

Not really.

The problem is: Perl cannot be parsed, it can only be executed. You can only resolve these ambiguities if you know all functions that are visible in the current namespace, and if you know their prototype. Without this information you can only guess, and ask people to avoid exotic calling conventions.

There is one rule though: The argument list always ends after the first closing balanced parenthesis:

        func "foo", "bar", (baz ("foo", "bar"), "bazoo"), "this", "not";

The argument list cannot possibly go beyond the parenthesis behind "bazoo". It will end after the first "foo" if the function takes exactly one argument. If the function takes two, three, or four arguments, the code will not compile. But xgettext cannot know whether func() is prototyped, and how the prototype looks.

I think, the only solution is to agree on a sane behavior, and then document this behavior, so that people can write code according to it. IMHO, the behavior of xgettext 0.14.5 was sane, and it should not be changed. There are already some bigger projects using the Perl backend, and they may run into compatibility problems.

The attached Perl script illustrates some of the problems. It defines the function one_arg() that requires one argument, two_args() that requires two_arguments(), list_args() requires one scalar argument plus a (variable-size) list and var_args which just takes a (variable-size) list. Actually var_args() and list_args() are equivalent. All functions just take their arguments and print them out. As you can see, even identical argument lists produce different results, depending on the signature of the called function. Unfortunately, the signature of the called function is mostly not visible, at least you can not rely on that.

It will always be possible to outsmart the Perl parser in xgettext, and that behavior is unavoidable and documented.

Regards,
Guido
--
Imperia AG, Development
Leyboldstr. 10 - D-50354 Hürth - http://www.imperia.net/

Attachment: args.pl
Description: Perl program


reply via email to

[Prev in Thread] Current Thread [Next in Thread]