DE
games/alis / tools / lang / basic.php · commit 9c722cf
<?php// ALIS BASIC (docs/language.md, App\Alis\Lang\Basic): converts the sources of a folder and checks the// round trip (canonical -> BASIC -> canonical gives back the same text, so the same bytes).//   bin/jumphp php games/alis tools/lang/basic.php <src folder> [out folder]require __DIR__ . '/../../vendor/autoload.php';use App\Alis\Lang\Basic;$src = rtrim($argv[1] ?? '', '/');$out = isset($argv[2]) ? rtrim($argv[2], '/') : null;if ($src === '' || !is_dir($src)) {    fwrite(STDERR, "usage: tools/lang/basic.php <src folder> [out folder]\n");    exit(1);}if ($out !== null) {    @mkdir($out, 0777, true);}$bad = 0;$n = 0;foreach (glob("$src/*.als") as $file) {    $canon = (string) file_get_contents($file);    $human = Basic::toBasic($canon);    $back = Basic::toCanonical($human);    $n++;    if ($back !== $canon || !Basic::isBasic($human) || Basic::isBasic($canon)) {        $bad++;        $a = explode("\n", $canon);        $b = explode("\n", $back);        foreach ($a as $k => $l) {            if (($b[$k] ?? null) !== $l) {                printf("%s line %d:\n  %s\n  %s\n  (BASIC: %s)\n", basename($file), $k + 1, $l, $b[$k] ?? '(none)', explode("\n", $human)[$k] ?? '');                break;            }        }    }    if ($out !== null) {        file_put_contents("$out/" . basename($file), $human);    }}printf("%d scripts, %d round trips differ\n", $n, $bad);exit($bad ? 2 : 0);