docs(cli): update comments to English for CLI tools

- Translate Chinese comments to English in dump-ast.php
- Update comment headers from Chinese to English in extractor.php
- Replace Chinese documentation comments with English equivalents
- Maintain all functionality while improving internationalization
- Standardize commenting style across CLI utility files
master
韩天峰 5 days ago
parent 287a1f5d84
commit 1c300bf35a
  1. 6
      bin/dump-ast.php
  2. 22
      bin/extractor.php

@ -126,10 +126,10 @@ function valueToArray(mixed $value): mixed
return $value; return $value;
} }
// ─── 美化打印 ───────────────────────────────────────────── // ─── Pretty printing ──────────────────────────────────────
/** /**
* 用缩进打印 AST 结构,类似 json 的视觉风格 * Print the AST structure with indentation, similar to JSON's visual style.
*/ */
function printAst(array $nodes, string $indent = ''): void function printAst(array $nodes, string $indent = ''): void
{ {
@ -221,7 +221,7 @@ echo "━━━━━━━━━━━━━━━━━━━━━━━━
echo "AST_ROOT: Program (L1-" . count($stmts) . " statements)\n\n"; echo "AST_ROOT: Program (L1-" . count($stmts) . " statements)\n\n";
/** /**
* 简洁的分层输出 * Concise hierarchical output.
*/ */
function dumpNode(NodeAbstract $node, int $depth = 0): void function dumpNode(NodeAbstract $node, int $depth = 0): void
{ {

@ -1,7 +1,7 @@
<?php <?php
require __DIR__ . '/bootstrap.php'; require __DIR__ . '/bootstrap.php';
// ============================================================================ // ============================================================================
// 命令行接口 // Command-line interface
// ============================================================================ // ============================================================================
function showUsage(): void function showUsage(): void
@ -50,7 +50,7 @@ USAGE;
function extractorMain(array $argv): void function extractorMain(array $argv): void
{ {
// 解析命令行参数 // Parse command-line arguments
$options = [ $options = [
'help' => false, 'help' => false,
'pretty' => false, 'pretty' => false,
@ -73,16 +73,16 @@ function extractorMain(array $argv): void
} }
} }
// 显示帮助 // Show help
if ($options['help'] || (empty($args) && !$options['batch'])) { if ($options['help'] || (empty($args) && !$options['batch'])) {
showUsage(); showUsage();
exit(0); exit(0);
} }
// 创建提取器 // Create the extractor
$extractor = new TypePhp\Extractor(); $extractor = new TypePhp\Extractor();
// 批量模式 // Batch mode
if ($options['batch']) { if ($options['batch']) {
$prefixes = !empty($args[0]) ? explode(',', $args[0]) : ['php_']; $prefixes = !empty($args[0]) ? explode(',', $args[0]) : ['php_'];
$files = []; $files = [];
@ -101,7 +101,7 @@ function extractorMain(array $argv): void
$functions = $extractor->extractFromFiles($files, $prefixes); $functions = $extractor->extractFromFiles($files, $prefixes);
// 输出结果 // Output the result
$jsonFlags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; $jsonFlags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
if ($options['pretty']) { if ($options['pretty']) {
$jsonFlags |= JSON_PRETTY_PRINT; $jsonFlags |= JSON_PRETTY_PRINT;
@ -111,7 +111,7 @@ function extractorMain(array $argv): void
exit(0); exit(0);
} }
// 单文件模式 // Single-file mode
$filename = $args[0] ?? null; $filename = $args[0] ?? null;
$prefixesStr = $args[1] ?? 'php_'; $prefixesStr = $args[1] ?? 'php_';
$output = $args[2] ?? null; $output = $args[2] ?? null;
@ -122,14 +122,14 @@ function extractorMain(array $argv): void
exit(1); exit(1);
} }
// 解析前缀 // Parse prefixes
$prefixes = array_map('trim', explode(',', $prefixesStr)); $prefixes = array_map('trim', explode(',', $prefixesStr));
try { try {
// 提取函数 // Extract functions
$functions = $extractor->extractFunctions($filename, $prefixes); $functions = $extractor->extractFunctions($filename, $prefixes);
// 准备 JSON 输出 // Prepare JSON output
$jsonFlags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; $jsonFlags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
if ($options['pretty']) { if ($options['pretty']) {
$jsonFlags |= JSON_PRETTY_PRINT; $jsonFlags |= JSON_PRETTY_PRINT;
@ -137,7 +137,7 @@ function extractorMain(array $argv): void
$json = json_encode($functions, $jsonFlags); $json = json_encode($functions, $jsonFlags);
// 输出 // Output
if ($output) { if ($output) {
file_put_contents($output, $json . "\n"); file_put_contents($output, $json . "\n");
fprintf(STDERR, "\033[0;32m已保存到: %s\033[0m\n", $output); fprintf(STDERR, "\033[0;32m已保存到: %s\033[0m\n", $output);

Loading…
Cancel
Save