예제 #1
0
 /**
  *
  * @param TokenStream $stream
  * @param int $indention
  * @return TokenStreamBuilder
  */
 public function addStream(TokenStream $stream, $indention = 1)
 {
     if ($indention > 0) {
         $stream->indent($indention);
     }
     $this->stream->append($stream);
     return $this;
 }
예제 #2
0
 function scan($source)
 {
     //todo: track indentation
     $stream = new TokenStream();
     $depth = 0;
     foreach (token_get_all($source) as $token) {
         if (is_array($token)) {
             list($token, $text) = $token;
         } elseif (is_string($token)) {
             $text = $token;
             $token = -1;
         }
         if ($token === T_CURLY_OPEN || $token === T_DOLLAR_OPEN_CURLY_BRACES || $text === '{') {
             ++$depth;
         } elseif ($text == '}') {
             --$depth;
         }
         $stream->append(new Token($text, $token, $depth));
     }
     return $stream;
 }
예제 #3
0
 /**
  * get substream
  * @param int $from
  * @param int $to
  */
 public function get($from, $to)
 {
     $tokenStream = new TokenStream();
     $tokenStream->append(array_slice($this->tokens, $from, $to - $from + 1));
     return $tokenStream;
 }