/** * Constructs a new missing value exception. * * @param \PDepend\Source\Tokenizer\Tokenizer $tokenizer */ public function __construct(Tokenizer $tokenizer) { // Get wrong token $token = $tokenizer->next(); // The parser must take care for this assert($token instanceof Token); $message = sprintf('Missing default value on line: %d, col: %d, file: %s.', $token->startLine, $token->startColumn, $tokenizer->getSourceFile()); parent::__construct($message); }
/** * Constructor. * * @param Stream $stream * @param Token|null $expected */ public function __construct(Stream $stream, Token $expected = null) { $this->actual = $stream->current(); $this->expected = $expected; $this->tokenLine = $this->actual->getLine(); $message = sprintf('Unexpected token %s at line %d ("%s").', (string) $this->actual, $this->tokenLine, $stream->humanize()); if ($this->expected !== null) { $message = sprintf('%s Expects token %s.', $message, (string) $this->expected); } parent::__construct($message); }
/** * Constructs a new unexpected token exception. * * @param \pdepend\reflection\parser\Token $token The unexpected token. * @param string $fileName The parsed source file. */ public function __construct(Token $token, $fileName) { parent::__construct(sprintf('Unexpected token[image="%s", type=%d] on line %d in file %s', $token->image, $token->type, $token->startLine, $fileName)); }
/** * Constructs a new invalid state exception. * * @param integer $lineNumber Line number where the parser has stopped. * @param string $fileName The source file where this exception occured. * @param string $reason Short description what has happend. */ public function __construct($lineNumber, $fileName, $reason) { parent::__construct(sprintf('The parser has reached an invalid state near line "%d" in file ' . '"%s". Please check the following conditions: %s', $lineNumber, $fileName, $reason)); }
/** * Constructs a new exception instance. * * @param string $fileName Name of the currently parsed file. */ public function __construct($fileName) { parent::__construct('Unexpected end of token stream in file ' . $fileName); }
/** * Builds a regex from a tokens structure array. * * @param array $token A tokens structure root node. * @return array An array containing the regex pattern and its associated variable names. */ public static function compile($token) { $variables = []; $regex = ''; foreach ($token['tokens'] as $child) { if (is_string($child)) { $regex .= preg_quote($child, '~'); } elseif (isset($child['tokens'])) { $rule = static::compile($child); if ($child['repeat']) { if (count($rule[1]) > 1) { throw ParserException::placeholderExceeded(); } $regex .= '((?:' . $rule[0] . ')' . $child['greedy'] . ')'; } elseif ($child['optional']) { $regex .= '(?:' . $rule[0] . ')?'; } foreach ($rule[1] as $name => $pattern) { if (isset($variables[$name])) { throw ParserException::duplicatePlaceholder($name); } $variables[$name] = $pattern; } } else { $name = $child['name']; if (isset($variables[$name])) { throw ParserException::duplicatePlaceholder($name); } if ($token['repeat']) { $variables[$name] = $token['pattern']; $regex .= $child['pattern']; } else { $variables[$name] = false; $regex .= '(' . $child['pattern'] . ')'; } } } return [$regex, $variables]; }
/** * Throws a ParserException if the string content contains any kind of invalid character * * @param string $sString * * @throws ParserException * @return Parser */ protected function invalidCharactersCheck(&$sString) { $aInvalidCharacters = array('{', '}'); foreach ($aInvalidCharacters as $sInvalidCharacter) { if (strpos($sString, $sInvalidCharacter) !== false) { $e = new ParserException('Invalid characters detected in the content! :: "' . $sInvalidCharacter . '"'); throw $e->setExtraInfo($sString); } } return $this; }