|
|
@ -21,10 +21,9 @@ function generateJS(ast, options) {
|
|
|
|
'],',
|
|
|
|
'],',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'peg$bytecode = [',
|
|
|
|
'peg$bytecode = [',
|
|
|
|
indent2(arrays.map(ast.rules, function(rule) {
|
|
|
|
indent2(ast.rules.map(function(rule) {
|
|
|
|
return 'peg$decode("'
|
|
|
|
return 'peg$decode("'
|
|
|
|
+ js.stringEscape(arrays.map(
|
|
|
|
+ js.stringEscape(rule.bytecode.map(
|
|
|
|
rule.bytecode,
|
|
|
|
|
|
|
|
function(b) { return String.fromCharCode(b + 32); }
|
|
|
|
function(b) { return String.fromCharCode(b + 32); }
|
|
|
|
).join(''))
|
|
|
|
).join(''))
|
|
|
|
+ '")';
|
|
|
|
+ '")';
|
|
|
@ -32,8 +31,7 @@ function generateJS(ast, options) {
|
|
|
|
'],'
|
|
|
|
'],'
|
|
|
|
].join('\n');
|
|
|
|
].join('\n');
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return arrays.map(
|
|
|
|
return ast.consts.map(
|
|
|
|
ast.consts,
|
|
|
|
|
|
|
|
function(c, i) { return 'peg$c' + i + ' = ' + c + ','; }
|
|
|
|
function(c, i) { return 'peg$c' + i + ' = ' + c + ','; }
|
|
|
|
).join('\n');
|
|
|
|
).join('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -443,7 +441,7 @@ function generateJS(ast, options) {
|
|
|
|
if (n === void 0) {
|
|
|
|
if (n === void 0) {
|
|
|
|
return s(this.sp--);
|
|
|
|
return s(this.sp--);
|
|
|
|
} else {
|
|
|
|
} 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;
|
|
|
|
this.sp -= n;
|
|
|
|
|
|
|
|
|
|
|
|
return values;
|
|
|
|
return values;
|
|
|
@ -524,8 +522,7 @@ function generateJS(ast, options) {
|
|
|
|
paramsLength = bc[ip + baseLength - 1];
|
|
|
|
paramsLength = bc[ip + baseLength - 1];
|
|
|
|
|
|
|
|
|
|
|
|
var value = c(bc[ip + 1]) + '('
|
|
|
|
var value = c(bc[ip + 1]) + '('
|
|
|
|
+ arrays.map(
|
|
|
|
+ bc.slice(ip + baseLength, ip + baseLength + paramsLength).map(
|
|
|
|
bc.slice(ip + baseLength, ip + baseLength + paramsLength),
|
|
|
|
|
|
|
|
function(p) { return stack.index(p); }
|
|
|
|
function(p) { return stack.index(p); }
|
|
|
|
).join(', ')
|
|
|
|
).join(', ')
|
|
|
|
+ ')';
|
|
|
|
+ ')';
|
|
|
@ -731,12 +728,12 @@ function generateJS(ast, options) {
|
|
|
|
|
|
|
|
|
|
|
|
if (options.trace) {
|
|
|
|
if (options.trace) {
|
|
|
|
parts.push([
|
|
|
|
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;'
|
|
|
|
' startPos = peg$currPos;'
|
|
|
|
].join('\n'));
|
|
|
|
].join('\n'));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
parts.push(
|
|
|
|
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") {
|
|
|
|
if (options.optimize === "size") {
|
|
|
|
startRuleIndices = '{ '
|
|
|
|
startRuleIndices = '{ '
|
|
|
|
+ arrays.map(
|
|
|
|
+ options.allowedStartRules.map(
|
|
|
|
options.allowedStartRules,
|
|
|
|
|
|
|
|
function(r) { return r + ': ' + asts.indexOfRule(ast, r); }
|
|
|
|
function(r) { return r + ': ' + asts.indexOfRule(ast, r); }
|
|
|
|
).join(', ')
|
|
|
|
).join(', ')
|
|
|
|
+ ' }';
|
|
|
|
+ ' }';
|
|
|
@ -972,8 +968,7 @@ function generateJS(ast, options) {
|
|
|
|
].join('\n'));
|
|
|
|
].join('\n'));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
startRuleFunctions = '{ '
|
|
|
|
startRuleFunctions = '{ '
|
|
|
|
+ arrays.map(
|
|
|
|
+ options.allowedStartRules.map(
|
|
|
|
options.allowedStartRules,
|
|
|
|
|
|
|
|
function(r) { return r + ': peg$parse' + r; }
|
|
|
|
function(r) { return r + ': peg$parse' + r; }
|
|
|
|
).join(', ')
|
|
|
|
).join(', ')
|
|
|
|
+ ' }';
|
|
|
|
+ ' }';
|
|
|
@ -1010,8 +1005,7 @@ function generateJS(ast, options) {
|
|
|
|
if (options.trace) {
|
|
|
|
if (options.trace) {
|
|
|
|
if (options.optimize === "size") {
|
|
|
|
if (options.optimize === "size") {
|
|
|
|
ruleNames = '['
|
|
|
|
ruleNames = '['
|
|
|
|
+ arrays.map(
|
|
|
|
+ ast.rules.map(
|
|
|
|
ast.rules,
|
|
|
|
|
|
|
|
function(r) { return '"' + js.stringEscape(r.name) + '"'; }
|
|
|
|
function(r) { return '"' + js.stringEscape(r.name) + '"'; }
|
|
|
|
).join(', ')
|
|
|
|
).join(', ')
|
|
|
|
+ ']';
|
|
|
|
+ ']';
|
|
|
@ -1267,8 +1261,7 @@ function generateJS(ast, options) {
|
|
|
|
commonjs: function() {
|
|
|
|
commonjs: function() {
|
|
|
|
var parts = [],
|
|
|
|
var parts = [],
|
|
|
|
dependencyVars = objects.keys(options.dependencies),
|
|
|
|
dependencyVars = objects.keys(options.dependencies),
|
|
|
|
requires = arrays.map(
|
|
|
|
requires = dependencyVars.map(
|
|
|
|
dependencyVars,
|
|
|
|
|
|
|
|
function(variable) {
|
|
|
|
function(variable) {
|
|
|
|
return variable
|
|
|
|
return variable
|
|
|
|
+ ' = require("'
|
|
|
|
+ ' = require("'
|
|
|
@ -1303,8 +1296,7 @@ function generateJS(ast, options) {
|
|
|
|
var dependencyIds = objects.values(options.dependencies),
|
|
|
|
var dependencyIds = objects.values(options.dependencies),
|
|
|
|
dependencyVars = objects.keys(options.dependencies),
|
|
|
|
dependencyVars = objects.keys(options.dependencies),
|
|
|
|
dependencies = '['
|
|
|
|
dependencies = '['
|
|
|
|
+ arrays.map(
|
|
|
|
+ dependencyIds.map(
|
|
|
|
dependencyIds,
|
|
|
|
|
|
|
|
function(id) { return '"' + js.stringEscape(id) + '"'; }
|
|
|
|
function(id) { return '"' + js.stringEscape(id) + '"'; }
|
|
|
|
).join(', ')
|
|
|
|
).join(', ')
|
|
|
|
+ ']',
|
|
|
|
+ ']',
|
|
|
@ -1342,13 +1334,11 @@ function generateJS(ast, options) {
|
|
|
|
dependencyIds = objects.values(options.dependencies),
|
|
|
|
dependencyIds = objects.values(options.dependencies),
|
|
|
|
dependencyVars = objects.keys(options.dependencies),
|
|
|
|
dependencyVars = objects.keys(options.dependencies),
|
|
|
|
dependencies = '['
|
|
|
|
dependencies = '['
|
|
|
|
+ arrays.map(
|
|
|
|
+ dependencyIds.map(
|
|
|
|
dependencyIds,
|
|
|
|
|
|
|
|
function(id) { return '"' + js.stringEscape(id) + '"'; }
|
|
|
|
function(id) { return '"' + js.stringEscape(id) + '"'; }
|
|
|
|
).join(', ')
|
|
|
|
).join(', ')
|
|
|
|
+ ']',
|
|
|
|
+ ']',
|
|
|
|
requires = arrays.map(
|
|
|
|
requires = dependencyIds.map(
|
|
|
|
dependencyIds,
|
|
|
|
|
|
|
|
function(id) { return 'require("' + js.stringEscape(id) + '")'; }
|
|
|
|
function(id) { return 'require("' + js.stringEscape(id) + '")'; }
|
|
|
|
).join(', '),
|
|
|
|
).join(', '),
|
|
|
|
params = dependencyVars.join(', ');
|
|
|
|
params = dependencyVars.join(', ');
|
|
|
|