Potential flaw in grammar

[email protected] (ken Koch)
Newsgroups php.standards
Message-ID <CAJqvgTwgg3EQBkUjpBgZ1XFuOZxM7eKAgYXh6R+PduGFM8hoXw@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.