private function getLink() { $link = ''; if (substr($this->lexer->lookahead['value'], 1, 1) == '[' && substr($this->lexer->lookahead['value'], -1, 1) == ']') { //We are looking for a link like $h[xxx]yyy$h $this->lexer->moveNext(); $matches = array(); if ($this->lexer->lookahead && preg_match('/^\\[([^\\]]*)\\]$/iu', $this->lexer->lookahead['value'], $matches)) { $link = $matches[1]; } } else { //We are looking for a link like $hxxxx$h $endLinkTokens = array(Lexer::T_EXTERNAL_LINK, Lexer::T_INTERNAL_LINK, Lexer::T_RESET_ALL); do { $nextLookahead = $this->lexer->peek(); if ($nextLookahead && ($nextLookahead['type'] == Lexer::T_NONE || $nextLookahead['type'] == Lexer::T_ESCAPED_CHAR)) { $link .= $nextLookahead['value']; if (substr($link, 0, 1) == '[') { //It means that there is no closing square bracket $l[noclosingsquarebracket array_push($this->lookaheadToSkip, $nextLookahead); } } } while ($nextLookahead !== null && !in_array($nextLookahead['type'], $endLinkTokens)); if (substr($link, 0, 1) == '[') { //It means that there is no closing square bracket $l[noclosingsquarebracket $link = ''; } } return $link; }
/** * Peeks beyond the matched closing parenthesis and returns the first token after that one. * * @param bool $resetPeek Reset peek after finding the closing parenthesis. * * @return array */ protected function peekBeyondClosingParenthesis($resetPeek = true) { $token = $this->lexer->peek(); $numUnmatched = 1; while ($numUnmatched > 0 && $token !== null) { switch ($token['type']) { case Lexer::T_OPEN_PARENTHESIS: ++$numUnmatched; break; case Lexer::T_CLOSE_PARENTHESIS: --$numUnmatched; break; default: // Do nothing } $token = $this->lexer->peek(); } if ($resetPeek) { $this->lexer->resetPeek(); } return $token; }