diff --git a/tools/get_language_definitions.php b/tools/get_language_definitions.php index bd5bb97f..a4be913d 100644 --- a/tools/get_language_definitions.php +++ b/tools/get_language_definitions.php @@ -31,8 +31,7 @@ /** * Extract language definitions (JSON strings) from the large file that was - * created using 'get_language_definitions.php' and create a JSON file for - * each language. + * created using 'node launcher.js' and create a JSON file for each language. */ $f = file("languages.dat"); @@ -41,13 +40,13 @@ // The expression \\/: causes issues for PREG due to the / and the : having special meaning, therefore we use \Q and // \E to have PREG treat them as literal characters "1c" => array( - array("\\\\\\\\/:", "\\\\Q\\\\/:\\\\E") + array("\\\\\\\\/:", "\\\\Q\\\\/:\\\\E"), ), // The expression []{}%#'" should be treated as a list of invalid characters, however the [] is special in PREG so // we use \Q and \E to have PREG treat them as literal characters "ada" => array( - array("[]{}%#'\\\"", "\\\\Q[]{}%#'\\\"\\\\E") + array("[]{}%#'\\\"", "\\\\Q[]{}%#'\\\"\\\\E"), ), // WTF, any ideas anyone? @@ -63,33 +62,39 @@ )), ); -for ($i=0; $i $patch) { + $patched = str_replace($patch[0], $patch[1], $jsonLangDef); - if (isset($patches[$fl])) { - foreach ($patches[$fl] as $patch) { - $json = str_replace($patch[0], $patch[1], $json); - echo "{$patch[0]}, {$patch[1]}\n{$json}"; + if ($jsonLangDef === $patched) { + printf("Patch %d for %s was not applied and likely unnecessary\n", $j, $languageName); } - } - echo "Creating language file '{$fl}.json'\n"; - if (!file_put_contents("../Highlight/languages/{$fl}.json", $json)) { - die("ERROR: Couldn't write to file.\n"); + $jsonLangDef = $patched; } } + + if (!file_put_contents("../Highlight/languages/{$languageName}.json", $jsonLangDef)) { + die("ERROR: Couldn't write to file.\n"); + } }