opened parenthesis converted to class field

This commit is contained in:
Andrei Sozonov
2015-10-06 10:48:39 +03:00
parent eb1755efbf
commit c3a5dfb681
3 changed files with 15 additions and 10 deletions
@@ -111,7 +111,8 @@ class DomainPart extends Parser
}
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments($openedParenthesis);
$this->parseComments();
$openedParenthesis += $this->getOpenedParenthesis();
$this->lexer->moveNext();
$tmpPrev = $this->lexer->getPrevious();
if ($tmpPrev['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
@@ -24,7 +24,8 @@ class LocalPart extends Parser
}
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments($openedParenthesis);
$this->parseComments();
$openedParenthesis += $this->getOpenedParenthesis();
}
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
if ($openedParenthesis === 0) {
+11 -8
View File
@@ -9,6 +9,7 @@ abstract class Parser
{
protected $warnings = array();
protected $lexer;
protected $openedParenthesis = 0;
public function __construct(EmailLexer $lexer)
{
@@ -22,6 +23,12 @@ abstract class Parser
abstract public function parse($str);
/** @return int */
public function getOpenedParenthesis()
{
return $this->openedParenthesis;
}
/**
* validateQuotedPair
*/
@@ -35,18 +42,14 @@ abstract class Parser
$this->warnings[] = EmailValidator::DEPREC_QP;
}
/**
* @param int $openedParenthesis
* @return string the comment
*/
protected function parseComments(&$openedParenthesis = 0)
protected function parseComments()
{
$openedParenthesis++;
$this->openedParenthesis = 1;
$this->isUnclosedComment();
$this->warnings[] = EmailValidator::CFWS_COMMENT;
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
$openedParenthesis++;
$this->openedParenthesis++;
}
$this->warnEscaping();
$this->lexer->moveNext();
@@ -164,7 +167,7 @@ abstract class Parser
return $hasClosingQuote;
}
$previous = $this->lexer->getPrevious();
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
if ($previous['type'] === EmailLexer::GENERIC && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
}