/PHP-Parser/grammar/ |
H A D | phpyLang.php | 23 $code = resolveNodes($code); 24 $code = resolveMacros($code); 25 $code = resolveStackAccess($code); 26 $code = str_replace('$this', '$self', $code); 28 return $code; 31 function resolveNodes($code) { argument 50 $code 129 $code 140 $code = preg_replace('/\$\d+/', '$this->semStack[$0]', $code); 141 $code = preg_replace('/#(\d+)/', '$$1', $code); [all …]
|
/PHP-Parser/lib/PhpParser/ |
H A D | Error.php | 102 * @param string $code Source code of the file 104 public function getStartColumn(string $code): int { argument 115 * @param string $code Source code of the file 117 public function getEndColumn(string $code): int { argument 132 public function getMessageWithColumnInfo(string $code): string { argument 135 $this->getStartLine(), $this->getStartColumn($code), 136 $this->getEndLine(), $this->getEndColumn($code) 143 * @param string $code Source code that $pos indexes into 148 private function toColumn(string $code, int $pos): int { argument 149 if ($pos > strlen($code)) { [all …]
|
H A D | Parser.php | 9 * @param string $code The source code to parse 16 public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array; argument
|
H A D | NodeDumper.php | 19 private ?string $code; variable in PhpParser\\NodeDumper 54 * @param string|null $code Code corresponding to dumped AST. This only needs to be passed if 60 public function dump($node, ?string $code = null): string { argument 61 $this->code = $code; 278 && null !== $this->code 280 $start .= ':' . $this->toColumn($this->code, $node->getStartFilePos()); 281 $end .= ':' . $this->toColumn($this->code, $node->getEndFilePos()); 287 private function toColumn(string $code, int $pos): int { argument 288 if ($pos > strlen($code)) { 292 $lineStartPos = strrpos($code, "\n", $pos - strlen($code));
|
/PHP-Parser/lib/PhpParser/Lexer/TokenEmulator/ |
H A D | ReverseEmulator.php | 22 public function isEmulationNeeded(string $code): bool { argument 23 return $this->emulator->isEmulationNeeded($code); 26 public function emulate(string $code, array $tokens): array { argument 27 return $this->emulator->reverseEmulate($code, $tokens); 30 public function reverseEmulate(string $code, array $tokens): array { argument 31 return $this->emulator->emulate($code, $tokens); 34 public function preprocessCode(string $code, array &$patches): string { argument 35 return $code;
|
H A D | AttributeEmulator.php | 13 public function isEmulationNeeded(string $code): bool { argument 14 return strpos($code, '#[') !== false; 17 public function emulate(string $code, array $tokens): array { argument 34 public function reverseEmulate(string $code, array $tokens): array { argument 39 public function preprocessCode(string $code, array &$patches): string { argument 41 while (false !== $pos = strpos($code, '#[', $pos)) { 43 $code[$pos] = '%'; 47 return $code;
|
H A D | TokenEmulator.php | 12 abstract public function isEmulationNeeded(string $code): bool; argument 18 abstract public function emulate(string $code, array $tokens): array; argument 24 abstract public function reverseEmulate(string $code, array $tokens): array; argument 27 public function preprocessCode(string $code, array &$patches): string { argument 28 return $code;
|
H A D | ExplicitOctalEmulator.php | 13 public function isEmulationNeeded(string $code): bool { argument 14 return strpos($code, '0o') !== false || strpos($code, '0O') !== false; 17 public function emulate(string $code, array $tokens): array { argument 41 public function reverseEmulate(string $code, array $tokens): array { argument
|
H A D | AsymmetricVisibilityTokenEmulator.php | 12 public function isEmulationNeeded(string $code): bool { argument 13 $code = strtolower($code); 14 return strpos($code, 'public(set)') !== false || 15 strpos($code, 'protected(set)') !== false || 16 strpos($code, 'private(set)') !== false; 19 public function emulate(string $code, array $tokens): array { argument 44 public function reverseEmulate(string $code, array $tokens): array { argument
|
H A D | KeywordEmulator.php | 11 public function isEmulationNeeded(string $code): bool { argument 12 return strpos(strtolower($code), $this->getKeywordString()) !== false; 25 public function emulate(string $code, array $tokens): array { argument 50 public function reverseEmulate(string $code, array $tokens): array { argument
|
H A D | NullsafeTokenEmulator.php | 13 public function isEmulationNeeded(string $code): bool { argument 14 return strpos($code, '?->') !== false; 17 public function emulate(string $code, array $tokens): array { argument 56 public function reverseEmulate(string $code, array $tokens): array { argument
|
/PHP-Parser/test/PhpParser/Lexer/ |
H A D | EmulativeTest.php | 24 $code = '<?php ' . $keyword; 29 ], $lexer->tokenize($code)); 37 $code = '<?php ' . strtoupper($keyword); 43 ], $lexer->tokenize($code)); 51 $code = '<?php ->' . $keyword; 58 ], $lexer->tokenize($code)); 66 $code = '<?php -> ' . $keyword; 74 ], $lexer->tokenize($code)); 82 $code = '<?php ?->' . $keyword; 89 ], $lexer->tokenize($code)); [all …]
|
/PHP-Parser/bin/ |
H A D | php-parse | 41 $code = file_get_contents('php://stdin'); variable 44 $code = $file; variable 45 fwrite(STDERR, "====> Code $code\n"); 52 $code = file_get_contents($file); variable 58 $stmts = $parser->parse($code, $errorHandler); 60 $message = formatErrorMessage($error, $code, $attributes['with-column-info']); 68 $stmts = $parser->parse($code); 70 $message = formatErrorMessage($error, $code, $attributes['with-column-info']); 79 echo $dumper->dump($stmts, $code), "\n"; 96 function formatErrorMessage(PhpParser\Error $e, $code, $withColumnInfo) { argument [all …]
|
/PHP-Parser/test/PhpParser/ |
H A D | CodeTestParser.php | 6 public function parseTest($code, $chunksPerTest) { argument 7 $code = canonicalize($code); 10 $code = preg_replace_callback( 15 $code 19 $parts = preg_split("/\n-----(?:\n|$)/", $code);
|
H A D | LexerTest.php | 16 public function testError($code, $messages): void { argument 23 $lexer->tokenize($code, $errorHandler); 28 $this->assertSame($messages[$i], $errors[$i]->getMessageWithColumnInfo($code)); 58 public function testLex($code, $expectedTokens): void { argument 60 $tokens = $lexer->tokenize($code); 101 $code = '<?php "a";' . "\n" . '// foo' . "\n" . '// bar' . "\n\n" . '"b";'; 117 $this->assertEquals($expectedTokens, $lexer->tokenize($code));
|
H A D | CodeParsingTest.php | 12 public function testParse($name, $code, $expected, $modeLine): void { argument 15 list($stmts, $output) = $this->getParseOutput($parser, $code, $modes); 29 public function getParseOutput(Parser $parser, $code, array $modes) { argument 34 $stmts = $parser->parse($code, $errors); 38 $output .= $this->formatErrorMessage($error, $code) . "\n"; 47 $output .= $dumper->dump($stmts, $code); 57 private function formatErrorMessage(Error $e, $code) { argument 59 return $e->getMessageWithColumnInfo($code);
|
H A D | PrettyPrinterTest.php | 33 $output = canonicalize($prettyPrinter->$method($parser->parse($code))); 40 public function testPrettyPrint($name, $code, $expected, $mode): void { argument 47 public function testPrettyPrintFile($name, $code, $expected, $mode): void { argument 195 $oldStmts = $parser->parse($code); 234 $oldStmts = $parser->parse($code); 268 $code = $prettyPrinter->prettyPrint($stmts); 270 $code = $prettyPrinter->prettyPrintFile($stmts); 274 $code = $prettyPrinter->prettyPrintFile($stmts); 275 $this->assertSame("Hello world", $code); 291 $code = $prettyPrinter->prettyPrint($stmts); [all …]
|
H A D | NodeDumperTest.php | 64 $code = "<?php\n\$a = 1;\necho \$a;"; 87 $stmts = $parser->parse($code); 88 $dump = $dumper->dump($stmts, $code);
|
H A D | JsonDecoderTest.php | 7 $code = <<<'PHP' 17 $stmts = $parser->parse($code);
|
/PHP-Parser/test_old/ |
H A D | run.php | 86 $codeExtractor = function($file, $code) { argument 87 return $code; 94 $codeExtractor = function($file, $code) { argument 128 if (!preg_match('~--FILE--\s*(.*?)\n--[A-Z]+--~s', $code, $matches)) { 131 if (preg_match('~--EXPECT(?:F|REGEX)?--\s*(?:Parse|Fatal) error~', $code)) { 194 if ($code !== $origCode) { 197 echo "FPPP output:\n=====\n$code\n=====\n\n"; 204 $code = "<?php\n" . $prettyPrinter->prettyPrint($stmts); variable 209 $ppStmts = $parser->parse($code); 219 echo "Pretty printer output:\n=====\n$code\n=====\n\n"; [all …]
|
/PHP-Parser/test/ |
H A D | updateTests.php | 13 foreach (filesInDir($dir, 'test') as $fileName => $code) { 14 if (false !== strpos($code, '@@{')) { 19 list($name, $tests) = $testParser->parseTest($code, 2);
|
/PHP-Parser/doc/component/ |
H A D | Pretty_printing.markdown | 4 Pretty printing is the process of converting a syntax tree back to PHP code. In its basic mode of 6 code style and will discard (nearly) all formatting of the original code. Because programmers tend 7 to be rather picky about their code formatting, this mode of operation is not very suitable for 8 refactoring code, but can be used for automatically generated code, which is usually only read for 15 $stmts = $parser->parse($code); 27 `prettyPrint()` also takes a statement array, but produces code which is valid inside an already 63 default pretty printer with an existing library for code reformatting, such as 71 this, because it will also reformat parts of the code which have not been modified. 75 code which has been modified or newly inserted. 83 $oldStmts = $parser->parse($code); [all …]
|
/PHP-Parser/lib/PhpParser/Lexer/ |
H A D | Emulative.php | 64 public function tokenize(string $code, ?ErrorHandler $errorHandler = null): array { argument 65 $emulators = array_filter($this->emulators, function ($emulator) use ($code) { 66 return $emulator->isEmulationNeeded($code); 71 return parent::tokenize($code, $errorHandler); 80 $code = $emulator->preprocessCode($code, $this->patches); 84 $tokens = parent::tokenize($code, $collector); 97 $tokens = $emulator->emulate($code, $tokens);
|
/PHP-Parser/ |
H A D | README.md | 18 * Parsing PHP 7, and PHP 8 code into an abstract syntax tree (AST). 19 * Invalid code can be parsed into a partial AST. 22 * Converting an AST back to PHP code. 27 * Builders to simplify AST construction for code generation. 37 Parse some PHP code into an AST and dump the result in human-readable form: 45 $code = <<<'CODE' 56 $ast = $parser->parse($code); 168 Finally, we can convert the new AST back to PHP code: 208 * Converting AST back to PHP code 210 * Formatting-preserving code transformations [all …]
|
/PHP-Parser/tools/fuzzing/ |
H A D | generateCorpus.php | 23 foreach (PhpParser\filesInDir($inputDir, 'test') as $fileName => $code) { 24 list($_name, $tests) = $testParser->parseTest($code, 2);
|