/** * 获取下一个token * @see Fl_Token::getNextToken() */ public function getNextToken() { $token = parent::getNextToken(); if ($token || $token === false) { return $token; } $result = ""; while ($this->pos < $this->length) { //如果是圆括号,则匹配对应的结束圆括号 if ($this->text[$this->pos] === '(') { $match = $this->getMatched("(", ")"); $result .= $match; continue; } $char = $this->getNextChar(); if ($this->isWhiteSpace($char) && !preg_match("/^\\s*\\(/", substr($this->text, $this->pos))) { break; } else { $result .= $char; } } if (strlen($result)) { return $this->getTokenInfo(FL_TOKEN_CSS_VALUE_TYPE_COMMON, $result); } return false; }
/** * 获取下一个TOKEN * (non-PHPdoc) * @see Fl_Token::getNextToken() */ public function getNextToken() { $token = parent::getNextToken(); if ($token || $token === false) { return $token; } $char = $this->getCurrentChar(); if ($char === false) { return $this->getLastToken(); } //现在特殊token的配置第一个字符都是<,所有可以优先判断<进行提速 if ($char === Fl_Html_Static::LEFT) { $token = $this->getSpecialToken(); if ($token) { return $token; } } $next = $this->getPosChar($this->pos + 1); //当前字符为<,且下个字符不为<,且下个字符是个合法的tag首字符 if ($char === Fl_Html_Static::LEFT && $next !== Fl_Html_Static::RIGHT && Fl_Html_Static::isTagFirstChar($next)) { $token = $this->readWhile('getTagToken'); if ($this->tagChecked) { $lastChar = $token[strlen($token) - 1]; //检测tag最有一个字符是否是> if ($lastChar !== Fl_Html_Static::RIGHT) { $this->throwException('uncaught tag token ' . $token); } } $type = FL_TOKEN_HTML_TAG_START; if (strpos($token, '</') === 0) { $type = FL_TOKEN_HTML_TAG_END; } elseif (!$this->isXML && strpos($token, Fl_Html_Static::XML_PREFIX) === 0) { $this->isXML = true; $type = FL_TOKEN_XML_HEAD; array_push(Fl_Html_Static::$specialTokens, array(Fl_Html_Static::CDATA_PREFIX, Fl_Html_Static::CDATA_SUFFIX, FL_TOKEN_XML_CDATA)); } return $this->getTokenInfo($type, $token); } $token = $this->readWhile('getTextToken'); if (isset($token)) { $this->newlineBefore -= count(explode(FL_NEWLINE, $token)) - 1; return $this->getTokenInfo(FL_TOKEN_HTML_TEXT, $token); } $this->throwException('uncaught char ' . $char); }
/** * @see Fl_Token::getLastToken() */ public function getLastToken() { if ($this->validate) { $length = count($this->validateData); for ($i = 0; $i < $length; $i += 2) { if ($this->validateData[$i] != $this->validateData[$i + 1]) { $this->throwException('"' . $item[0] . '"(' . $this->validateData[$item[0]] . ') & "' . $item[1] . '"(' . $this->validateData[$item[1]] . ') count not equal'); } } } return parent::getLastToken(); }
/** * 在获取最后一个token的时候,检测{和}个数是否相等 * @see Fl_Token::getLastToken() */ public function getLastToken() { if ($this->validate && $this->bracesNum[0] != $this->bracesNum[1]) { $this->throwException('`{` & `}` count not equal. please check.', false); } return parent::getLastToken(); }
/** * get next token * @see Fl_Token::getNextToken() */ public function getNextToken() { $token = parent::getNextToken(); if ($token || $token === false) { return $token; } $char = $this->getCurrentChar(); if ($char === false) { return $this->getLastToken(); } if (!$this->_checkNamespace) { $this->_checkNamespace = true; if (Fl_Css_Static::checkNamespace($this->text)) { $result = $this->readWhile('getNamespaceToken'); return $this->getTokenInfo(FL_TOKEN_CSS_SELECTOR_NAMESPACE, $result); } } $type = ''; $value = ''; switch ($char) { case '*': $type = FL_TOKEN_CSS_SELECTOR_UNIVERSAL; $this->getNextChar(); $value = $char; break; case ',': $type = FL_TOKEN_CSS_SELECTOR_COMMA; $this->getNextChar(); $value = $char; break; case '>': case '+': case '~': $this->getNextChar(); $value = $char; $type = FL_TOKEN_CSS_SELECTOR_COMBINATOR; break; case '#': $type = FL_TOKEN_CSS_SELECTOR_ID; $value = $this->readWhile('getIdToken'); break; case '.': $type = FL_TOKEN_CSS_SELECTOR_CLASS; $value = $this->readWhile('getClassToken'); break; case '[': $type = FL_TOKEN_CSS_SELECTOR_ATTRIBUTES; $value = $this->getAttributeToken($char); break; case ':': if ($this->getPosChar($this->pos + 1) === ':') { $this->getNextChar(); $value = ':' . $this->readWhile('getPseudoElementToken'); $type = FL_TOKEN_CSS_SELECTOR_PSEUDO_ELEMENT; } else { $value = $this->getPseudoClassToken($char); $type = FL_TOKEN_CSS_SELECTOR_PSEUDO_CLASS; } break; default: $value = $this->readWhile('getTypeToken'); $type = FL_TOKEN_CSS_SELECTOR_TYPE; } if ($this->check && !Fl_Css_Static::checkSelectorToken($type, $value)) { $this->throwException($value . ' is not valid'); } return $this->getTokenInfo($type, $value); }
/** * * 获取模版语法的Token * @param object $instance */ public function getToken(Fl_Token &$instance) { return $instance->getMatched($instance->ld, $instance->rd, true); }
/** * 在获取最后一个token的时候,检测{和}个数是否相等 * @see Fl_Token::getLastToken() */ public function getLastToken() { if ($this->bracesNum[0] != $this->bracesNum[1]) { $this->throwException('{ & } num not equal'); } return parent::getLastToken(); }
/** * get next token * @see Fl_Token::getNextToken() */ public function getNextToken() { //左右定界符可能包含html注释 $this->skipWhiteSpace(); $this->startToken(); $tplToken = $this->getTplToken(); if ($tplToken !== false) { return $this->getTokenInfo(FL_TOKEN_TPL, $tplToken); } $token = parent::getNextToken(); if ($token || $token === false) { return $token; } $char = $this->text[$this->pos]; //现在特殊token的配置第一个字符都是<,所有可以优先判断<进行提速 if ($char === Fl_Html_Static::LEFT) { $token = $this->getSpecialToken(); if ($token) { return $token; } } $next = $this->text[$this->pos + 1]; //当前字符为<,且下个字符不为<,且下个字符是个合法的tag首字符 if ($char === Fl_Html_Static::LEFT && $next !== Fl_Html_Static::RIGHT && Fl_Html_Static::isTagFirstChar($next)) { $token = $this->readWhile('getTagToken'); if ($this->validate) { $lastChar = $token[strlen($token) - 1]; //检测tag最有一个字符是否是> if ($lastChar !== Fl_Html_Static::RIGHT) { $this->throwException('uncaught tag token ' . $token); } } $type = FL_TOKEN_HTML_TAG_START; if (strpos($token, '</') === 0) { $type = FL_TOKEN_HTML_TAG_END; } elseif (!$this->isXML && strpos($token, Fl_Html_Static::XML_PREFIX) === 0) { $this->isXML = true; $type = FL_TOKEN_XML_HEAD; array_push(Fl_Html_Static::$specialTokens, array(Fl_Html_Static::CDATA_PREFIX, Fl_Html_Static::CDATA_SUFFIX, FL_TOKEN_XML_CDATA)); } return $this->getTokenInfo($type, $token); } $token = $this->readWhile('getTextToken'); if (isset($token)) { //check tag name if ($this->validate && ($token === '<' || $token[strlen($token) - 1] === '<')) { if ($this->hasTplToken && $this->ld === substr($this->text, $this->pos, strlen($this->ld))) { $text = substr($this->text, $this->pos); $pattern = "/" . preg_quote($this->ld, "/") . ".*?" . preg_quote($this->rd, "/") . "/e"; $text = preg_replace($pattern, "", $text); $pos = strpos($text, ">"); if ($this->validate && $pos !== false && strpos(substr($text, 0, $pos), "<") === false) { $this->throwException("tag name can't have tpl."); } } } $this->newlineBefore -= count(explode(FL_NEWLINE, $token)) - 1; return $this->getTokenInfo(FL_TOKEN_HTML_TEXT, $token); } $this->throwException('uncaught char ' . $char); }
/** * 获取最后一个节点(non-PHPdoc) * @see Fl_Token::getLastToken() */ public function getLastToken() { if ($this->validate) { $data = array(array('(', ')'), array('{', '}'), array('[', ']')); foreach ($data as $item) { if ($this->validateData[$item[0]] != $this->validateData[$item[1]]) { $this->throwException('"' . $item[0] . '"(' . $this->validateData[$item[0]] . ') & "' . $item[1] . '"(' . $this->validateData[$item[1]] . ') count not equal'); } } } return parent::getLastToken(); }