Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.4.0

Bug #14731 $ in regex is interpreted as an reference to variable
Submitted: 2008-10-02 17:57 UTC
From: lew21 Assigned:
Status: Open Package: PHP_LexerGenerator (version 0.3.4)
PHP Version: 5.2.6 OS: Linux
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 13 + 38 = ?

 
 [2008-10-02 17:57 UTC] lew21 (Janusz Lewandowski)
Description: ------------ $ in regex is interpreted as an reference to variable Test script: --------------- label = #[$a-zA-Z_\x7f-\xff][$a-zA-Z0-9_\x7f-\xff]*# Expected result: ---------------- I expected it to work. Actual result: -------------- PHP Notice: Undefined variable: a in /*/lexer.php on line 122 PHP Notice: Undefined variable: a in /*/lexer.php on line 122

Comments

 [2008-10-05 17:26 UTC] doconnor (Daniel O'Connor)
Hey, Janusz, can you put together a small executable test script for us less familiar with the package?
 [2008-10-07 11:37 UTC] lew21 (Janusz Lewandowski)
lexer.plex: <?php class Lexer { private $data; private $N = 0; public $token; public $value; public $line = 1; function __construct($data) { $this->data = $data; } /*!lex2php %input {$this->data} %counter {$this->N} %token {$this->token} %value {$this->value} %line {$this->line} label = #[$a-zA-Z_\x7f-\xff][$a-zA-Z0-9_\x7f-\xff]*# */ /*!lex2php label {$this->token = 'LABEL';} */ } ?> test.php: <?php error_reporting(E_ALL); include 'lexer.php'; $lexer = new Lexer('$test'); $lexer->yylex(); echo $lexer->token, '(', $lexer->value, ')', PHP_EOL; ?> # plex lexer.plex # php test.php Expected output: LABEL($hehe) Actual output: PHP Notice: Undefined variable: a in /.../lexer.php on line 50 PHP Notice: Undefined variable: a in /.../lexer.php on line 50 PHP Fatal error: Uncaught exception 'Exception' with message 'Unexpected input at line1: $' in /.../lexer.php:137 Stack trace: #0 /.../lexer.php(21): Lexer->yylex1() #1 /.../test.php(7): Lexer->yylex() #2 {main} thrown in /.../lexer.php on line 137
 [2008-10-09 13:29 UTC] kguest (Ken Guest)
the "$a" in the .plex file needs to be backquoted ie "\$a" plus the expected output really should be as follows: kguest@ubuntu:~$ php test.php LABEL($test)
 [2008-10-09 13:30 UTC] doconnor (Daniel O'Connor)
Oh, as if I missed that one. Thanks for the test case Janusz, anyhow!
 [2008-10-09 14:10 UTC] lew21 (Janusz Lewandowski)
One \ before $ is ignored, and \\ is replaced to \\\\. The only way to use $ is \036. Also, I don't think that anybody will need access to PHP variables here. $ should automagically get escaped.
 [2008-10-09 14:57 UTC] cellog (Greg Beaver)
I agree, this is a bug