Skip to content

Commit 7e5df40

Browse files
committed
Implement deprecation warnings
Generate deprecation warnings in mathoid if deprecated texvc commands are used. Bug: T197842
1 parent 7f8db2e commit 7e5df40

9 files changed

+1123
-1025
lines changed

lib/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ var check = module.exports.check = function(input, options, warnings) {
8585
}
8686
return result;
8787
} catch (e) {
88+
if(e instanceof Parser.SyntaxError && !options.oldtexvc && e.message.startsWith("Deprecation")){
89+
warnings.push( {type: 'texvc-deprecation', details:handleTexError(e,options)});
90+
options.oldtexvc = true;
91+
return check(input, options, warnings);
92+
}
8893
if(e instanceof Parser.SyntaxError && options.usemhchem && !options.oldmhchem ){
8994
warnings.push( {type: 'mhchem-deprecation', details:handleTexError(e,options)});
9095
options.oldmhchem = true;

lib/parser.js

+1,054-1,005
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/parser.pegjs

+20-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ lit
123123
console.assert(Array.isArray(ast) && ast.length === 1);
124124
return ast[0];
125125
}
126+
/ f:generic_func &{ return tu.deprecated_nullary_macro_aliase[f]; } _ // from Texutil.find(...)
127+
{
128+
var ast = peg$parse(tu.deprecated_nullary_macro_aliase[f]);
129+
console.assert(Array.isArray(ast) && ast.length === 1);
130+
if (options.oldtexvc){
131+
return ast[0];
132+
} else {
133+
throw new peg$SyntaxError("Deprecation: Alias no longer supported.", [], text(), location());
134+
}
135+
}
126136
/ r:DELIMITER { return ast.Tex.LITERAL(r); }
127137
/ b:BIG r:DELIMITER { return ast.Tex.BIG(b, r); }
128138
/ b:BIG SQ_CLOSE { return ast.Tex.BIG(b, ast.RenderT.TEX_ONLY( "]")); }
@@ -325,7 +335,11 @@ LITERAL
325335
/ c:[><~] _
326336
{ return ast.RenderT.TEX_ONLY(c); }
327337
/ c:[%$] _
328-
{ return ast.RenderT.TEX_ONLY("\\" + c); /* escape dangerous chars */}
338+
{ if(options.oldtexvc) {
339+
return ast.RenderT.TEX_ONLY("\\" + c); /* escape dangerous chars */
340+
} else {
341+
throw new peg$SyntaxError("Deprecation: % and $ need to be escaped.", [], text(), location());
342+
}}
329343

330344
// returns a RenderT
331345
DELIMITER
@@ -438,7 +452,11 @@ FUN_AR1
438452
/ f:generic_func &{ return options.oldmhchem && tu.fun_mhchem[f]} _
439453
{ return f; }
440454
/ f:generic_func &{ return tu.other_fun_ar1[f]; } _
441-
{ return tu.other_fun_ar1[f]; }
455+
{ if (options.oldtexvc) {
456+
return tu.other_fun_ar1[f];
457+
} else {
458+
throw new peg$SyntaxError("Deprecation: \\Bbb and \\bold are not allowed in math mode.", [], text(), location());
459+
}}
442460

443461
FUN_MHCHEM
444462
= f:generic_func &{ return tu.fun_mhchem[f]; } _

lib/texutil.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,13 @@ module.exports.nullary_macro_in_mbox = arr2set([
514514
]);
515515

516516
module.exports.nullary_macro_aliase = obj2map({
517-
"\\C": "\\mathbb{C}",
518-
"\\H": "\\mathbb{H}",
519517
"\\N": "\\mathbb{N}",
520518
"\\Q": "\\mathbb{Q}",
521519
"\\R": "\\mathbb{R}",
522520
"\\Z": "\\mathbb{Z}",
523521
"\\alef": "\\aleph",
524522
"\\alefsym": "\\aleph",
525523
"\\Alpha": "\\mathrm{A}",
526-
"\\and": "\\land",
527-
"\\ang": "\\angle",
528524
"\\Beta": "\\mathrm{B}",
529525
"\\bull": "\\bullet",
530526
"\\Chi": "\\mathrm{X}",
@@ -565,8 +561,6 @@ module.exports.nullary_macro_aliase = obj2map({
565561
"\\O": "\\emptyset",
566562
"\\omicron": "\\mathrm{o}",
567563
"\\Omicron": "\\mathrm{O}",
568-
"\\or": "\\lor",
569-
"\\part": "\\partial",
570564
"\\plusmn": "\\pm",
571565
"\\rarr": "\\rightarrow",
572566
"\\Rarr": "\\Rightarrow",
@@ -589,6 +583,16 @@ module.exports.nullary_macro_aliase = obj2map({
589583
"\\Zeta": "\\mathrm{Z}"
590584
});
591585

586+
// Deprecated via T197842
587+
module.exports.deprecated_nullary_macro_aliase = obj2map({
588+
"\\C": "\\mathbb{C}",
589+
"\\H": "\\mathbb{H}",
590+
"\\and": "\\land",
591+
"\\ang": "\\angle",
592+
"\\or": "\\lor",
593+
"\\part": "\\partial",
594+
});
595+
592596
module.exports.big_literals = arr2set([
593597
"\\big",
594598
"\\Big",
@@ -700,6 +704,7 @@ module.exports.fun_mhchem = arr2set([
700704
"\\ce"
701705
]);
702706

707+
// Deprecated via T197842
703708
module.exports.other_fun_ar1 = obj2map({
704709
"\\Bbb": "\\mathbb",
705710
"\\bold": "\\mathbf"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mathoid-texvcjs",
3-
"version": "0.3.7",
3+
"version": "0.3.8",
44
"description": "A TeX/LaTeX validator for mediawiki.",
55
"main": "lib/index.js",
66
"scripts": {

test/all.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ describe('Comprehensive test cases', function() {
209209
skipOcaml: true
210210
},
211211
'Literals (3)': {
212+
oldtexvc: true,
212213
input:
213214
'\\C\\H\\N\\Q\\R\\Z\\alef\\alefsym\\Alpha\\and\\ang\\Beta' +
214215
'\\bull\\Chi\\clubs\\cnums\\Complex\\Dagger\\diamonds\\Doteq' +
@@ -317,6 +318,7 @@ describe('Comprehensive test cases', function() {
317318
skipOcaml: 'double spacing and extra braces'
318319
},
319320
'FUN_AR1 (2)': {
321+
oldtexvc: true,
320322
input: '\\Bbb{foo}\\bold{bar}',
321323
output: '{\\mathbb {foo}}{\\mathbf {bar}}',
322324
skipOcaml: 'double spacing',
@@ -452,7 +454,7 @@ describe('Comprehensive test cases', function() {
452454
tc.output = tc.output || tc.input;
453455
if (!tc.skipJs) {
454456
it('output should be correct', function() {
455-
var result = texvcjs.check(tc.input, { debug: true, usemathrm:tc.usemathrm});
457+
var result = texvcjs.check(tc.input, { debug: true, usemathrm:tc.usemathrm, oldtexvc: tc.oldtexvc});
456458
assert.equal(result.status, '+');
457459
assert.equal(result.output, tc.output);
458460
});

test/contains.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('ast.Tex.contains_func', function() {
6565
(expected ? tc.yes : tc.no).forEach(function(target) {
6666
it('should ' + (expected ? '' : 'not ') + 'find ' + target +
6767
' in ' + tc.input.replace(/\n/g,' '), function() {
68-
var p = texvcjs.parse(tc.input, { debug: true, usemhchem:true });
68+
var p = texvcjs.parse(tc.input, { debug: true, usemhchem:true, oldtexvc:true });
6969
assert.equal(texvcjs.contains_func(p, target),
7070
expected ? target : false);
7171
});

test/mathjax-texvc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('Run test for all mathjax-texvc commands:', function () {
2222
expected: testcase.texvcjs
2323
}, null, 2));
2424
assert.equal(result.status,'+');
25-
assert.equal(result.warnings.length, testcase.warnCount||0);
25+
assert.equal(result.warnings.length, testcase.warnCount||0, "incorrect number of warnings");
2626
});
2727
}
2828
});

test/mathjax-texvc.json

+27-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"texvcjs": "\\mathbb {C} ",
3838
"options": {
3939
"usemathrm": true
40-
}
40+
},
41+
"warnCount": 1
4142
},
4243
{
4344
"id": 6,
@@ -61,7 +62,8 @@
6162
"texvcjs": "\\mathbb {H} ",
6263
"options": {
6364
"usemathrm": true
64-
}
65+
},
66+
"warnCount": 1
6567
},
6668
{
6769
"id": 9,
@@ -181,7 +183,8 @@
181183
"texvcjs": "\\partial ",
182184
"options": {
183185
"usemathrm": true
184-
}
186+
},
187+
"warnCount": 1
185188
},
186189
{
187190
"id": 24,
@@ -213,7 +216,8 @@
213216
"texvcjs": "\\angle ",
214217
"options": {
215218
"usemathrm": true
216-
}
219+
},
220+
"warnCount": 1
217221
},
218222
{
219223
"id": 28,
@@ -269,15 +273,17 @@
269273
"texvcjs": "\\land ",
270274
"options": {
271275
"usemathrm": true
272-
}
276+
},
277+
"warnCount": 1
273278
},
274279
{
275280
"id": 35,
276281
"input": "\\or",
277282
"texvcjs": "\\lor ",
278283
"options": {
279284
"usemathrm": true
280-
}
285+
},
286+
"warnCount": 1
281287
},
282288
{
283289
"id": 36,
@@ -693,7 +699,8 @@
693699
"texvcjs": "{\\mathbf {x}}",
694700
"options": {
695701
"usemathrm": true
696-
}
702+
},
703+
"warnCount": 1
697704
},
698705
{
699706
"id": 88,
@@ -1587,7 +1594,8 @@
15871594
"options": {
15881595
"usemathrm": true,
15891596
"usemhchem": true
1590-
}
1597+
},
1598+
"warnCount": 1
15911599
},
15921600
{
15931601
"id": 195,
@@ -1737,6 +1745,17 @@
17371745
"usemathrm": true,
17381746
"usemhchem": true
17391747
},
1748+
"warnCount": 2
1749+
},
1750+
{
1751+
"id": 211,
1752+
"input": "\\$",
1753+
"texvcjs": "\\$"
1754+
},
1755+
{
1756+
"id": 212,
1757+
"input": "$",
1758+
"texvcjs": "\\$",
17401759
"warnCount": 1
17411760
}
17421761
]

0 commit comments

Comments
 (0)