/** * @return bool 若标签到达关闭,返回true,否则false */ public function parseTagBreak(TokenStream $tokenStream) { $endTagName = 'end' . $this->getTagName(); if ($tokenStream->test(Token::TYPE_NAME, $endTagName)) { $tokenStream->next(); $tokenStream->expect(Token::TYPE_TAG_END); $this->isClosed = true; return true; } else { return false; } }
public function parseTagBreak(TokenStream $tokenStream) { if ($tokenStream->test(Token::TYPE_NAME, 'elseif')) { $token = $tokenStream->next(); //XXX fix to check elseif after else $this->elseIfConditionNodeList[] = $this->getExpressionParser()->parse($tokenStream); $tokenStream->expect(Token::TYPE_TAG_END); $this->elseIfBodyNodesList[] = $this->rootParser->parseBody($this); return true; } if ($tokenStream->test(Token::TYPE_NAME, 'else')) { $tokenStream->next(); $tokenStream->expect(Token::TYPE_TAG_END); $this->elseBodyNode = $this->rootParser->parseBody($this); return true; } return parent::parseTagBreak($tokenStream); }
public function parsePrimary() { //unary if ($this->inUnaryOperator($this->tokenStream->lookNext())) { return $this->parseUnary(); } //bracket if ($this->tokenStream->test(Token::TYPE_PUNCTUATION, '(')) { return $this->parseBracket(); } //array if ($this->tokenStream->test(Token::TYPE_PUNCTUATION, '[') || $this->tokenStream->test(Token::TYPE_PUNCTUATION, '{')) { return $this->parseArray(); } if ($this->tokenStream->test(Token::TYPE_NAME)) { //constant val eg: null if (in_array(strtolower($this->tokenStream->lookNext()->getValue()), ['null', 'true', 'false'])) { return new ConstantNode($this->tokenStream->next()); } else { //function eg: test() return $this->parseFunction(); } } //attribute eg: $x | $x.varName | $x.func(1,2) | $x["y"] if ($this->tokenStream->test(Token::TYPE_VARIABLE)) { return $this->parseAttributeOrMethod(); } $token = $this->tokenStream->next(); switch ($token->getType()) { case Token::TYPE_NUMBER: case Token::TYPE_STRING: return new ConstantNode($token); default: throw new ParseException($this->tokenStream->getFileName(), 'unexpected ' . $token->getValue(), $token->line, $token->col); } }
public function parse(TokenStream $tokenStream) { while (!$tokenStream->isEOF() && $tokenStream->lookNext()->getType() != Token::TYPE_TAG_END) { $paramNameToken = $tokenStream->expect(Token::TYPE_NAME); $tokenStream->expect(Token::TYPE_OPERATOR, '='); $expressionNode = $this->getExpressionParser()->parse($tokenStream); $this->attributes[$paramNameToken->getValue()] = $expressionNode; } $tokenStream->expect(Token::TYPE_TAG_END); foreach ($this->getRequiredAttributes() as $attributeName) { if (!isset($this->attributes[$attributeName])) { throw new ParseException($tokenStream->getFileName(), sprintf('%s require %s attribute', $this->getTagName(), $attributeName), $this->tagToken->line, $this->tagToken->col); } } if ($this->hasCloseTag()) { $this->bodyNode = $this->rootParser->parseBody($this); } return new CommonTagNode($this); }
/** * @param $tokenStream TokenStream * @return AbstractNode */ public function parse(TokenStream $tokenStream) { $this->tokenStream = $tokenStream; $bodyNode = $this->parseBody(null); return new RootNode($tokenStream->getFileName(), $bodyNode->childNodes); }