/** * Parse a pre modifying operator * * @param ezcTemplateCursor $cursor * @return bool */ protected function parsePreModifyingOperator($cursor) { if ($cursor->match('++')) { $operatorStartCursor = clone $cursor; $operator = new ezcTemplatePreIncrementOperatorTstNode($this->parser->source, clone $this->lastCursor, $cursor); } elseif ($cursor->match('--')) { $operatorStartCursor = clone $cursor; $operator = new ezcTemplatePreDecrementOperatorTstNode($this->parser->source, clone $this->lastCursor, $cursor); } else { return false; } if ($this->currentOperator === null) { $this->currentOperator = $operator; } else { // All pre operators should not sort precedence at this // moment so just append it to the current operator. $this->currentOperator->appendParameter($operator); $operator->parentOperator = $this->currentOperator; $this->currentOperator = $operator; } $this->lastCursor->copy($cursor); return true; }
/** * * @param ezcTemplateSource $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end */ public function __construct(ezcTemplateSourceCode $source, $start, $end) { parent::__construct($source, $start, $end, 4, 1, self::LEFT_ASSOCIATIVE, '&&'); }
/** * Initialise operator with source and cursor positions. * * @param ezcTemplateSource $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end */ public function __construct(ezcTemplateSourceCode $source, $start, $end) { parent::__construct($source, $start, $end, 5, 2, self::NON_ASSOCIATIVE, '==='); }
/** * * @param ezcTemplateSource $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end */ public function __construct(ezcTemplateSourceCode $source, $start, $end) { parent::__construct($source, $start, $end, 9, 3, self::NON_ASSOCIATIVE, '!'); $this->maxParameterCount = 1; }
/** * Initialize element with source and cursor positions. * * @param ezcTemplateSourceCode $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end * @param int $precedence * @param int $order * @param int $associativity * @param string $symbol */ public function __construct(ezcTemplateSourceCode $source, $start, $end, $precedence, $order, $associativity, $symbol) { parent::__construct($source, $start, $end, $precedence, $order, $associativity, $symbol); }
/** * * @param ezcTemplateSource $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end */ public function __construct(ezcTemplateSourceCode $source, $start, $end) { parent::__construct($source, $start, $end, 11, 2, self::LEFT_ASSOCIATIVE, '->'); $this->sourceOperand = null; $this->property = null; }
/** * Initialise operator with source and cursor positions. * * @param ezcTemplateSourceCode $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end */ public function __construct(ezcTemplateSourceCode $source, $start, $end) { // TODO change this. parent::__construct($source, $start, $end, 6, 5, self::NON_ASSOCIATIVE, '..'); }
/** * Constructs a new ezcTemplateArrayFetchOperatorTstNode * * @param ezcTemplateSourceCode $source * @param ezcTemplateCursor $start * @param ezcTemplateCursor $end */ public function __construct(ezcTemplateSourceCode $source, $start, $end) { parent::__construct($source, $start, $end, 11, 1, self::RIGHT_ASSOCIATIVE, '[...]'); $this->sourceOperand = null; $this->arrayKeys = array(); }
/** * Figures out the operator precedence for the new operator $newOperator * by examining it with the current operator element. * * @param ezcTemplateTstNode $currentOperator Either the current operator * element or general parameter * element. * @param ezcTemplateOperatorTstNode $newOperator The newly found operator. * @return ezcTemplateOperatorTstNode */ public function handleOperatorPrecedence($currentOperator, ezcTemplateOperatorTstNode $newOperator) { if ($currentOperator === null) { throw new ezcTemplateInternalException("No current operator/operand has been set"); } if (!$currentOperator instanceof ezcTemplateOperatorTstNode) { // Note this operand should be prepended (not appended) in case // the new operator already have some parameters set. $newOperator->prependParameter($currentOperator); return $newOperator; } if ($currentOperator->precedence > $newOperator->precedence) { // Controls whether the $newOperator should be become the new root operator or not // This happens if all operators have a higher precedence than the new operator. $asRoot = false; // Find parent with less or equal precedence while ($currentOperator->precedence > $newOperator->precedence) { if ($currentOperator->parentOperator === null) { $asRoot = true; break; } $currentOperator = $currentOperator->parentOperator; } if ($asRoot) { $newOperator->prependParameter($currentOperator); $currentOperator->parentOperator = $newOperator; return $newOperator; } } // Check if the operators can merge parameters, reasons for this can be: // - The operators are of the same class // - The : part of a conditional operator is found if ($currentOperator->canMergeParametersOf($newOperator)) { $currentOperator->mergeParameters($newOperator); return $currentOperator; } if ($currentOperator->precedence < $newOperator->precedence) { $parameter = $currentOperator->getLastParameter(); $currentOperator->setLastParameter($newOperator); $newOperator->parentOperator = $currentOperator; if ($parameter !== null) { $newOperator->prependParameter($parameter); } return $newOperator; } // Same precedence, order must be checked if ($currentOperator->precedence == $newOperator->precedence) { $parentOperator = $currentOperator->parentOperator; $parameter = $currentOperator->getLastParameter(); $newOperator->prependParameter($currentOperator); if ($parentOperator !== null) { $parentOperator->setLastParameter($newOperator); } $currentOperator->parentOperator = $newOperator; $newOperator->parentOperator = $parentOperator; return $newOperator; } throw new ezcTemplateInternalException("Should not reach this place."); }