Skip to content
Browse files

Removed need to explicitly end lines with backslashes inside matched …

…parens or curlies.
  • Loading branch information...
1 parent f4e0c58 commit 45aa5fe986fc614ded46f53d8b705db8eb3bd2e7 @bobthecow committed Mar 16, 2010
Showing with 32 additions and 6 deletions.
  1. +32 −6 PHP/Repl.php
View
38 PHP/Repl.php
@@ -154,9 +154,11 @@ public function run(array $scope = array())
*/
private function read()
{
- $code = '';
- $done = false;
- $lines = 0;
+ $code = '';
+ $done = false;
+ $lines = 0;
+ $curleys = 0;
+ $parens = 0;
static $shifted;
if (!$shifted) {
// throw away argv[0]
@@ -179,13 +181,37 @@ private function read()
return false;
}
+ $done = true;
$line = trim($line);
// If the last char is a backslash, remove it and
// accumulate more lines.
if (substr($line, -1) == '\\') {
- $line = substr($line, 0, strlen($line) - 1);
- } else {
- $done = true;
+ $line = trim(substr($line, 0, strlen($line) - 1));
+ $done = false;
+ }
+
+ // check for curleys and parens, keep accumulating lines.
+ $tokens = token_get_all("<?php {$line}");
+ foreach ($tokens as $t) {
+ switch ($t) {
+ case '{':
+ ++$curleys;
+ break;
+ case '}':
+ --$curleys;
+ break;
+ case '(':
+ ++$parens;
+ break;
+ case ')':
+ --$parens;
+ break;
+ }
+ }
+ if ($curleys > 0) {
+ $done = false;
+ } else if ($parens > 0) {
+ $done = false;
}
$code .= $line;
$lines++;

0 comments on commit 45aa5fe

Please sign in to comment.
Something went wrong with that request. Please try again.