Permalink
Browse files

pfff: allow HereDoc as static scalar

Summary: One can do 'const X = <<<EOF ... EOF;'

Test Plan:
unit test included
$ make test

Reviewers: michalburger1, julienv

Reviewed By: michalburger1

CC: sfodor

Differential Revision: https://phabricator.fb.com/D458118
  • Loading branch information...
1 parent 4e2baab commit 9fa72e3b2321222d964330f3a178f3bba57e0f53 @aryx aryx committed Apr 25, 2012
Showing with 12 additions and 3 deletions.
  1. +2 −2 lang_php/parsing/ast_php.mli
  2. +5 −1 lang_php/parsing/parser_php.mly
  3. +5 −0 tests/php/parsing/const_heredoc.php
@@ -727,10 +727,10 @@ and static_var = dname * static_scalar_affect option
* and visitors more complicated because stuff like "+ 1" could
* be an expr or a static_scalar. We don't need this "isomorphism".
* I never leveraged the specificities of static_scalar (maybe a compiler
- * would, but my checker/refactorers/... don't).
+ * would, but my checker/refactorer/... didn't).
*
* Note that it's not 'type static_scalar = scalar' because static_scalar
- * actually allows arrays (why the heck they called it a scalar then ....)
+ * actually allows arrays (why the heck they called it a scalar then ...)
* and plus/minus which are only in expr.
*)
and static_scalar = expr
@@ -1141,17 +1141,21 @@ static_scalar: /* compile-time evaluated scalars */
| TPLUS static_scalar { Unary ((UnPlus, $1),$2) }
| TMINUS static_scalar { Unary ((UnMinus, $1),$2) }
+ /*(* arrays are considered scalars in the PHP grammar, brilliant *)*/
| T_ARRAY TOPAR static_array_pair_list TCPAR
{ ArrayLong($1, ($2, $3, $4)) }
| TOBRA static_array_pair_list TCBRA
{ ArrayShort($1, $2, $3) }
-
+ /*(* todo? ensure encaps_list contains only constant strings? *)*/
+ | T_START_HEREDOC encaps_list T_END_HEREDOC
+ { Sc (HereDoc ($1, $2, $3)) }
/*(*s: static_scalar grammar rule hook *)*/
/* xdebug TODO AST */
| TDOTS { sgrep_guard (SgrepExprDots $1) }
/*(*e: static_scalar grammar rule hook *)*/
+
common_scalar:
| T_LNUMBER { Int($1) }
| T_DNUMBER { Double($1) }
@@ -0,0 +1,5 @@
+<?php
+
+const XX = <<<'XXX'
+this is a string
+XXX;

0 comments on commit 9fa72e3

Please sign in to comment.