/** * @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); } }