Invenzzia »

IMPORTANT ANNOUNCEMENT

Due to the uncertain status of the Flyspray project, lack of new releases and moving the code repository to Github, we decided to shutdown this issue tracker by the end of January 2011. From that date, the bugs should be reported directly in Github project repositories.

List of repositories:

Open Power Template 2.x family

PLEASE PROVIDE THE TEMPLATES AND/OR PHP CODE IN THE TASK DESCRIPTION (Not URL-s to them). THAT ALLOWS US TO REPRODUCE THE PROBLEM! OTHERWISE WE ARE NOT ABLE TO HELP YOU!

Remember to hide all the security-related pieces of code from the task description, like passwords, server paths etc. for your own safety. Once we close the task, we cannot edit it anymore!
Tasklist

FS#178 - Expression token order

Attached to Project: Open Power Template
Opened by Skruppy (Skrupellos) - Friday, 26 August 2011, 17:13 GMT-8
Task Type Bug Report
Category Template syntax
Status Unconfirmed
Assigned To No-one
Operating System OS-independent
Severity High
Priority Normal
Reported Version 2.1-beta1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 1
Private No

Details

Reproduce
=========
Create an expression containing a "===" e.g. in an opt:if condition (like in my case) and compile it.

~~~ snip: a.tpl ~~~
<opt:if test="$edit === true">
~~~ END snip: a.tpl ~~~


Result
======
The compiler struggles interpreting "===" and raises the following exception:

~~~ snip: cli output ~~~
PHP Fatal error: Uncaught exception 'Opt_Expression_Exception' with message 'Invalid token: =' in /Opt/Expression/Standard/Parser.php:2062
Stack trace:
#0 /Opt/Expression/Standard/Parser.php(2120): Opt_Expression_Standard_Parser->yy_syntax_error(25, '=')
#1 /Opt/Expression/Standard.php(177): Opt_Expression_Standard_Parser->doParse(25, '=')
#2 /Opt/Compiler/Class.php(1946): Opt_Expression_Standard->parse('$edit === true', true)
#3 /Opt/Instruction/Abstract.php(606): Opt_Compiler_Class->parseExpression('$edit === true', 'parse')
#4 /Opt/Instruction/Abstract.php(479): Opt_Instruction_Abstract->_extractAttribute(Object(Opt_Xml_Element), Object(Opt_Xml_Attribute), 6, NULL)
#5 /Opt/Instruction/If.php(107): Opt_Instruction_Abstract->_extractAttributes(Object(Opt_Xml_Element), Array)
#6 /Opt/Xml/Element.php(503): Opt_Instruction_If->proc in /Opt/Expression/Standard/Parser.php on line 2062
~~~ END snip: cli output ~~~


adding the following PHP code in Opt/Expression/Standard.php on line 172 (in the while loop) I get the output following afterwards.

~~~ snip: PHP code ~~~
if($expr == '$edit === true') {
echo "{$lexer->token} ## {$lexer->value}\n";
}
~~~ END snip: PHP code ~~~

~~~ snip: debug output ~~~
57 ## $
50 ## edit
w ##
4 ## ==
25 ## =
... The error message
~~~ END snip: debug output ~~~


Assumption
==========
I guess the lexer sees the valid "==" token and accepts it before finding an also valid "===". Perhaps this is because of an wrong order in tools/lexer/expression_lexer.plex as shown below:

~~~ snip: expression_lexer.plex ~~~
identifier {
switch($this->value)
{
[...]
case 'eq':
$this->token = Opt_Expression_Standard_Parser::T_EQUALS;
break;
case 'neq':
$this->token = Opt_Expression_Standard_Parser::T_NEQUALS;
case 'eqt':
$this->token = Opt_Expression_Standard_Parser::T_EQUALS_T;
break;
case 'neqt':
$this->token = Opt_Expression_Standard_Parser::T_NEQUALS_T;
break;

~~~ END snip: expression_lexer.plex ~~~
This task depends upon

Comment by Skruppy (Skrupellos) - Friday, 26 August 2011, 17:16 GMT-8
Oh, I see I have FAILED copy & pasting the expression_lexer.plex snip :-(
(Because I've tried to change the order manually and ....)
the snip should show expression_lexer.plex as contained in the official release.
Comment by Skruppy (Skrupellos) - Saturday, 03 September 2011, 20:10 GMT-8
This applies also to != and !==

WORKAROUND
==========
According to http://static.invenzzia.org/docs/opt/2_0/book/en/syntax.expressions.operators.html , you can replace "===" with "eqt", "!=" with "neq" and "!==" with "neqt"
Comment by Skruppy (Skrupellos) - Sunday, 04 September 2011, 09:23 GMT-8
This bug is now copied to https://github.com/OPL/Open-Power-Template/issues/5 and will be handled there.

Loading...