/** * append token or stream to stream * * This function may either be passed a TokenStream, an array of token-like * elements or a single token-like element. * The array will be appended recursively (thus it can have sub-arrays.) * A token-like element is either a Token or a single character mapable to * a token. All other elements are dropped, *without* error message. * * @param mixed $tokenStream * @return int number of appended tokens */ public function append($tokenStream) { if (!is_array($tokenStream)) { $tokenStream = array($tokenStream); } $count = 0; // number of appended tokens foreach ($tokenStream as $token) { // instanceof Token: append if ($token instanceof Prephp_Token) { $this->tokens[] = $token; ++$count; } elseif (is_string($token)) { $this->tokens[] = Prephp_Token::newCharToken($token); ++$count; } elseif ($token instanceof Prephp_TokenStream) { foreach ($token as $t) { $this->tokens[] = $t; ++$count; } } elseif (is_array($token)) { $count += $this->append($token); } // else: drop *without* error message } return $count; }