Skip to content

Commit 970cb40

Browse files
committed
Extract logic
1 parent c6a0e57 commit 970cb40

3 files changed

Lines changed: 674 additions & 620 deletions

File tree

tools/FileRefExtractor/BuildMode/Ast.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,16 @@ public function __construct(
4747
) {
4848
}
4949

50-
private static function crc(string $schema): string
50+
public static function crc(string $schema): string
5151
{
5252
$clean = preg_replace(['/:bytes /', '/;/', '/#[a-f0-9]+ /', '/ [a-zA-Z0-9_]+\\:flags\\.[0-9]+\\?true/', '/[<]/', '/[>]/', '/ /', '/^ /', '/ $/', '/\\?bytes /', '/{/', '/}/'], [':string ', '', ' ', '', ' ', ' ', ' ', '', '', '?string ', '', ''], $schema);
5353
$id = hash('crc32b', $clean);
5454
$id = str_pad($id, 8, '0', STR_PAD_LEFT);
5555
return $id;
5656
}
5757

58-
public function finalize(string $schemaFile, string $refMapFile, string $dbSchemaFile): void
58+
public function finalize(string $refMapFile, string $dbSchemaFile): void
5959
{
60-
$schema = explode("\n", file_get_contents($schemaFile));
61-
foreach ($schema as &$line) {
62-
$line = rtrim(trim($line), ';');
63-
if (str_starts_with($line, '//') || !$line) {
64-
continue;
65-
}
66-
$line = explode(" ", $line, 2);
67-
$line[0] = preg_replace('/#.*/', '', $line[0]);
68-
$line = implode(" ", $line);
69-
$id = self::crc($line);
70-
71-
$line = explode(" ", $line, 2);
72-
$line[0] .= "#$id";
73-
$line = implode(" ", $line);
74-
$line .= ';';
75-
}
76-
$schema = implode("\n", $schema);
77-
file_put_contents($schemaFile, $schema);
78-
7960
$dbSchema = '';
8061
foreach ($this->outputSchema as $constructor => $params) {
8162
$dbSchema .= self::stringifySchema($constructor, $params)."\n";

0 commit comments

Comments
 (0)