#!/usr/bin/perl # -*- Mode: Perl; tab-width: 2; indent-tabs-mode: nil; -*- # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
use XML::LibXSLT;
use XML::LibXML;
use LWP::Simple;
# 1.3) save the key and value
$moz_hash{$key} = [ @value ];
}
close($file);
################################################################################ # 2) If mode "check", verify validity of our operator dictionary and quit. # If mode "compare", go to step 3)
if ($ARGV[0] eq "check") {
print "checking operator dictionary...\n";
open($file_syntax_errors, ">$FILE_SYNTAX_ERRORS") ||
die ("Couldn't open $FILE_SYNTAX_ERRORS!");
$nb_errors = 0;
$nb_warnings = 0;
@moz_keys = (keys %moz_hash); # check the validity of our private data while ($key = pop(@moz_keys)) {
if ($key =~ /\\u.+\\u.+\\u.+/) {
$valid = 0;
$nb_errors++;
print $file_syntax_errors "error: \"$key\" has more than 2 characters\n";
}
if ($key =~ /\\u20D2\./ || $key =~ /\\u0338\./) {
$valid = 0;
$nb_errors++;
print $file_syntax_errors "error: \"$key\" ends with character U+20D2 or U+0338\n";
}
if (@moz[4] && !(@moz[13] eq "vertical")) {
$valid = 0;
$nb_errors++;
print $file_syntax_errors "error: operator is largeop but does not have vertical direction\n";
}
if (@moz_prefix) { if (@moz_infix &&
!($moz_infix[13] eq $moz_prefix[13])) {
$same_direction = 0;
} if (@moz_postfix &&
!($moz_postfix[13] eq $moz_prefix[13])) {
$same_direction = 0;
}
} if (@moz_infix) { if (@moz_postfix &&
!($moz_postfix[13] eq $moz_infix[13])) {
$same_direction = 0;
}
}
if (!$same_direction) {
$nb_errors++;
print $file_syntax_errors "error: operator has a stretchy form, but all forms";
print $file_syntax_errors " have not the same direction\n"; if (@moz_prefix) {
$_ = &generateEntry($key_prefix, @moz_prefix);
print $file_syntax_errors $_;
} if (@moz_infix) {
$_ = &generateEntry($key_infix, @moz_infix);
print $file_syntax_errors $_;
} if (@moz_postfix) {
$_ = &generateEntry($key_postfix, @moz_postfix);
print $file_syntax_errors $_;
}
print $file_syntax_errors "\n";
}
if (@moz_prefix) { delete $moz_hash{$key.prefix};
} if (@moz_infix) { delete $moz_hash{$key_infix};
} if (@moz_postfix) { delete $moz_hash{$key_postfix};
}
}
}
# not stored in the WG dictionary
$value[8] = ""; # accent
$value[13] = ""; # direction
# 3.3) save the key and value
push(@wg_keys, $key);
$wg_hash{$key} = [ @value ];
}
@wg_keys = reverse(@wg_keys);
################################################################################ # 4) Compare the two dictionaries and output the result
print "comparing dictionaries...\n";
open($file_differences, ">$FILE_DIFFERENCES") ||
die ("Couldn't open $FILE_DIFFERENCES!");
open($file_new_dictionary, ">$FILE_NEW_DICTIONARY") ||
die ("Couldn't open $FILE_NEW_DICTIONARY!");
print $file_new_dictionary "\n# Entries below are not part of the official MathML dictionary\n\n"; # 4.2) look in our dictionary the remaining entries
@moz_keys = (keys %moz_hash);
@moz_keys = reverse(sort(@moz_keys));
print "\n";
print "- $obsolete obsolete entries ";
print "($obsolete_stretching of them are related to stretching)\n";
print "- $unchanged unchanged entries\n";
print "- $conflicting conflicting entries ";
print "($conflicting_stretching of them are related to stretching)\n";
print "- $new new entries ";
print "($new_stretching of them are related to stretching)\n";
print "\nSee output files $FILE_DIFFERENCES and $FILE_NEW_DICTIONARY.\n\n";
print "After having modified the dictionary, please run";
print "./updateOperatorDictionary check\n\n";
exit 0;
sub generateCommon { # helper function to generate the string of data shared by both dictionaries
my(@v) = @_;
$entry = "lspace:$v[1] rspace:$v[2]"; if ($v[4]) { $entry = "$entry largeop"; } if ($v[5]) { $entry = "$entry movablelimits"; } if ($v[6]) { $entry = "$entry stretchy"; } if ($v[7]) { $entry = "$entry separator"; } if ($v[9]) { $entry = "$entry fence"; } if ($v[10]) { $entry = "$entry symmetric"; }
return $entry;
}
sub completeCommon { # helper to add key and private data to generateCommon
my($entry, $key, @v_moz, @v_wg) = @_;
$entry = "$key = $entry";
if ($v_moz[8]) { $entry = "$entry accent"; } if ($v_moz[13]) { $entry = "$entry direction:$v_moz[13]"; }
if ($v_moz[0]) { # keep our previous comment
$entry = "$entry # $v_moz[0]";
} else { # otherwise use the description given by the WG
$entry = "$entry # $v_wg[0]";
}
$entry = "$entry\n";
return $entry;
}
sub generateEntry { # helper function to generate an entry of our operator dictionary
my($key, @moz) = @_;
$entry = &generateCommon(@moz);
$entry = &completeCommon($entry, $key, @moz, @moz);
return $entry;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.35Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.