Page MenuHomePhabricator

Improve parsing of variables embedded in strings in XHPAST
Open, WishlistPublic

Description

It seems that XHPAST doesn't properly parse strings contains interpolated variables. Specifically, "This string contains no variables" and "This string contains $variables" are both parsed as n_STRING_SCALAR. See https://secure.phabricator.com/xhpast/view/729/ for example... tokenizing this same file with token_get_all produces the following:

array (
  0 => 
  array (
    0 => 374,
    1 => '<?php ',
    2 => 1,
  ),
  1 => 
  array (
    0 => 377,
    1 => '

',
    2 => 1,
  ),
  2 => 
  array (
    0 => 317,
    1 => 'echo',
    2 => 3,
  ),
  3 => 
  array (
    0 => 377,
    1 => ' ',
    2 => 3,
  ),
  4 => 
  array (
    0 => 316,
    1 => '"This string contains no variables."',
    2 => 3,
  ),
  5 => ';',
  6 => 
  array (
    0 => 377,
    1 => '
',
    2 => 3,
  ),
  7 => 
  array (
    0 => 317,
    1 => 'echo',
    2 => 4,
  ),
  8 => 
  array (
    0 => 377,
    1 => ' ',
    2 => 4,
  ),
  9 => '"',
  10 => 
  array (
    0 => 315,
    1 => 'This string contains ',
    2 => 4,
  ),
  11 => 
  array (
    0 => 310,
    1 => '$variables',
    2 => 4,
  ),
  12 => 
  array (
    0 => 315,
    1 => '.',
    2 => 4,
  ),
  13 => '"',
  14 => ';',
)

More succinctly:

// "This string contains no variables."
array(
  array(
    0 => T_CONSTANT_ENCAPSED_STRING,
    1 => '"This string contains no variables."',
    2 => 3,
  ),
);

// "This string contains $variables."
array(
  '"',
  array(
    0 => T_ENCAPSED_AND_WHITESPACE,
    1 => 'This string contains ',
    2 => 4,
  ),
  array(
    0 => T_VARIABLE,
    1 => '$variables',
    2 => 4,
  ),
  array(
    0 => T_ENCAPSED_AND_WHITESPACE,
    1 => '.',
    2 => 4,
  ),
  '"',
);

Event Timeline

joshuaspence raised the priority of this task from to Needs Triage.
joshuaspence updated the task description. (Show Details)
joshuaspence added a project: XHPAST.
joshuaspence added a subscriber: joshuaspence.
epriestley renamed this task from Improve parsing of strings to Improve parsing of variables embedded in strings in XHPAST.May 4 2015, 1:31 PM
epriestley triaged this task as Wishlist priority.May 7 2015, 1:50 PM