public function __construct(Token $aToken) { if (!array_key_exists($aToken->tokenType(), self::$arrClosureObjectBeginTypes) and !array_key_exists($aToken->tokenType(), self::$arrClosureObjectEndTypes)) { throw new ClassCompileException(null, $aToken, "参数 \$aToken 传入的不是一个有效的闭合token(%s:%s)。该参数只接受以下类型的token:" . implode(', ', self::closureSymbols()), array($aToken->tokenTypeName(), $aToken->sourceCode())); } $this->cloneOf($aToken); }
public function cloneOf(self $aOther) { $this->nType = $aOther->nType; $this->setSourceCode($aOther->sourceCode()); $this->setTargetCode($aOther->targetCode()); $this->setPosition($aOther->position()); $this->setBelongsClass($aOther->belongsClass()); $this->setBelongsFunction($aOther->belongsFunction()); $this->setBelongsNamespace($aOther->belongsNamespace()); $this->setLine($aOther->line()); $this->sType = $this->tokenTypeName(); }
public function generateTargetCode(TokenPool $aTokenPool, Token $aObject) { switch( $aObject->tokenType() ) { case T_OBJECT_OPERATOR : // -> to . $aObject->setTargetCode('.') ; break ; case Token::T_CONCAT : // . to + $aObject->setTargetCode('+') ; break ; case T_CONCAT_EQUAL : // .= to += $aObject->setTargetCode('+=') ; break ; case T_VARIABLE : // 变量名前的 $ $aObject->setTargetCode( str_replace('$','',$aObject->sourceCode()) ) ; break ; case T_OPEN_TAG : // < ?php $aObject->setTargetCode( '' ) ; break ; case T_OPEN_TAG_WITH_ECHO : // < ?= $aObject->setTargetCode( 'echo ' ) ; break ; case T_CLOSE_TAG : // ? > $aObject->setTargetCode( '' ) ; break ; // 字符串压缩到一行 case T_CONSTANT_ENCAPSED_STRING : case T_ENCAPSED_AND_WHITESPACE: $sTarget = str_replace("\r","\\r", $aObject->targetCode()) ; $sTarget = str_replace("\n","\\n", $sTarget) ; $aObject->setTargetCode($sTarget) ; break ; // 转换 foreach (js 中没有foreach) case T_FOREACH: $this->transForeach($aTokenPool,$aObject) ; break ; case T_ENDFOREACH: // @todo break; } }
public function matchExecutionPoint(Token $aToken) { return preg_match($this->newObjectRegexp(), $aToken->sourceCode()) ? true : false; }