Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 5fb285c0d0e3 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
7 use PhpParser\Internal\TokenStream; | 7 use PhpParser\Internal\TokenStream; |
8 use PhpParser\Node\Expr; | 8 use PhpParser\Node\Expr; |
9 use PhpParser\Node\Expr\AssignOp; | 9 use PhpParser\Node\Expr\AssignOp; |
10 use PhpParser\Node\Expr\BinaryOp; | 10 use PhpParser\Node\Expr\BinaryOp; |
11 use PhpParser\Node\Expr\Cast; | 11 use PhpParser\Node\Expr\Cast; |
12 use PhpParser\Node\Name; | |
13 use PhpParser\Node\Scalar; | 12 use PhpParser\Node\Scalar; |
14 use PhpParser\Node\Stmt; | 13 use PhpParser\Node\Stmt; |
15 | 14 |
16 abstract class PrettyPrinterAbstract | 15 abstract class PrettyPrinterAbstract |
17 { | 16 { |
81 AssignOp\BitwiseOr::class => [160, 1], | 80 AssignOp\BitwiseOr::class => [160, 1], |
82 AssignOp\BitwiseXor::class => [160, 1], | 81 AssignOp\BitwiseXor::class => [160, 1], |
83 AssignOp\ShiftLeft::class => [160, 1], | 82 AssignOp\ShiftLeft::class => [160, 1], |
84 AssignOp\ShiftRight::class => [160, 1], | 83 AssignOp\ShiftRight::class => [160, 1], |
85 AssignOp\Pow::class => [160, 1], | 84 AssignOp\Pow::class => [160, 1], |
85 AssignOp\Coalesce::class => [160, 1], | |
86 Expr\YieldFrom::class => [165, 1], | 86 Expr\YieldFrom::class => [165, 1], |
87 Expr\Print_::class => [168, 1], | 87 Expr\Print_::class => [168, 1], |
88 BinaryOp\LogicalAnd::class => [170, -1], | 88 BinaryOp\LogicalAnd::class => [170, -1], |
89 BinaryOp\LogicalXor::class => [180, -1], | 89 BinaryOp\LogicalXor::class => [180, -1], |
90 BinaryOp\LogicalOr::class => [190, -1], | 90 BinaryOp\LogicalOr::class => [190, -1], |
615 $key = $type . '->' . $subNodeName; | 615 $key = $type . '->' . $subNodeName; |
616 if (!isset($this->insertionMap[$key])) { | 616 if (!isset($this->insertionMap[$key])) { |
617 return $this->pFallback($fallbackNode); | 617 return $this->pFallback($fallbackNode); |
618 } | 618 } |
619 | 619 |
620 list($findToken, $extraLeft, $extraRight) = $this->insertionMap[$key]; | 620 list($findToken, $beforeToken, $extraLeft, $extraRight) = $this->insertionMap[$key]; |
621 if (null !== $findToken) { | 621 if (null !== $findToken) { |
622 $subStartPos = $this->origTokens->findRight($pos, $findToken) + 1; | 622 $subStartPos = $this->origTokens->findRight($pos, $findToken) |
623 + (int) !$beforeToken; | |
623 } else { | 624 } else { |
624 $subStartPos = $pos; | 625 $subStartPos = $pos; |
625 } | 626 } |
627 | |
626 if (null === $extraLeft && null !== $extraRight) { | 628 if (null === $extraLeft && null !== $extraRight) { |
627 // If inserting on the right only, skipping whitespace looks better | 629 // If inserting on the right only, skipping whitespace looks better |
628 $subStartPos = $this->origTokens->skipRightWhitespace($subStartPos); | 630 $subStartPos = $this->origTokens->skipRightWhitespace($subStartPos); |
629 } | 631 } |
630 $subEndPos = $subStartPos - 1; | 632 $subEndPos = $subStartPos - 1; |
949 * | 951 * |
950 * @param string $str | 952 * @param string $str |
951 * @param string $append | 953 * @param string $append |
952 */ | 954 */ |
953 protected function safeAppend(string &$str, string $append) { | 955 protected function safeAppend(string &$str, string $append) { |
954 // $append must not be empty in this function | |
955 if ($str === "") { | 956 if ($str === "") { |
956 $str = $append; | 957 $str = $append; |
958 return; | |
959 } | |
960 | |
961 if ($append === "") { | |
957 return; | 962 return; |
958 } | 963 } |
959 | 964 |
960 if (!$this->labelCharMap[$append[0]] | 965 if (!$this->labelCharMap[$append[0]] |
961 || !$this->labelCharMap[$str[\strlen($str) - 1]]) { | 966 || !$this->labelCharMap[$str[\strlen($str) - 1]]) { |
1150 | 1155 |
1151 $assignOps = [ | 1156 $assignOps = [ |
1152 Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class, | 1157 Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class, |
1153 AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class, | 1158 AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class, |
1154 AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class, | 1159 AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class, |
1155 AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, | 1160 AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class |
1156 ]; | 1161 ]; |
1157 foreach ($assignOps as $assignOp) { | 1162 foreach ($assignOps as $assignOp) { |
1158 $this->fixupMap[$assignOp] = [ | 1163 $this->fixupMap[$assignOp] = [ |
1159 'var' => self::FIXUP_PREC_LEFT, | 1164 'var' => self::FIXUP_PREC_LEFT, |
1160 'expr' => self::FIXUP_PREC_RIGHT, | 1165 'expr' => self::FIXUP_PREC_RIGHT, |
1204 'Stmt_Continue->num' => $stripBoth, | 1209 'Stmt_Continue->num' => $stripBoth, |
1205 'Stmt_Foreach->keyVar' => $stripDoubleArrow, | 1210 'Stmt_Foreach->keyVar' => $stripDoubleArrow, |
1206 'Stmt_Function->returnType' => $stripColon, | 1211 'Stmt_Function->returnType' => $stripColon, |
1207 'Stmt_If->else' => $stripLeft, | 1212 'Stmt_If->else' => $stripLeft, |
1208 'Stmt_Namespace->name' => $stripLeft, | 1213 'Stmt_Namespace->name' => $stripLeft, |
1214 'Stmt_Property->type' => $stripRight, | |
1209 'Stmt_PropertyProperty->default' => $stripEquals, | 1215 'Stmt_PropertyProperty->default' => $stripEquals, |
1210 'Stmt_Return->expr' => $stripBoth, | 1216 'Stmt_Return->expr' => $stripBoth, |
1211 'Stmt_StaticVar->default' => $stripEquals, | 1217 'Stmt_StaticVar->default' => $stripEquals, |
1212 'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft, | 1218 'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft, |
1213 'Stmt_TryCatch->finally' => $stripLeft, | 1219 'Stmt_TryCatch->finally' => $stripLeft, |
1221 protected function initializeInsertionMap() { | 1227 protected function initializeInsertionMap() { |
1222 if ($this->insertionMap) return; | 1228 if ($this->insertionMap) return; |
1223 | 1229 |
1224 // TODO: "yield" where both key and value are inserted doesn't work | 1230 // TODO: "yield" where both key and value are inserted doesn't work |
1225 $this->insertionMap = [ | 1231 $this->insertionMap = [ |
1226 'Expr_ArrayDimFetch->dim' => ['[', null, null], | 1232 'Expr_ArrayDimFetch->dim' => ['[', false, null, null], |
1227 'Expr_ArrayItem->key' => [null, null, ' => '], | 1233 'Expr_ArrayItem->key' => [null, false, null, ' => '], |
1228 'Expr_Closure->returnType' => [')', ' : ', null], | 1234 'Expr_Closure->returnType' => [')', false, ' : ', null], |
1229 'Expr_Ternary->if' => ['?', ' ', ' '], | 1235 'Expr_Ternary->if' => ['?', false, ' ', ' '], |
1230 'Expr_Yield->key' => [\T_YIELD, null, ' => '], | 1236 'Expr_Yield->key' => [\T_YIELD, false, null, ' => '], |
1231 'Expr_Yield->value' => [\T_YIELD, ' ', null], | 1237 'Expr_Yield->value' => [\T_YIELD, false, ' ', null], |
1232 'Param->type' => [null, null, ' '], | 1238 'Param->type' => [null, false, null, ' '], |
1233 'Param->default' => [null, ' = ', null], | 1239 'Param->default' => [null, false, ' = ', null], |
1234 'Stmt_Break->num' => [\T_BREAK, ' ', null], | 1240 'Stmt_Break->num' => [\T_BREAK, false, ' ', null], |
1235 'Stmt_ClassMethod->returnType' => [')', ' : ', null], | 1241 'Stmt_ClassMethod->returnType' => [')', false, ' : ', null], |
1236 'Stmt_Class->extends' => [null, ' extends ', null], | 1242 'Stmt_Class->extends' => [null, false, ' extends ', null], |
1237 'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null], | 1243 'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null], |
1238 'Stmt_Continue->num' => [\T_CONTINUE, ' ', null], | 1244 'Stmt_Continue->num' => [\T_CONTINUE, false, ' ', null], |
1239 'Stmt_Foreach->keyVar' => [\T_AS, null, ' => '], | 1245 'Stmt_Foreach->keyVar' => [\T_AS, false, null, ' => '], |
1240 'Stmt_Function->returnType' => [')', ' : ', null], | 1246 'Stmt_Function->returnType' => [')', false, ' : ', null], |
1241 'Stmt_If->else' => [null, ' ', null], | 1247 'Stmt_If->else' => [null, false, ' ', null], |
1242 'Stmt_Namespace->name' => [\T_NAMESPACE, ' ', null], | 1248 'Stmt_Namespace->name' => [\T_NAMESPACE, false, ' ', null], |
1243 'Stmt_PropertyProperty->default' => [null, ' = ', null], | 1249 'Stmt_Property->type' => [\T_VARIABLE, true, null, ' '], |
1244 'Stmt_Return->expr' => [\T_RETURN, ' ', null], | 1250 'Stmt_PropertyProperty->default' => [null, false, ' = ', null], |
1245 'Stmt_StaticVar->default' => [null, ' = ', null], | 1251 'Stmt_Return->expr' => [\T_RETURN, false, ' ', null], |
1246 //'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, ' ', null], // TODO | 1252 'Stmt_StaticVar->default' => [null, false, ' = ', null], |
1247 'Stmt_TryCatch->finally' => [null, ' ', null], | 1253 //'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, false, ' ', null], // TODO |
1254 'Stmt_TryCatch->finally' => [null, false, ' ', null], | |
1248 | 1255 |
1249 // 'Expr_Exit->expr': Complicated due to optional () | 1256 // 'Expr_Exit->expr': Complicated due to optional () |
1250 // 'Stmt_Case->cond': Conversion from default to case | 1257 // 'Stmt_Case->cond': Conversion from default to case |
1251 // 'Stmt_Class->name': Unclear | 1258 // 'Stmt_Class->name': Unclear |
1252 // 'Stmt_Declare->stmts': Not a proper node | 1259 // 'Stmt_Declare->stmts': Not a proper node |