Esempio n. 1
0
 /**
  * Parses the float types by looking for float expression.
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseCurrent(ezcTemplateCursor $cursor)
 {
     if (!$cursor->atEnd()) {
         $matches = $cursor->pregMatch("#^(?:[0-9]+(([eE][+-]?[0-9]+)|((\\.[0-9]+)([eE][+-]?[0-9]+)?)))#");
         if ($matches !== false) {
             $float = new ezcTemplateLiteralTstNode($this->parser->source, $this->startCursor, $cursor);
             $float->value = (double) $matches;
             $this->value = $float->value;
             $this->element = $float;
             $this->appendElement($float);
             return true;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Parses the integer types by looking for numerical characters.
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseCurrent(ezcTemplateCursor $cursor)
 {
     if (!$cursor->atEnd()) {
         $matches = $cursor->pregMatch("#^-?[0-9]+#");
         if ($matches !== false) {
             $integer = new ezcTemplateLiteralTstNode($this->parser->source, $this->startCursor, $cursor);
             $integer->value = (int) $matches;
             $this->value = $integer->value;
             $this->element = $integer;
             $this->appendElement($integer);
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Parses the identifier types by looking for allowed characters.
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseCurrent(ezcTemplateCursor $cursor)
 {
     if (!$cursor->atEnd()) {
         $matches = $cursor->pregMatch("#^[a-zA-Z_][a-zA-Z0-9_]*#");
         if ($matches !== false) {
             $identifier = new ezcTemplateIdentifierTstNode($this->parser->source, $this->startCursor, $cursor);
             $identifier->value = (string) $matches;
             $this->identifierName = $identifier->value;
             $this->element = $identifier;
             $this->appendElement($identifier);
             return true;
         }
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Parses the array types by looking for 'array(...)' and then using the
  * generic expression parser (ezcTemplateExpressionSourceToTstParser) to fetch the
  * keys and values.
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseCurrent(ezcTemplateCursor $cursor)
 {
     // skip whitespace and comments
     if (!$this->findNextElement()) {
         return false;
     }
     $name = $cursor->pregMatch("#^array[^\\w]#i", false);
     if ($name === false) {
         return false;
     }
     $lower = strtolower($name);
     if ($name !== $lower) {
         $this->findNonLowercase();
         throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_ARRAY_NOT_LOWERCASE);
     }
     $cursor->advance(5);
     // skip whitespace and comments
     $this->findNextElement();
     if (!$cursor->match('(')) {
         throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_ROUND_BRACKET_OPEN);
     }
     $currentArray = array();
     $currentKeys = array();
     $expectItem = true;
     $elementNumber = 0;
     while (true) {
         // skip whitespace and comments
         if (!$this->findNextElement()) {
             throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_ROUND_BRACKET_CLOSE);
         }
         if ($cursor->current() == ')') {
             $cursor->advance();
             $array = new ezcTemplateLiteralArrayTstNode($this->parser->source, $this->startCursor, $cursor);
             $array->keys = $currentKeys;
             $array->value = $currentArray;
             $this->element = $array;
             $this->appendElement($array);
             return true;
         }
         if (!$expectItem) {
             throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_ROUND_BRACKET_CLOSE_OR_COMMA);
         }
         // Check for type
         if (!$expectItem || !$this->parseRequiredType('Expression')) {
             throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_LITERAL);
         }
         $this->findNextElement();
         if ($cursor->match('=>')) {
             // Found the array key. Store it, and continue with the search for the value.
             $currentKeys[$elementNumber] = $this->lastParser->rootOperator;
             $this->findNextElement();
             // We have the key => value syntax so we need to find the value
             if (!$this->parseRequiredType('Expression')) {
                 throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_LITERAL);
             }
             // Store the value.
             $currentArray[$elementNumber] = $this->lastParser->rootOperator;
             $elementNumber++;
         } else {
             // Store the value.
             $currentArray[$elementNumber] = $this->lastParser->rootOperator;
             $elementNumber++;
         }
         if ($this->lastParser->rootOperator instanceof ezcTemplateModifyingOperatorTstNode) {
             throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_MODIFYING_EXPRESSION_NOT_ALLOWED);
         }
         $this->findNextElement();
         // We allow a comma after the key/value even if there are no more
         // entries. This is compatible with PHP syntax.
         if ($cursor->match(',')) {
             $this->findNextElement();
             $expectItem = true;
         } else {
             $expectItem = false;
         }
     }
 }
Esempio n. 5
0
 /**
  * Parse a parameter
  *
  * @param ezcTemplateCursor $cursor
  * @return bool
  */
 protected function parseParameter($cursor)
 {
     // Without this, the expression parser keeps on reading.
     if ($cursor->match(')', false)) {
         return false;
     }
     $this->readingParameter = true;
     $startCursor = clone $cursor;
     $namedParameter = $cursor->pregMatch("#^[a-zA-Z_][a-zA-Z0-9_]*#");
     if ($namedParameter !== false) {
         $this->findNextElement();
         if (!$cursor->match("=")) {
             $namedParameter = false;
         }
     }
     if ($namedParameter === false) {
         $cursor->copy($startCursor);
     }
     // Check for expression, the parser will call self::atEnd() to check for end of expression.
     $expressionStartCursor = clone $cursor;
     $expressionParser = new ezcTemplateExpressionSourceToTstParser($this->parser, $this, null);
     $expressionParser->allowIdentifier = true;
     if (!$this->parseRequiredType($expressionParser) || $this->lastParser->currentOperator === null) {
         return false;
     }
     $rootOperator = $this->lastParser->currentOperator;
     if ($rootOperator instanceof ezcTemplateOperatorTstNode) {
         $rootOperator = $rootOperator->getRoot();
     }
     if ($rootOperator instanceof ezcTemplateModifyingOperatorTstNode) {
         throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, sprintf(ezcTemplateSourceToTstErrorMessages::MSG_PARAMETER_CANNOT_BE_MODIFYING_BLOCK, $this->parameterCount));
     }
     if ($namedParameter !== false) {
         if (isset($this->functionCall->parameters[$namedParameter])) {
             throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, sprintf(ezcTemplateSourceToTstErrorMessages::MSG_NAMED_PARAMETER_ALREADY_ASSIGNED, $namedParameter));
         }
         $this->functionCall->parameters[$namedParameter] = $rootOperator;
     } else {
         $this->functionCall->appendParameter($rootOperator);
     }
     $this->readingParameter = false;
     return true;
 }