Improving invalid operations syntax recovery (#1466) (see also #589)

This commit is contained in:
Yury Delendik 2012-04-04 11:50:20 -05:00
parent 921c1e82a3
commit 0ca4ca6077
3 changed files with 37 additions and 12 deletions

View File

@ -111,6 +111,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
EX: 'endCompat'
};
function splitCombinedOperations(operations) {
// Two operations can be combined together, trying to find which two
// operations were concatenated.
for (var i = operations.length - 1; i > 0; i--) {
var op1 = operations.substring(0, i), op2 = operations.substring(i);
if (op1 in OP_MAP && op2 in OP_MAP)
return [op1, op2]; // operations found
}
return null;
}
PartialEvaluator.prototype = {
getOperatorList: function partialEvaluatorGetOperatorList(stream, resources,
dependency, queue) {
@ -255,26 +266,32 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var patterns = xref.fetchIfRef(resources.get('Pattern')) || new Dict();
var parser = new Parser(new Lexer(stream), false);
var res = resources;
var hasNextObj = false, nextObj;
var args = [], obj;
var getObjBt = function getObjBt() {
parser = this.oldParser;
return { name: 'BT' };
};
var TILING_PATTERN = 1, SHADING_PATTERN = 2;
while (!isEOF(obj = parser.getObj())) {
while (true) {
if (hasNextObj) {
obj = nextObj;
hasNextObj = false;
} else {
obj = parser.getObj();
if (isEOF(obj))
break;
}
if (isCmd(obj)) {
var cmd = obj.cmd;
var fn = OP_MAP[cmd];
if (!fn) {
// invalid content command, trying to recover
if (cmd.substr(-2) == 'BT') {
fn = OP_MAP[cmd.substr(0, cmd.length - 2)];
// feeding 'BT' on next interation
parser = {
getObj: getObjBt,
oldParser: parser
};
var cmds = splitCombinedOperations(cmd);
if (cmds) {
cmd = cmds[0];
fn = OP_MAP[cmd];
// feeding other command on the next interation
hasNextObj = true;
nextObj = Cmd.get(cmds[1]);
}
}
assertWellFormed(fn, 'Unknown command "' + cmd + '"');

View File

@ -0,0 +1 @@
http://web.missouri.edu/~fanxud/publications/On%20the%20performance%20quantification%20of%20resonant%20refractive%20index%20sensors.pdf

View File

@ -501,6 +501,13 @@
"link": true,
"type": "eq"
},
{ "id": "issue1466",
"file": "pdfs/issue1466.pdf",
"md5": "8a8877432e5bb10cfd50d60488d947bb",
"rounds": 1,
"link": true,
"type": "eq"
},
{ "id": "issue1133",
"file": "pdfs/issue1133.pdf",
"md5": "d1b61580cb100e3df93d33703af1773a",