Refectory term parser (if ->switch)

This commit is contained in:
bzick 2015-06-01 23:36:30 +03:00
parent ec890cc819
commit 30921d3500

View File

@ -782,14 +782,20 @@ class Template extends Render
} else {
$unary = "";
}
if ($tokens->is(T_LNUMBER, T_DNUMBER)) {
switch($tokens->key()) {
case T_LNUMBER:
case T_DNUMBER:
$code = $unary . $this->parseScalar($tokens, true);
} elseif ($tokens->is(T_CONSTANT_ENCAPSED_STRING, '"', T_ENCAPSED_AND_WHITESPACE)) {
break;
case T_CONSTANT_ENCAPSED_STRING:
case '"':
case T_ENCAPSED_AND_WHITESPACE:
if ($unary) {
throw new UnexpectedTokenException($tokens->back());
}
$code = $this->parseScalar($tokens, true);
} elseif ($tokens->is(T_VARIABLE)) {
break;
case T_VARIABLE:
$code = $this->parseVariable($tokens);
if ($tokens->is("(") && $tokens->hasBackList(T_STRING, T_OBJECT_OPERATOR)) {
if ($this->_options & Fenom::DENY_METHODS) {
@ -810,20 +816,25 @@ class Template extends Render
$code = $unary . $code;
}
}
} elseif ($tokens->is('$')) {
break;
case '$':
$code = $unary . $this->parseAccessor($tokens, $is_var);
} elseif ($tokens->is(Tokenizer::MACRO_INCDEC)) {
break;
case T_DEC:
case T_INC:
if($this->_options & Fenom::FORCE_VERIFY) {
$var = $this->parseVariable($tokens);
$code = $unary . '(isset(' . $var . ') ? ' . $tokens->getAndNext() . $this->parseVariable($tokens).' : null)';
} else {
$code = $unary . $tokens->getAndNext() . $this->parseVariable($tokens);
}
} elseif ($tokens->is("(")) {
break;
case '(':
$tokens->next();
$code = $unary . "(" . $this->parseExpr($tokens) . ")";
$tokens->need(")")->next();
} elseif ($tokens->is(T_STRING)) {
break;
case T_STRING:
if ($tokens->isSpecialVal()) {
$code = $unary . $tokens->getAndNext();
} elseif ($tokens->isNext("(") && !$tokens->getWhitespace()) {
@ -844,7 +855,9 @@ class Template extends Render
} else {
return false;
}
} elseif ($tokens->is(T_ISSET, T_EMPTY)) {
break;
case T_ISSET:
case T_EMPTY:
$func = $tokens->getAndNext();
if ($tokens->is("(") && $tokens->isNext(T_VARIABLE)) {
$code = $unary . $func . "(" . $this->parseVariable($tokens->next()) . ")";
@ -852,16 +865,20 @@ class Template extends Render
} else {
throw new TokenizeException("Unexpected token " . $tokens->getNext() . ", isset() and empty() accept only variables");
}
} elseif ($tokens->is('[')) {
break;
case '[':
if ($unary) {
throw new UnexpectedTokenException($tokens->back());
}
$code = $this->parseArray($tokens);
} elseif ($unary) {
break;
default:
if ($unary) {
throw new UnexpectedTokenException($tokens->back());
} else {
return false;
}
}
if (($allows & self::TERM_MODS) && $tokens->is('|')) {
$code = $this->parseModifier($tokens, $code);
$is_var = false;