parent
b044a021c4
commit
5f65de92bc
|
@ -222,7 +222,7 @@ function generateBytecode(ast) {
|
|||
}
|
||||
|
||||
function buildCall(functionIndex, delta, env, sp) {
|
||||
var params = arrays.map(objects.values(env), function(p) { return sp - p; });
|
||||
var params = objects.values(env).map(function(p) { return sp - p; });
|
||||
|
||||
return [op.CALL, functionIndex, delta, params.length].concat(params);
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ function generateBytecode(ast) {
|
|||
if (node.parts.length > 0) {
|
||||
regexp = '/^['
|
||||
+ (node.inverted ? '^' : '')
|
||||
+ arrays.map(node.parts, function(part) {
|
||||
+ node.parts.map(function(part) {
|
||||
return part instanceof Array
|
||||
? js.regexpClassEscape(part[0])
|
||||
+ '-'
|
||||
|
@ -591,7 +591,7 @@ function generateBytecode(ast) {
|
|||
}
|
||||
|
||||
parts = '['
|
||||
+ arrays.map(node.parts, function(part) {
|
||||
+ node.parts.map(function(part) {
|
||||
return part instanceof Array
|
||||
? '["' + js.stringEscape(part[0]) + '", "' + js.stringEscape(part[1]) + '"]'
|
||||
: '"' + js.stringEscape(part) + '"';
|
||||
|
|
|
@ -21,10 +21,9 @@ function generateJS(ast, options) {
|
|||
'],',
|
||||
'',
|
||||
'peg$bytecode = [',
|
||||
indent2(arrays.map(ast.rules, function(rule) {
|
||||
indent2(ast.rules.map(function(rule) {
|
||||
return 'peg$decode("'
|
||||
+ js.stringEscape(arrays.map(
|
||||
rule.bytecode,
|
||||
+ js.stringEscape(rule.bytecode.map(
|
||||
function(b) { return String.fromCharCode(b + 32); }
|
||||
).join(''))
|
||||
+ '")';
|
||||
|
@ -32,8 +31,7 @@ function generateJS(ast, options) {
|
|||
'],'
|
||||
].join('\n');
|
||||
} else {
|
||||
return arrays.map(
|
||||
ast.consts,
|
||||
return ast.consts.map(
|
||||
function(c, i) { return 'peg$c' + i + ' = ' + c + ','; }
|
||||
).join('\n');
|
||||
}
|
||||
|
@ -443,7 +441,7 @@ function generateJS(ast, options) {
|
|||
if (n === void 0) {
|
||||
return s(this.sp--);
|
||||
} else {
|
||||
values = arrays.map(arrays.range(this.sp - n + 1, this.sp + 1), s);
|
||||
values = arrays.range(this.sp - n + 1, this.sp + 1).map(s);
|
||||
this.sp -= n;
|
||||
|
||||
return values;
|
||||
|
@ -524,8 +522,7 @@ function generateJS(ast, options) {
|
|||
paramsLength = bc[ip + baseLength - 1];
|
||||
|
||||
var value = c(bc[ip + 1]) + '('
|
||||
+ arrays.map(
|
||||
bc.slice(ip + baseLength, ip + baseLength + paramsLength),
|
||||
+ bc.slice(ip + baseLength, ip + baseLength + paramsLength).map(
|
||||
function(p) { return stack.index(p); }
|
||||
).join(', ')
|
||||
+ ')';
|
||||
|
@ -731,12 +728,12 @@ function generateJS(ast, options) {
|
|||
|
||||
if (options.trace) {
|
||||
parts.push([
|
||||
' var ' + arrays.map(arrays.range(0, stack.maxSp + 1), s).join(', ') + ',',
|
||||
' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ',',
|
||||
' startPos = peg$currPos;'
|
||||
].join('\n'));
|
||||
} else {
|
||||
parts.push(
|
||||
' var ' + arrays.map(arrays.range(0, stack.maxSp + 1), s).join(', ') + ';'
|
||||
' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ';'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -959,8 +956,7 @@ function generateJS(ast, options) {
|
|||
|
||||
if (options.optimize === "size") {
|
||||
startRuleIndices = '{ '
|
||||
+ arrays.map(
|
||||
options.allowedStartRules,
|
||||
+ options.allowedStartRules.map(
|
||||
function(r) { return r + ': ' + asts.indexOfRule(ast, r); }
|
||||
).join(', ')
|
||||
+ ' }';
|
||||
|
@ -972,8 +968,7 @@ function generateJS(ast, options) {
|
|||
].join('\n'));
|
||||
} else {
|
||||
startRuleFunctions = '{ '
|
||||
+ arrays.map(
|
||||
options.allowedStartRules,
|
||||
+ options.allowedStartRules.map(
|
||||
function(r) { return r + ': peg$parse' + r; }
|
||||
).join(', ')
|
||||
+ ' }';
|
||||
|
@ -1010,8 +1005,7 @@ function generateJS(ast, options) {
|
|||
if (options.trace) {
|
||||
if (options.optimize === "size") {
|
||||
ruleNames = '['
|
||||
+ arrays.map(
|
||||
ast.rules,
|
||||
+ ast.rules.map(
|
||||
function(r) { return '"' + js.stringEscape(r.name) + '"'; }
|
||||
).join(', ')
|
||||
+ ']';
|
||||
|
@ -1267,8 +1261,7 @@ function generateJS(ast, options) {
|
|||
commonjs: function() {
|
||||
var parts = [],
|
||||
dependencyVars = objects.keys(options.dependencies),
|
||||
requires = arrays.map(
|
||||
dependencyVars,
|
||||
requires = dependencyVars.map(
|
||||
function(variable) {
|
||||
return variable
|
||||
+ ' = require("'
|
||||
|
@ -1303,8 +1296,7 @@ function generateJS(ast, options) {
|
|||
var dependencyIds = objects.values(options.dependencies),
|
||||
dependencyVars = objects.keys(options.dependencies),
|
||||
dependencies = '['
|
||||
+ arrays.map(
|
||||
dependencyIds,
|
||||
+ dependencyIds.map(
|
||||
function(id) { return '"' + js.stringEscape(id) + '"'; }
|
||||
).join(', ')
|
||||
+ ']',
|
||||
|
@ -1342,13 +1334,11 @@ function generateJS(ast, options) {
|
|||
dependencyIds = objects.values(options.dependencies),
|
||||
dependencyVars = objects.keys(options.dependencies),
|
||||
dependencies = '['
|
||||
+ arrays.map(
|
||||
dependencyIds,
|
||||
+ dependencyIds.map(
|
||||
function(id) { return '"' + js.stringEscape(id) + '"'; }
|
||||
).join(', ')
|
||||
+ ']',
|
||||
requires = arrays.map(
|
||||
dependencyIds,
|
||||
requires = dependencyIds.map(
|
||||
function(id) { return 'require("' + js.stringEscape(id) + '")'; }
|
||||
).join(', '),
|
||||
params = dependencyVars.join(', ');
|
||||
|
|
|
@ -56,20 +56,8 @@ var arrays = {
|
|||
return arrays.indexOf(array, valueOrPredicate) !== -1;
|
||||
},
|
||||
|
||||
map: function(array, iterator) {
|
||||
var length = array.length,
|
||||
result = new Array(length),
|
||||
i;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
result[i] = iterator(array[i], i);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
pluck: function(array, key) {
|
||||
return arrays.map(array, function (e) { return e[key]; });
|
||||
return array.map(function (e) { return e[key]; });
|
||||
},
|
||||
|
||||
every: function(array, predicate) {
|
||||
|
|
Loading…
Reference in a new issue