copyText = $copyText; } /** * The default {@see CommonTokenFactory} instance. * * This token factory does not explicitly copy token text when constructing * tokens. */ public static function default() : self { static $default; return $default = $default ?? new CommonTokenFactory(); } public function createEx( Pair $source, int $type, ?string $text, int $channel, int $start, int $stop, int $line, int $column ) : Token { $token = new CommonToken($type, $source, $channel, $start, $stop); $token->setLine($line); $token->setCharPositionInLine($column); if ($text !== null) { $token->setText($text); } elseif ($this->copyText && $source->b !== null) { if (!$source->b instanceof CharStream) { throw new \RuntimeException('Unexpected stream type.'); } $token->setText($source->b->getText($start, $stop)); } return $token; } public function create(int $type, string $text) : Token { $token = new CommonToken($type); $token->setText($text); return $token; } }