Skip to content

Commit

Permalink
consolidate token logic
Browse files Browse the repository at this point in the history
  • Loading branch information
scoates authored and ieure committed Nov 29, 2009
1 parent b0783c0 commit 1377cbf
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions PHP/Repl.php
Expand Up @@ -218,6 +218,7 @@ private function cleanup($input)
static $last;

$input = trim($input);
$tokens = token_get_all("<?php {$input}");

// Sugar
if (substr($input, 0, 1) == ',' &&
Expand All @@ -229,7 +230,6 @@ private function cleanup($input)

// if the input string contains anything but a single variable,
// wrap it in single-quotes
$tokens = token_get_all(rtrim("<php {$input}", "\t ;"));
if (!(count($tokens) == 2 && isset($tokens[1][0]) &&
$tokens[1][0] = T_VARIABLE)) {
$input = "'$input'";
Expand All @@ -245,9 +245,8 @@ private function cleanup($input)

// determine if the input contains multiple statements
// e.g. $a=1;$a=2;
$tokens = array_count_values(array_filter(
token_get_all("<?php {$input}"), 'is_scalar'));
$multi = isset($tokens[';']) && $tokens[';'] > 1;
$semis = array_count_values(array_filter($tokens, 'is_scalar'));
$multi = isset($semis[';']) && $semis[';'] > 0;

// Make sure we get a value back from eval()
// but if input contains a semi-colon
Expand Down

0 comments on commit 1377cbf

Please sign in to comment.