Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_language_definitions.php 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /* Copyright (c)
  3. * - 2013-2019 Geert Bergman (geert@scrivo.nl), highlight.php
  4. * - 2014 Daniel Lynge, highlight.php (contributor)
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * 3. Neither the name of "highlight.js", "highlight.php", nor the names of its
  15. * contributors may be used to endorse or promote products derived from this
  16. * software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * Extract language definitions (JSON strings) from the large file that was
  32. * created using 'get_language_definitions.php' and create a JSON file for
  33. * each language.
  34. */
  35. $f = file("languages.dat");
  36. $patches = array(
  37. // The expression \\/: causes issues for PREG due to the / and the : having special meaning, therefore we use \Q and
  38. // \E to have PREG treat them as literal characters
  39. "1c" => array(
  40. array("\\\\\\\\/:", "\\\\Q\\\\/:\\\\E")
  41. ),
  42. // The expression []{}%#'" should be treated as a list of invalid characters, however the [] is special in PREG so
  43. // we use \Q and \E to have PREG treat them as literal characters
  44. "ada" => array(
  45. array("[]{}%#'\\\"", "\\\\Q[]{}%#'\\\"\\\\E")
  46. ),
  47. // The `-` character must be escaped in while in `[]`. This is enforced in PHP 7.3+
  48. // https://wiki.php.net/rfc/pcre2-migration
  49. // https://github.com/php/php-src/pull/2857
  50. "dsconfig" => array(
  51. array("[\\\\w-?]", "[\\\\w\\\\-?]")
  52. ),
  53. // WTF, any ideas anyone?
  54. "mercury" => array(array("\\\\\\\/", "\\\\\\\\\\\/")),
  55. // The expression [^] is not allowed in PREG
  56. "lisp" => array(array("[^]", "[^|]")),
  57. // Same reason as dsconfig
  58. "xquery" => array(
  59. array("[\\\\w-:]+","[\\\\w\\\\-:]+")
  60. ),
  61. );
  62. for ($i=0; $i<count($f); $i+=2) {
  63. if (isset($f[$i+1])) {
  64. $fl = trim($f[$i]);
  65. $json = $f[$i+1];
  66. if (!$fl) {
  67. die(sprintf("ERROR: No language name on line %d\n", ($i+1)));
  68. }
  69. if (!@json_decode($json)) {
  70. die(sprintf("ERROR: Invalid JSON data on line %d\n", ($i+2)));
  71. }
  72. if (isset($patches[$fl])) {
  73. foreach ($patches[$fl] as $patch) {
  74. $json = str_replace($patch[0], $patch[1], $json);
  75. echo "{$patch[0]}, {$patch[1]}\n{$json}";
  76. }
  77. }
  78. echo "Creating language file '{$fl}.json'\n";
  79. if (!file_put_contents("../Highlight/languages/{$fl}.json", $json)) {
  80. die("ERROR: Couldn't write to file.\n");
  81. }
  82. }
  83. }