Merge pull request #4976 from CodingFabian/restructure-evaluator-read
Restructured EvaluatorPreprocessor_read to be more natural.
This commit is contained in:
commit
bb7e7d33c5
@ -2104,10 +2104,60 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
var args = null;
|
var args = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
var obj = this.parser.getObj();
|
var obj = this.parser.getObj();
|
||||||
if (isEOF(obj)) {
|
if (isCmd(obj)) {
|
||||||
return false; // no more commands
|
var cmd = obj.cmd;
|
||||||
}
|
// Check that the command is valid
|
||||||
if (!isCmd(obj)) {
|
var opSpec = OP_MAP[cmd];
|
||||||
|
if (!opSpec) {
|
||||||
|
warn('Unknown command "' + cmd + '"');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fn = opSpec.id;
|
||||||
|
var numArgs = opSpec.numArgs;
|
||||||
|
|
||||||
|
if (!opSpec.variableArgs) {
|
||||||
|
// Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
||||||
|
var argsLength = args !== null ? args.length : 0;
|
||||||
|
if (argsLength !== numArgs) {
|
||||||
|
var nonProcessedArgs = this.nonProcessedArgs;
|
||||||
|
while (argsLength > numArgs) {
|
||||||
|
nonProcessedArgs.push(args.shift());
|
||||||
|
argsLength--;
|
||||||
|
}
|
||||||
|
while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
|
||||||
|
if (!args) {
|
||||||
|
args = [];
|
||||||
|
}
|
||||||
|
args.unshift(nonProcessedArgs.pop());
|
||||||
|
argsLength++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argsLength < numArgs) {
|
||||||
|
// If we receive too few args, it's not possible to possible
|
||||||
|
// to execute the command, so skip the command
|
||||||
|
info('Command ' + fn + ': because expected ' +
|
||||||
|
numArgs + ' args, but received ' + argsLength +
|
||||||
|
' args; skipping');
|
||||||
|
args = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (argsLength > numArgs) {
|
||||||
|
info('Command ' + fn + ': expected [0,' + numArgs +
|
||||||
|
'] args, but received ' + argsLength + ' args');
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO figure out how to type-check vararg functions
|
||||||
|
this.preprocessCommand(fn, args);
|
||||||
|
|
||||||
|
operation.fn = fn;
|
||||||
|
operation.args = args;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (isEOF(obj)) {
|
||||||
|
return false; // no more commands
|
||||||
|
}
|
||||||
// argument
|
// argument
|
||||||
if (obj !== null) {
|
if (obj !== null) {
|
||||||
if (!args) {
|
if (!args) {
|
||||||
@ -2116,58 +2166,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||||||
args.push((obj instanceof Dict ? obj.getAll() : obj));
|
args.push((obj instanceof Dict ? obj.getAll() : obj));
|
||||||
assert(args.length <= 33, 'Too many arguments');
|
assert(args.length <= 33, 'Too many arguments');
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd = obj.cmd;
|
|
||||||
// Check that the command is valid
|
|
||||||
var opSpec = OP_MAP[cmd];
|
|
||||||
if (!opSpec) {
|
|
||||||
warn('Unknown command "' + cmd + '"');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fn = opSpec.id;
|
|
||||||
var numArgs = opSpec.numArgs;
|
|
||||||
|
|
||||||
if (!opSpec.variableArgs) {
|
|
||||||
// Some post script commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
|
|
||||||
var argsLength = args !== null ? args.length : 0;
|
|
||||||
if (argsLength !== numArgs) {
|
|
||||||
var nonProcessedArgs = this.nonProcessedArgs;
|
|
||||||
while (argsLength > numArgs) {
|
|
||||||
nonProcessedArgs.push(args.shift());
|
|
||||||
argsLength--;
|
|
||||||
}
|
|
||||||
while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
|
|
||||||
if (!args) {
|
|
||||||
args = [];
|
|
||||||
}
|
|
||||||
args.unshift(nonProcessedArgs.pop());
|
|
||||||
argsLength++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argsLength < numArgs) {
|
|
||||||
// If we receive too few args, it's not possible to possible
|
|
||||||
// to execute the command, so skip the command
|
|
||||||
info('Command ' + fn + ': because expected ' +
|
|
||||||
numArgs + ' args, but received ' + argsLength +
|
|
||||||
' args; skipping');
|
|
||||||
args = null;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else if (argsLength > numArgs) {
|
|
||||||
info('Command ' + fn + ': expected [0,' + numArgs +
|
|
||||||
'] args, but received ' + argsLength + ' args');
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO figure out how to type-check vararg functions
|
|
||||||
this.preprocessCommand(fn, args);
|
|
||||||
|
|
||||||
operation.fn = fn;
|
|
||||||
operation.args = args;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user