Skip to content

Commit

Permalink
Implement deprecation warnings
Browse files Browse the repository at this point in the history
Generate deprecation warnings in mathoid if deprecated texvc commands are used.

Bug: T197842
  • Loading branch information
physikerwelt committed Feb 25, 2020
1 parent 7f8db2e commit 7e5df40
Show file tree
Hide file tree
Showing 9 changed files with 1,123 additions and 1,025 deletions.
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ var check = module.exports.check = function(input, options, warnings) {
}
return result;
} catch (e) {
if(e instanceof Parser.SyntaxError && !options.oldtexvc && e.message.startsWith("Deprecation")){
warnings.push( {type: 'texvc-deprecation', details:handleTexError(e,options)});
options.oldtexvc = true;
return check(input, options, warnings);
}
if(e instanceof Parser.SyntaxError && options.usemhchem && !options.oldmhchem ){
warnings.push( {type: 'mhchem-deprecation', details:handleTexError(e,options)});
options.oldmhchem = true;
Expand Down
2,059 changes: 1,054 additions & 1,005 deletions lib/parser.js

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions lib/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ lit
console.assert(Array.isArray(ast) && ast.length === 1);
return ast[0];
}
/ f:generic_func &{ return tu.deprecated_nullary_macro_aliase[f]; } _ // from Texutil.find(...)
{
var ast = peg$parse(tu.deprecated_nullary_macro_aliase[f]);
console.assert(Array.isArray(ast) && ast.length === 1);
if (options.oldtexvc){
return ast[0];
} else {
throw new peg$SyntaxError("Deprecation: Alias no longer supported.", [], text(), location());
}
}
/ r:DELIMITER { return ast.Tex.LITERAL(r); }
/ b:BIG r:DELIMITER { return ast.Tex.BIG(b, r); }
/ b:BIG SQ_CLOSE { return ast.Tex.BIG(b, ast.RenderT.TEX_ONLY( "]")); }
Expand Down Expand Up @@ -325,7 +335,11 @@ LITERAL
/ c:[><~] _
{ return ast.RenderT.TEX_ONLY(c); }
/ c:[%$] _
{ return ast.RenderT.TEX_ONLY("\\" + c); /* escape dangerous chars */}
{ if(options.oldtexvc) {
return ast.RenderT.TEX_ONLY("\\" + c); /* escape dangerous chars */
} else {
throw new peg$SyntaxError("Deprecation: % and $ need to be escaped.", [], text(), location());
}}

// returns a RenderT
DELIMITER
Expand Down Expand Up @@ -438,7 +452,11 @@ FUN_AR1
/ f:generic_func &{ return options.oldmhchem && tu.fun_mhchem[f]} _
{ return f; }
/ f:generic_func &{ return tu.other_fun_ar1[f]; } _
{ return tu.other_fun_ar1[f]; }
{ if (options.oldtexvc) {
return tu.other_fun_ar1[f];
} else {
throw new peg$SyntaxError("Deprecation: \\Bbb and \\bold are not allowed in math mode.", [], text(), location());
}}

FUN_MHCHEM
= f:generic_func &{ return tu.fun_mhchem[f]; } _
Expand Down
17 changes: 11 additions & 6 deletions lib/texutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,13 @@ module.exports.nullary_macro_in_mbox = arr2set([
]);

module.exports.nullary_macro_aliase = obj2map({
"\\C": "\\mathbb{C}",
"\\H": "\\mathbb{H}",
"\\N": "\\mathbb{N}",
"\\Q": "\\mathbb{Q}",
"\\R": "\\mathbb{R}",
"\\Z": "\\mathbb{Z}",
"\\alef": "\\aleph",
"\\alefsym": "\\aleph",
"\\Alpha": "\\mathrm{A}",
"\\and": "\\land",
"\\ang": "\\angle",
"\\Beta": "\\mathrm{B}",
"\\bull": "\\bullet",
"\\Chi": "\\mathrm{X}",
Expand Down Expand Up @@ -565,8 +561,6 @@ module.exports.nullary_macro_aliase = obj2map({
"\\O": "\\emptyset",
"\\omicron": "\\mathrm{o}",
"\\Omicron": "\\mathrm{O}",
"\\or": "\\lor",
"\\part": "\\partial",
"\\plusmn": "\\pm",
"\\rarr": "\\rightarrow",
"\\Rarr": "\\Rightarrow",
Expand All @@ -589,6 +583,16 @@ module.exports.nullary_macro_aliase = obj2map({
"\\Zeta": "\\mathrm{Z}"
});

// Deprecated via T197842
module.exports.deprecated_nullary_macro_aliase = obj2map({
"\\C": "\\mathbb{C}",
"\\H": "\\mathbb{H}",
"\\and": "\\land",
"\\ang": "\\angle",
"\\or": "\\lor",
"\\part": "\\partial",
});

module.exports.big_literals = arr2set([
"\\big",
"\\Big",
Expand Down Expand Up @@ -700,6 +704,7 @@ module.exports.fun_mhchem = arr2set([
"\\ce"
]);

// Deprecated via T197842
module.exports.other_fun_ar1 = obj2map({
"\\Bbb": "\\mathbb",
"\\bold": "\\mathbf"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mathoid-texvcjs",
"version": "0.3.7",
"version": "0.3.8",
"description": "A TeX/LaTeX validator for mediawiki.",
"main": "lib/index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ describe('Comprehensive test cases', function() {
skipOcaml: true
},
'Literals (3)': {
oldtexvc: true,
input:
'\\C\\H\\N\\Q\\R\\Z\\alef\\alefsym\\Alpha\\and\\ang\\Beta' +
'\\bull\\Chi\\clubs\\cnums\\Complex\\Dagger\\diamonds\\Doteq' +
Expand Down Expand Up @@ -317,6 +318,7 @@ describe('Comprehensive test cases', function() {
skipOcaml: 'double spacing and extra braces'
},
'FUN_AR1 (2)': {
oldtexvc: true,
input: '\\Bbb{foo}\\bold{bar}',
output: '{\\mathbb {foo}}{\\mathbf {bar}}',
skipOcaml: 'double spacing',
Expand Down Expand Up @@ -452,7 +454,7 @@ describe('Comprehensive test cases', function() {
tc.output = tc.output || tc.input;
if (!tc.skipJs) {
it('output should be correct', function() {
var result = texvcjs.check(tc.input, { debug: true, usemathrm:tc.usemathrm});
var result = texvcjs.check(tc.input, { debug: true, usemathrm:tc.usemathrm, oldtexvc: tc.oldtexvc});
assert.equal(result.status, '+');
assert.equal(result.output, tc.output);
});
Expand Down
2 changes: 1 addition & 1 deletion test/contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('ast.Tex.contains_func', function() {
(expected ? tc.yes : tc.no).forEach(function(target) {
it('should ' + (expected ? '' : 'not ') + 'find ' + target +
' in ' + tc.input.replace(/\n/g,' '), function() {
var p = texvcjs.parse(tc.input, { debug: true, usemhchem:true });
var p = texvcjs.parse(tc.input, { debug: true, usemhchem:true, oldtexvc:true });
assert.equal(texvcjs.contains_func(p, target),
expected ? target : false);
});
Expand Down
2 changes: 1 addition & 1 deletion test/mathjax-texvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Run test for all mathjax-texvc commands:', function () {
expected: testcase.texvcjs
}, null, 2));
assert.equal(result.status,'+');
assert.equal(result.warnings.length, testcase.warnCount||0);
assert.equal(result.warnings.length, testcase.warnCount||0, "incorrect number of warnings");
});
}
});
Expand Down
35 changes: 27 additions & 8 deletions test/mathjax-texvc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"texvcjs": "\\mathbb {C} ",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 6,
Expand All @@ -61,7 +62,8 @@
"texvcjs": "\\mathbb {H} ",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 9,
Expand Down Expand Up @@ -181,7 +183,8 @@
"texvcjs": "\\partial ",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 24,
Expand Down Expand Up @@ -213,7 +216,8 @@
"texvcjs": "\\angle ",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 28,
Expand Down Expand Up @@ -269,15 +273,17 @@
"texvcjs": "\\land ",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 35,
"input": "\\or",
"texvcjs": "\\lor ",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 36,
Expand Down Expand Up @@ -693,7 +699,8 @@
"texvcjs": "{\\mathbf {x}}",
"options": {
"usemathrm": true
}
},
"warnCount": 1
},
{
"id": 88,
Expand Down Expand Up @@ -1587,7 +1594,8 @@
"options": {
"usemathrm": true,
"usemhchem": true
}
},
"warnCount": 1
},
{
"id": 195,
Expand Down Expand Up @@ -1737,6 +1745,17 @@
"usemathrm": true,
"usemhchem": true
},
"warnCount": 2
},
{
"id": 211,
"input": "\\$",
"texvcjs": "\\$"
},
{
"id": 212,
"input": "$",
"texvcjs": "\\$",
"warnCount": 1
}
]

0 comments on commit 7e5df40

Please sign in to comment.