You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Nicholas Telford (JIRA)" <ji...@apache.org> on 2011/06/16 11:49:47 UTC

[jira] [Created] (THRIFT-1209) PHP compiler generates syntax error when for enums containing constant "GLOBAL"

PHP compiler generates syntax error when for enums containing constant "GLOBAL"
-------------------------------------------------------------------------------

                 Key: THRIFT-1209
                 URL: https://issues.apache.org/jira/browse/THRIFT-1209
             Project: Thrift
          Issue Type: Bug
          Components: PHP - Compiler
    Affects Versions: 0.6.1
            Reporter: Nicholas Telford


Reported on IRC:

If an interface calls for an enum that defines a constant that's an invalid identifier in PHP (e.g. "GLOBAL") the generated code contains a syntax error.

Example, from the Hive Metastore Thrift interface:

{code}
enum HiveObjectType {
  GLOBAL = 1,
  DATABASE = 2,
  TABLE = 3,
  PARTITION = 4,
  COLUMN = 5,
}
{code}


Generates the following PHP:

{code}
final class metastore_HiveObjectType {
  const GLOBAL = 1;
  const DATABASE = 2;
  const TABLE = 3;
  const PARTITION = 4;
  const COLUMN = 5;
  static public $__names = array(
    1 => 'GLOBAL',
    2 => 'DATABASE',
    3 => 'TABLE',
    4 => 'PARTITION',
    5 => 'COLUMN',
  );
}
{code}

I suggest we prefix enum constants to avoid this situation, although this would mean the interface didn't match.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1209) PHP compiler generates syntax error when for enums containing constant "GLOBAL"

Posted by "Jake Farrell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13279432#comment-13279432 ] 

Jake Farrell commented on THRIFT-1209:
--------------------------------------

If we added a reserved keywords file across all languages and prevent them from any idl we would resolve this issue but for any idl's that where for services in only one language or a set of languages which didn't have the same keywords as another set then we would block them from using a potentially large range of variables. Also since in php all keywords are case-insensitive this would double the reserved words list 
                
> PHP compiler generates syntax error when for enums containing constant "GLOBAL"
> -------------------------------------------------------------------------------
>
>                 Key: THRIFT-1209
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1209
>             Project: Thrift
>          Issue Type: Bug
>          Components: PHP - Compiler
>    Affects Versions: 0.6.1
>            Reporter: Nicholas Telford
>
> Reported on IRC:
> If an interface calls for an enum that defines a constant that's an invalid identifier in PHP (e.g. "GLOBAL") the generated code contains a syntax error.
> Example, from the Hive Metastore Thrift interface:
> {code}
> enum HiveObjectType {
>   GLOBAL = 1,
>   DATABASE = 2,
>   TABLE = 3,
>   PARTITION = 4,
>   COLUMN = 5,
> }
> {code}
> Generates the following PHP:
> {code}
> final class metastore_HiveObjectType {
>   const GLOBAL = 1;
>   const DATABASE = 2;
>   const TABLE = 3;
>   const PARTITION = 4;
>   const COLUMN = 5;
>   static public $__names = array(
>     1 => 'GLOBAL',
>     2 => 'DATABASE',
>     3 => 'TABLE',
>     4 => 'PARTITION',
>     5 => 'COLUMN',
>   );
> }
> {code}
> I suggest we prefix enum constants to avoid this situation, although this would mean the interface didn't match.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (THRIFT-1209) PHP compiler generates syntax error when for enums containing constant "GLOBAL"

Posted by "Nicholas Telford (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/THRIFT-1209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13280057#comment-13280057 ] 

Nicholas Telford commented on THRIFT-1209:
------------------------------------------

I'm not convinced. Such a list would be pretty long since Thrift supports a fairly large number of languages. Maintaining that list would become a bit of a pain too; while most languages don't add reserved words all that often, when they do it's bound to be missed.

There's also the issue of backwards compatibility - existing Thrift IDLs would suddenly become invalid due to their usage of reserved words.

Finally, different languages approach reserved words differently. Scala for example permits them when surrounded in backticks; some words might be permissible in certain scopes (I can't think of any examples, but they may exist).

I suggest that language-specific IDL compilers specially treat identifiers that are a reserved word in that language by transforming them somehow, e.g. prefixing with an underscore as in my original example. This way, we can have a simple rule for each language: "if an IDL identifier is a PHP reserved word, it will be prefixed with an underscore" etc.

This differs from my previous suggestion by only transforming identifiers that are reserved words and leaving everything else as-is.
                
> PHP compiler generates syntax error when for enums containing constant "GLOBAL"
> -------------------------------------------------------------------------------
>
>                 Key: THRIFT-1209
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1209
>             Project: Thrift
>          Issue Type: Bug
>          Components: PHP - Compiler
>    Affects Versions: 0.6.1
>            Reporter: Nicholas Telford
>
> Reported on IRC:
> If an interface calls for an enum that defines a constant that's an invalid identifier in PHP (e.g. "GLOBAL") the generated code contains a syntax error.
> Example, from the Hive Metastore Thrift interface:
> {code}
> enum HiveObjectType {
>   GLOBAL = 1,
>   DATABASE = 2,
>   TABLE = 3,
>   PARTITION = 4,
>   COLUMN = 5,
> }
> {code}
> Generates the following PHP:
> {code}
> final class metastore_HiveObjectType {
>   const GLOBAL = 1;
>   const DATABASE = 2;
>   const TABLE = 3;
>   const PARTITION = 4;
>   const COLUMN = 5;
>   static public $__names = array(
>     1 => 'GLOBAL',
>     2 => 'DATABASE',
>     3 => 'TABLE',
>     4 => 'PARTITION',
>     5 => 'COLUMN',
>   );
> }
> {code}
> I suggest we prefix enum constants to avoid this situation, although this would mean the interface didn't match.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira