本文整理汇总了PHP中ezcTemplateCursor类的典型用法代码示例。如果您正苦于以下问题:PHP ezcTemplateCursor类的具体用法?PHP ezcTemplateCursor怎么用?PHP ezcTemplateCursor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ezcTemplateCursor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: parseCurrent
/**
* Parses the boolean types by looking for either 'true' or 'false'.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
if (!$cursor->atEnd()) {
// @todo This should check that there is no alphabetical characters
// after the true|false.
$matches = $cursor->pregMatchComplete("#^(true|false)(?:\\W)#i");
if ($matches === false) {
return false;
}
$name = $matches[1][0];
$lower = strtolower($name);
if ($name !== $lower) {
$this->findNonLowercase();
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_BOOLEAN_NOT_LOWERCASE);
}
$cursor->advance(strlen($name));
$bool = new ezcTemplateLiteralTstNode($this->parser->source, $this->startCursor, $cursor);
$bool->value = $name == 'true';
$this->value = $bool->value;
$this->element = $bool;
$this->appendElement($bool);
return true;
}
return false;
}
开发者ID:zetacomponents,项目名称:template,代码行数:31,代码来源:bool.php
示例2: parseCurrent
/**
* Parses the statements, foreach, while, if, elseif, etc.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
// Check if any control structure names are used.
// Note: The code inside the (?:) brace ensures that the next character
// is not an alphabetical character ie. a word boundary
$matches = $cursor->pregMatchComplete("#^(tr|tr_context|foreach|while|if|elseif|else|switch|case|default|include|return|break|continue|skip|delimiter|increment|decrement|reset|charset|capture)(?:[^a-zA-Z0-9_])#");
if ($matches === false) {
return false;
}
$name = $matches[1][0];
$cursor->advance(strlen($matches[1][0]));
// control structure map
$csMap = array();
$csMap['foreach'] = 'ForeachLoop';
$csMap['for'] = 'ForLoop';
$csMap['while'] = 'WhileLoop';
$csMap['if'] = 'IfCondition';
$csMap['elseif'] = 'IfCondition';
$csMap['else'] = 'IfCondition';
$csMap['switch'] = 'SwitchCondition';
$csMap['case'] = 'SwitchCondition';
$csMap['default'] = 'SwitchCondition';
$csMap['include'] = 'Include';
$csMap['return'] = 'Include';
$csMap['break'] = 'Loop';
$csMap['continue'] = 'Loop';
$csMap['skip'] = 'Delimiter';
$csMap['delimiter'] = 'Delimiter';
$csMap['increment'] = 'Cycle';
$csMap['decrement'] = 'Cycle';
$csMap['reset'] = 'Cycle';
$csMap['charset'] = 'Charset';
$csMap['capture'] = 'Capture';
$csMap['tr'] = 'Translation';
$csMap['tr_context'] = 'TranslationContext';
// tmp
if (!isset($csMap[$name])) {
return false;
}
$parser = 'ezcTemplate' . $csMap[$name] . 'SourceToTstParser';
// tmp
if (!ezcBaseFeatures::classExists($parser)) {
return false;
}
if (!ezcBaseFeatures::classExists($parser)) {
throw new ezcTemplateInternalException("Requested parser class <{$parser}> does not exist");
}
$controlStructureParser = new $parser($this->parser, $this, null);
$this->block->name = $name;
$controlStructureParser->block = $this->block;
if (!$this->parseRequiredType($controlStructureParser)) {
return false;
}
return true;
}
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:61,代码来源:control_structure.php
示例3: parseCurrent
/**
* Parses the expression by using the ezcTemplateExpressionSourceToTstParser class.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
$element = new ezcTemplateLoopTstNode($this->parser->source, $this->startCursor, $cursor, $this->block->name);
if ($this->block->isClosingBlock) {
$element->isClosingBlock = true;
}
$this->findNextElement();
if (!$cursor->match("}")) {
throw new ezcTemplateParserException($this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
$this->appendElement($element);
return true;
}
开发者ID:zetacomponents,项目名称:template,代码行数:19,代码来源:loop.php
示例4: parseCurrent
/**
* Parses the null type.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
if (!$cursor->atEnd()) {
if ($cursor->match("null")) {
$literal = new ezcTemplateLiteralTstNode($this->parser->source, $this->startCursor, $cursor);
$literal->value = null;
$this->element = $literal;
$this->appendElement($literal);
return true;
}
}
return false;
}
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:19,代码来源:null.php
示例5: parseCurrent
/**
* Parses the comment by looking for the end marker * + }.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
$cursor->advance();
if ($cursor->atEnd()) {
return false;
}
$checkInlineComment = false;
// Check for a slash after the asterix, this typically means a typo for an inline comment
// Better give an error for this to warn the user.
if ($cursor->current() == '/') {
$checkInlineComment = true;
}
$endPosition = $cursor->findPosition('*}');
if ($endPosition === false) {
return false;
}
// If we found an end for an inline comment we need to check if there
// is an end for an inline comment
if ($checkInlineComment) {
$commentCursor = $cursor->cursorAt($cursor->position, $endPosition);
$commentCursor->advance();
$inlineCommentPosition = $commentCursor->findPosition('*/');
// We found the end of the inline comment, this is most likely a user error
if ($inlineCommentPosition !== false) {
$cursor->gotoPosition($inlineCommentPosition);
return false;
}
}
// reached end of comment
$cursor->gotoPosition($endPosition + 2);
$commentBlock = new ezcTemplateDocCommentTstNode($this->parser->source, clone $this->startCursor, clone $cursor);
$commentBlock->commentText = substr($commentBlock->text(), 2, -2);
$this->appendElement($commentBlock);
return true;
}
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:41,代码来源:doc_comment.php
示例6: parseCurrent
/**
* 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;
}
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:21,代码来源:float.php
示例7: parseCurrent
/**
* 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;
}
开发者ID:bmdevel,项目名称:ezc,代码行数:21,代码来源:integer.php
示例8: parseCurrent
/**
* 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;
}
开发者ID:zetacomponents,项目名称:template,代码行数:21,代码来源:identifier.php
示例9: parseCurrent
/**
* Parses the comment by looking for the end marker * + /.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
if (!$cursor->atEnd()) {
$cursor->advance(2);
$tagPos = $cursor->findPosition('*/');
if ($tagPos !== false) {
// reached end of comment
$cursor->gotoPosition($tagPos + 2);
$commentBlock = new ezcTemplateBlockCommentTstNode($this->parser->source, $this->startCursor, clone $cursor);
$commentBlock->commentText = substr($commentBlock->text(), 2, -2);
$this->appendElement($commentBlock);
return true;
}
}
return false;
}
开发者ID:bmdevel,项目名称:ezc,代码行数:22,代码来源:block_comment.php
示例10: parseCurrent
/**
* Parses the comment by looking for the end marker \n.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
$cutOff = false;
if (!$cursor->atEnd()) {
$cursor->advance(2);
$matches = $cursor->pregMatchComplete("#^([^}\r\n]*)(?:(?:})|(\r|\r\n|\n))#");
if ($matches) {
// reached end of comment
$cutOff = false;
if (isset($matches[2])) {
$cursor->advance($matches[2][1] + strlen($matches[2][0]));
// Do not include the newline itself in the comment.
$cutOff = -1;
} else {
$cursor->advance($matches[1][1] + strlen($matches[1][0]));
}
} else {
$cursor->gotoEnd();
}
$commentBlock = new ezcTemplateEolCommentTstNode($this->parser->source, $this->startCursor, clone $cursor);
if ($cutOff) {
$commentBlock->commentText = substr($commentBlock->text(), 2, $cutOff);
} else {
$commentBlock->commentText = substr($commentBlock->text(), 2);
}
$this->appendElement($commentBlock);
return true;
}
return false;
}
开发者ID:zetacomponents,项目名称:template,代码行数:36,代码来源:eol_comment.php
示例11: parseCurrent
/**
* Parses the types by utilizing:
* - ezcTemplateFloatSourceToTstParser for float types.
* - ezcTemplateIntegerSourceToTstParser for integer types.
* - ezcTemplateStringSourceToTstParser for string types.
* - ezcTemplateBoolSourceToTstParser for boolean types.
* - ezcTemplateArraySourceToTstParser for array types.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
$failedParser = null;
if (!$cursor->atEnd()) {
// Try parsing the various type types until one is found
$failedCursor = clone $cursor;
$types = array('Float', 'Integer', 'String', 'Bool', 'Array', 'Null');
foreach ($types as $type) {
if ($this->parseOptionalType($type)) {
$this->lastCursor->copy($this->startCursor);
$this->value = $this->lastParser->value;
$this->element = $this->lastParser->element;
return true;
}
}
}
return false;
}
开发者ID:bmdevel,项目名称:ezc,代码行数:29,代码来源:literal.php
示例12: parseCurrent
/**
* Parses the expression by using the ezcTemplateExpressionSourceToTstParser class.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
if ($this->block->name == "charset") {
$charset = new ezcTemplateCharsetTstNode($this->parser->source, $this->startCursor, $cursor);
$this->findNextElement();
if (!$this->parseOptionalType('String', null, false)) {
throw new ezcTemplateSourceToTstParserException($this, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_STRING);
}
$charset->name = $this->lastParser->value;
$this->findNextElement();
if (!$cursor->match("}")) {
throw new ezcTemplateParserException($this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
$this->appendElement($charset);
return true;
}
return false;
}
开发者ID:bmdevel,项目名称:ezc,代码行数:24,代码来源:charset.php
示例13: parseCurrent
/**
* Parses the expression by using the ezcTemplateExpressionSourceToTstParser class.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
$name = $this->block->name;
// handle closing block
if ($this->block->isClosingBlock) {
// skip whitespace and comments
$this->findNextElement();
if (!$cursor->match('}')) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
$el = new ezcTemplateIfConditionTstNode($this->parser->source, $this->startCursor, $cursor);
$el->name = 'if';
$el->isClosingBlock = true;
$this->appendElement($el);
return true;
}
$condition = null;
$this->findNextElement();
if ($name != 'else') {
if (!$this->parseRequiredType('Expression', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_EXPRESSION);
}
$condition = $this->lastParser->rootOperator;
if ($condition instanceof ezcTemplateModifyingOperatorTstNode) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_MODIFYING_EXPRESSION_NOT_ALLOWED);
}
$this->findNextElement();
}
if (!$cursor->match('}')) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
$cb = new ezcTemplateConditionBodyTstNode($this->parser->source, $this->startCursor, $cursor);
$cb->condition = $condition;
$cb->name = $name;
if ($name == 'if') {
$el = new ezcTemplateIfConditionTstNode($this->parser->source, $this->startCursor, $cursor);
$el->children[] = $cb;
$el->name = 'if';
$this->appendElement($el);
} else {
$this->appendElement($cb);
}
return true;
}
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:50,代码来源:if_condition.php
示例14: parseCurrent
/**
* Parses the variable types by looking for a dollar sign followed by an
* identifier. The identifier is parsed by using ezcTemplateIdentifierSourceToTstParser.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
if (!$cursor->atEnd()) {
if ($cursor->match('$')) {
if ($cursor->current() == '#') {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_INVALID_VARIABLE_NAME, ezcTemplateSourceToTstErrorMessages::LNG_INVALID_NAMESPACE_ROOT_MARKER);
}
if ($cursor->current() == ':') {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_INVALID_VARIABLE_NAME, ezcTemplateSourceToTstErrorMessages::LNG_INVALID_NAMESPACE_MARKER);
}
if (!$this->parseRequiredType('Identifier', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_INVALID_VARIABLE_NAME, ezcTemplateSourceToTstErrorMessages::MSG_INVALID_IDENTIFIER);
return false;
}
$this->variableName = $this->lastParser->identifierName;
$variable = new ezcTemplateVariableTstNode($this->parser->source, $this->startCursor, $cursor);
$variable->name = $this->variableName;
$this->element = $variable;
$this->appendElement($variable);
return true;
}
}
return false;
}
开发者ID:bmdevel,项目名称:ezc,代码行数:31,代码来源:variable.php
示例15: parseCurrent
/**
* Parses the string types by looking for single or double quotes to start
* the string.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
if (!$cursor->atEnd()) {
$char = $cursor->current();
if ($char == '"' || $char == "'") {
$string = new ezcTemplateLiteralTstNode($this->parser->source, $this->startCursor, $cursor);
$string->quoteType = $char == "'" ? ezcTemplateLiteralTstNode::SINGLE_QUOTE : ezcTemplateLiteralTstNode::DOUBLE_QUOTE;
$cursor->advance();
$nextChar = $cursor->current();
if ($nextChar === $char) {
// We know it is an empty string, no need to extract
$str = "";
$string->value = $str;
$this->value = $string->value;
$this->element = $string;
$this->appendElement($string);
$cursor->advance();
return true;
} else {
// Match:
// ([^{$char}\\\\]|\A) : Matches non quote ('"', "'"), non backslash (\), or does match the begin of the statement.
// (\\\\(\\\\|{$char}))* : Eat double slashes \\ and slash quotes: \' or \".
$matches = $cursor->pregMatchComplete("#(?:([^{$char}\\\\]|\\A)(\\\\(\\\\|{$char}))*){$char}#");
if ($matches === false) {
return false;
}
$cursor->advance($matches[0][1] + strlen($matches[0][0]));
$str = (string) $this->startCursor->subString($cursor->position);
$str = substr($str, 1, -1);
$string->value = $str;
$this->value = $string->value;
$this->element = $string;
$this->appendElement($string);
return true;
}
}
}
return false;
}
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:46,代码来源:string.php
示例16: atEnd
/**
* Returns true if the current character is a curly bracket (}) which means
* the end of the block.
*
* @param ezcTemplateCursor $cursor
* @param ezcTemplateTstNode $operator
* @param bool $finalize
* @return bool
*
* @todo Can be removed?
*/
public function atEnd(ezcTemplateCursor $cursor, $operator, $finalize = true)
{
return $cursor->current(1) == "}" || $cursor->current(1) == ",";
}
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:15,代码来源:include.php
示例17: parseCurrent
/**
* Parses the expression by using the ezcTemplateExpressionSourceToTstParser class.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
// Disable caching.
// return false;
if ($cursor->match("dynamic")) {
$cacheNode = new ezcTemplateDynamicBlockTstNode($this->parser->source, $this->startCursor, $cursor);
if ($this->block->isClosingBlock) {
$cacheNode->isClosingBlock = true;
}
$this->appendElement($cacheNode);
$this->findNextElement($cursor);
if (!$cursor->match("}")) {
throw new ezcTemplateParserException($this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
return true;
}
$cacheNode = null;
if ($cursor->match("cache_template")) {
$this->parser->hasCacheBlocks = true;
$cacheNode = new ezcTemplateCacheTstNode($this->parser->source, $this->startCursor, $cursor);
$cacheNode->type = ezcTemplateCacheTstNode::TYPE_CACHE_TEMPLATE;
} elseif ($cursor->match("cache_block")) {
$this->parser->hasCacheBlocks = true;
$cacheNode = new ezcTemplateCacheBlockTstNode($this->parser->source, $this->startCursor, $cursor);
// $cacheNode->type = ezcTemplateCacheTstNode::TYPE_CACHE_BLOCK;
if ($this->block->isClosingBlock) {
$cacheNode->isClosingBlock = true;
// Set closing block.
$this->appendElement($cacheNode);
$this->findNextElement($cursor);
if (!$cursor->match("}")) {
throw new ezcTemplateParserException($this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
return true;
}
} else {
return false;
}
// We do have an opening cache_block or cache_template.
$this->findNextElement($cursor);
while ($matches = $cursor->pregMatchComplete("#^([a-zA-Z_][a-zA-Z0-9_-]*)(?:[^a-zA-Z])#i")) {
$name = $matches[1][0];
$cursor->advance(strlen($name));
$this->findNextElement($cursor);
if ($name == "keys") {
do {
$this->findNextElement($cursor);
if (!$this->parseOptionalType("Expression", $this->currentCursor, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_VARIABLE);
}
$cacheNode->keys[] = $this->lastParser->children[0];
$this->findNextElement($cursor);
} while ($cursor->match(","));
// $this->parser->template->configuration->cacheSystem->appendCacheKeys( $values );
} elseif ($name == "ttl") {
// The parameter has an expression.
if (!$this->parseOptionalType('Expression', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_EXPRESSION);
}
if ($this->lastParser->rootOperator instanceof ezcTemplateModifyingOperatorTstNode) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_MODIFYING_EXPRESSION_NOT_ALLOWED);
}
// Append the parameter to the "namedParameters" array.
$cacheNode->ttl = $this->lastParser->rootOperator;
} else {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, "Unknown keyword: " . $name);
}
}
$this->appendElement($cacheNode);
$this->findNextElement($cursor);
if (!$cursor->match("}")) {
throw new ezcTemplateParserException($this->parser->source, $cursor, $cursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
return true;
}
开发者ID:bmdevel,项目名称:ezc,代码行数:81,代码来源:cache.php
示例18: parseCurrent
/**
* 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;
}
}
}
开发者ID:jacomyma,项目名称:GEXF-Atlas,代码行数:85,代码来源:array.php
示例19: handleSuccessfulResult
/**
* Performs checking on the parse result.
*
* The method will check if there are more text after the current cursor
* location and if so appends a new ezcTextElement object containing the
* text.
*
* It also checks if the $lastBlock contains the current program parser, if it
* does not it means the nesting in the current source code is incorrect.
*
* @param ezcTemplateCursor $lastCursor
* @param ezcTemplateCursor $cursor
*
* @throws ezcTemplateParserException if blocks are incorrectly nested.
*
* @return void
*/
protected function handleSuccessfulResult(ezcTemplateCursor $lastCursor, ezcTemplateCursor $cursor)
{
if ($lastCursor->length($cursor) > 0) {
$textElement = new ezcTemplateTextBlockTstNode($this->parser->source, clone $lastCursor, clone $cursor);
$this->handleElements(array($textElement));
}
if ($this->lastBlock === null) {
throw new ezcTemplateInternalException("lastBlock is null, should have been a parser element object.");
}
if (!$this->lastBlock instanceof ezcTemplateProgramTstNode) {
$parents = array();
// Calculate level of the last block, this used to indent the last block
$level = 0;
$block = $this->lastBlock;
while ($block->parentBlock !== null && !$block->parentBlock instanceof ezcTemplateProgramTstNode) {
if ($block === $block->parentBlock) {
throw new ezcTemplateInternalException("Infinite recursion found in parser element " . get_class($block));
}
++$level;
$block = $block->parentBlock;
}
$block = $this->lastBlock;
// Go trough all parents until the root is reached
while ($block->parentBlock !== null && !$block->parentBlock instanceof ezcTemplateProgramTstNode) {
if ($block === $block->parentBlock) {
throw new ezcTemplateInternalException("Infinite recursion found in parser element " . get_class($block));
}
$block = $block->parentBlock;
--$level;
$parents[] = str_repeat(" ", $level) . "{" . $block->name . "} @ {$block->startCursor->line}:{$block->startCursor->column}:";
}
$parents = array_reverse($parents);
$treeText = "The current nesting structure:\n" . join("\n", $parents);
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, "Incorrect nesting in code, close block {/" . $this->lastBlock->name . "} expected.");
}
// Get rid of whitespace for the block line of the program element
$this->parser->trimBlockLine($this->program);
}
开发者ID:zetacomponents,项目名称:template,代码行数:55,代码来源:program.php
示例20: parseCurrent
/**
* Parses the expression by using the ezcTemplateExpressionSourceToTstParser class.
*
* @param ezcTemplateCursor $cursor
* @return bool
*/
protected function parseCurrent(ezcTemplateCursor $cursor)
{
$el = new ezcTemplateTranslationTstNode($this->parser->source, $this->startCursor, $cursor);
$this->findNextElement();
if (!$this->parseRequiredType('String', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_STRING);
}
$el->string = $this->lastParser->element;
// empty keys and values before the loop, so that multiple vars statements can work
$currentKeys = $currentArray = array();
$foundContext = $foundComment = false;
$elementNr = 0;
// the loop that parses context/comment/vars
do {
$foundSomething = false;
$this->findNextElement();
// Check if we have a context
if ($cursor->match('context')) {
if ($foundContext) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->lastCursor, ezcTemplateSourceToTstErrorMessages::MSG_CONTEXT_DUPLICATE);
}
$this->findNextElement();
if (!$this->parseRequiredType('String', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_STRING);
}
$el->context = $this->lastParser->element;
$foundSomething = $foundContext = true;
}
// Check if we have a comment
if ($cursor->match('comment')) {
if ($foundComment) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_COMMENT_DUPLICATE);
}
$this->findNextElement();
if (!$this->parseRequiredType('String', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_STRING);
}
$el->comment = $this->lastParser->element;
$foundSomething = $foundComment = true;
}
// Check the variables.
if ($cursor->match('vars')) {
do {
// save the cursor so that we can restore it to retry a different sequence
$saveCursor = clone $cursor;
// try to parse string => expression
if ($elements = $this->parseSequence(array(array('type' => 'String'), array('type' => 'Character', 'args' => '=>'), array('type' => 'Expression')))) {
$currentKeys[$elementNr] = $elements[0];
$currentArray[$elementNr] = $elements[1];
$elementNr++;
continue;
}
// restore the cursor if not found
$this->currentCursor = $saveCursor;
$cursor = $saveCursor;
// try to parse integer => expression
if ($elements = $this->parseSequence(array(array('type' => 'Integer'), array('type' => 'Character', 'args' => '=>'), array('type' => 'Expression')))) {
$currentKeys[$elementNr] = $elements[0];
$currentArray[$elementNr] = $elements[1];
$elementNr++;
continue;
}
// restore the cursor if not found
$this->currentCursor = $saveCursor;
$cursor = $saveCursor;
if (!$this->parseRequiredType('Expression', null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, "Expecting a valid variable definition (String => Expression; Integer => Expression; or Expression).");
}
$expression = $this->lastParser->rootOperator;
unset($currentKeys[$elementNr]);
$currentArray[$elementNr] = $expression;
$elementNr++;
} while ($cursor->match(','));
$array = new ezcTemplateLiteralArrayTstNode($this->parser->source, $this->startCursor, $cursor);
$array->keys = $currentKeys;
$array->value = $currentArray;
$el->variables = $array;
$foundSomething = true;
}
} while ($foundSomething);
if (!$this->parentParser->atEnd($cursor, null, false)) {
throw new ezcTemplateParserException($this->parser->source, $this->startCursor, $this->currentCursor, ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_CURLY_BRACKET_CLOSE);
}
$cursor->advance();
$this->appendElement($el);
return true;
}
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:93,代码来源:translation.php
注:本文中的ezcTemplateCursor类示例整理自Github/MSDocs等源码及 |
请发表评论