| 1 |
<?php |
| 2 |
|
| 3 |
require_once __DIR__ . '/../../../maintenance/Maintenance.php'; |
| 4 |
|
| 5 |
class UpdateTexutil extends Maintenance { |
| 6 |
|
| 7 |
private const LEGACY_CONCEPTS = [ |
| 8 |
'!' => [ "1, 0, TEXCLASS.CLOSE, null" ], |
| 9 |
'!=' => [ " exports.MO.BIN4" ], |
| 10 |
'#' => [ " exports.MO.ORD" ], |
| 11 |
'$' => [ " exports.MO.ORD" ], |
| 12 |
'%' => [ " [3, 3, MmlNode_js_1.TEXCLASS.ORD], null]" ], |
| 13 |
'&&' => [ " exports.MO.BIN4" ], |
| 14 |
'' => [ " exports.MO.ORD" ], |
| 15 |
'*' => [ " exports.MO.BIN3" ], |
| 16 |
'**' => [ " OPDEF(1\"], 1)" ], |
| 17 |
'*=' => [ " exports.MO.BIN4" ], |
| 18 |
'+' => [ " exports.MO.BIN4" ], |
| 19 |
'+=' => [ " exports.MO.BIN4" ], |
| 20 |
',' => [ " [0, 3], MmlNode_js_1.TEXCLASS.PUNCT\"]," . |
| 21 |
"{ linebreakstyle=> [\" 'after'\"], separator=> [\" true }]", true ], |
| 22 |
'-' => [ " exports.MO.BIN4" ], |
| 23 |
'-=' => [ " exports.MO.BIN4" ], |
| 24 |
'->' => [ " exports.MO.BIN5" ], |
| 25 |
'.' => [ " [0, 3], MmlNode_js_1.TEXCLASS.PUNCT\"], { separator=> [ true }]" ], |
| 26 |
':' => [ " [1, 2], MmlNode_js_1.TEXCLASS.REL\"], null]" ], |
| 27 |
'/' => [ " exports.MO.ORD11", true ], |
| 28 |
'//' => [ " OPDEF(1\"], 1)" ], |
| 29 |
'/=' => [ " exports.MO.BIN4" ], |
| 30 |
'=>' => [ " [1, 2], MmlNode_js_1.TEXCLASS.REL\"], null]" ], |
| 31 |
'=>=' => [ " exports.MO.BIN4" ], |
| 32 |
';' => [ " [0, 3], MmlNode_js_1.TEXCLASS.PUNCT]," . |
| 33 |
"{ linebreakstyle=> ['after'], separator=> [ true }]", true ], |
| 34 |
'<' => [ " exports.MO.REL", true ], |
| 35 |
'<=' => [ " exports.MO.BIN5" ], |
| 36 |
'<>' => [ " OPDEF(1, 1)" ], |
| 37 |
'=' => [ " exports.MO.REL" ], |
| 38 |
'==' => [ " exports.MO.BIN4" ], |
| 39 |
'>' => [ " exports.MO.REL", true ], |
| 40 |
'>=' => [ " exports.MO.BIN5" ], |
| 41 |
'?' => [ " [1, 1], MmlNode_js_1.TEXCLASS.CLOSE], null]" ], |
| 42 |
'@' => [ " exports.MO.ORD11" ], |
| 43 |
'\\' => [ " exports.MO.ORD", true ], |
| 44 |
'^' => [ " exports.MO.ORD11" ], |
| 45 |
'_' => [ " exports.MO.ORD11" ], |
| 46 |
'|' => [ " [2, 2], MmlNode_js_1.TEXCLASS.ORD]," . |
| 47 |
"{ fence=> [\"true\"], stretchy=> [\"true\"], symmetric=> [\" true }]" ], |
| 48 |
'||' => [ " [2, 2], MmlNode_js_1.TEXCLASS.ORD]," . |
| 49 |
"{ fence=> [\"true\"], stretchy=> [\"true\"], symmetric=> [\" true }]" ], |
| 50 |
'|||' => [ " [2, 2], MmlNode_js_1.TEXCLASS.ORD]," . |
| 51 |
"{ fence=> [\"true\"], stretchy=> [\"true\"], symmetric=> [\" true }]" ] |
| 52 |
]; |
| 53 |
|
| 54 |
public function execute() { |
| 55 |
$jsonFilePath = './src/WikiTexVC/texutil.json'; |
| 56 |
|
| 57 |
$jsonContent = json_decode( file_get_contents( $jsonFilePath ), true ); |
| 58 |
|
| 59 |
if ( $jsonContent === null ) { |
| 60 |
die( "Failed to decode texutil.json. Please check the file format.\n" ); |
| 61 |
} |
| 62 |
|
| 63 |
foreach ( self::LEGACY_CONCEPTS as $key => $value ) { |
| 64 |
if ( isset( $jsonContent["$key"] ) ) { |
| 65 |
|
| 66 |
$jsonContent["$key"]['operator_infix'] = $value; |
| 67 |
} else { |
| 68 |
|
| 69 |
$jsonContent["$key"] = [ |
| 70 |
'operator_infix' => $value |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
ksort( $jsonContent["$key"] ); |
| 76 |
} |
| 77 |
|
| 78 |
ksort( $jsonContent ); |
| 79 |
$jsonString = json_encode( $jsonContent, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); |
| 80 |
|
| 81 |
$jsonStringWithTabs = preg_replace_callback( '/^( +)/m', static function ( $matches ) { |
| 82 |
|
| 83 |
return str_repeat( "\t", strlen( $matches[1] ) / 4 ); |
| 84 |
}, $jsonString ) . "\n"; |
| 85 |
|
| 86 |
$jsonStringWithTabs = str_replace( '\/', '/', $jsonStringWithTabs ); |
| 87 |
|
| 88 |
file_put_contents( $jsonFilePath, $jsonStringWithTabs ); |
| 89 |
|
| 90 |
echo "texutil.json successfully updated.\n"; |
| 91 |
} |
| 92 |
} |
| 93 |
$maintClass = UpdateTexutil::class; |
| 94 |
require_once RUN_MAINTENANCE_IF_MAIN; |