/** * parses NON_OPTIONAL rule * * @return null|PHPDocType */ private function parse_non_optional() { if (!$this->lexer->has_more()) { return null; } $start_index = $this->lexer->get_token_index(); $tok = $this->lexer->next_token(); if ($tok === "(") { $type = $this->parse_type(); $string_rep = $this->lexer->get_tokens_from_index_to_current_index($start_index); TestScribe\Utils\Assert::with('Box\\TestScribe\\PHPDoc\\PHPDocTypeException')->is_not_null($type, "The PHPDocType '{$string_rep}' is invalid or is not supported"); $tok = $this->lexer->next_token(); $string_rep = $this->lexer->get_tokens_from_index_to_current_index($start_index); TestScribe\Utils\Assert::with('Box\\TestScribe\\PHPDoc\\PHPDocTypeException')->are_equal(")", $tok, "The PHPDocType '{$string_rep}' is invalid or is not supported"); return $type; } else { $this->lexer->pushback(); } $type = $this->parse_primitive(); if ($type !== null) { return $type; } $type = $this->parse_class(); return $type; }
/** * @return void */ public function pushback() { TestScribe\Utils\Assert::with('Box\\TestScribe\\PHPDoc\\PHPDoc_Lexer_Exception')->are_not_equal(0, $this->token_index, "nothing to push back"); $this->token_index--; }