Potential flaw in grammar

From: Date: Tue, 26 Aug 2014 13:43:37 +0000
Subject: Potential flaw in grammar
Groups: php.standards 
Request: Send a blank email to standards-+get-404@lists.php.net to get a copy of this message
Hello all, I've been looking over the grammar to test out a parser I've been building. I think i may have discovered a small flaw in the grammar definition for string literals. The problem is in the definition of heredoc-string-literal and nowdoc-string literal. The relevant definitions: from https://github.com/php/php-langspec/blob/master/spec/19-grammar.md#string-literals: heredoc-string-literal:: hd-start-identifier new-line hd-char-sequenceopt new-line hd-end-identifier ;opt new-line hd-start-identifier:: name hd-end-identifier:: name nowdoc-string-literal:: hd-start-identifier ' new-line hd-char-sequenceopt new-line hd-end-identifier ;opt new-line According to my experience with these and example of a heredoc string would be: <<<TEST some string content here.... TEST; The grammar however makes no mention of the opening "<<<" and based on what i'm seeing would accept something like: TEST abcdef TEST; Which is not accepted by my version of PHP (5.5.9). A second issue i noticed is in the definition of nowdoc-string-literal An example nowdoc string taken from php.net looks like this: $str = <<<'EOD' Example of string spanning multiple lines using nowdoc syntax. EOD; The grammar definition seems to be missing the opening single quote and since it relies on on hd-start-identifier it is also missing the required "<<<". I think the following simple modifications should suffice, just wanted to make sure i wasn't crazy before opening a pull request. Change: hd-start-identifier:: name To: hd-start-identifier:: <<< name Create nd-start-identifier as: nd-start-identifier:: <<< ' name ' And change: nowdoc-string-literal:: nd-start-identifier new-line hd-char-sequenceopt new-line hd-end-identifier ;opt new-line Thanks! - Ken

« previous php.standards (#404) next »