|
|
|
@ -428,12 +428,10 @@ function generateJS(ast, options) {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
pop: function(n) {
|
|
|
|
|
let values;
|
|
|
|
|
|
|
|
|
|
if (n === undefined) {
|
|
|
|
|
return s(this.sp--);
|
|
|
|
|
} else {
|
|
|
|
|
values = arrays.range(this.sp - n + 1, this.sp + 1).map(s);
|
|
|
|
|
let values = arrays.range(this.sp - n + 1, this.sp + 1).map(s);
|
|
|
|
|
this.sp -= n;
|
|
|
|
|
|
|
|
|
|
return values;
|
|
|
|
@ -745,10 +743,7 @@ function generateJS(ast, options) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateToplevel() {
|
|
|
|
|
let parts = [],
|
|
|
|
|
startRuleIndices, startRuleIndex,
|
|
|
|
|
startRuleFunctions, startRuleFunction,
|
|
|
|
|
ruleNames;
|
|
|
|
|
let parts = [];
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
'function peg$subclass(child, parent) {',
|
|
|
|
@ -940,24 +935,24 @@ function generateJS(ast, options) {
|
|
|
|
|
].join('\n'));
|
|
|
|
|
|
|
|
|
|
if (options.optimize === "size") {
|
|
|
|
|
startRuleIndices = '{ '
|
|
|
|
|
let startRuleIndices = '{ '
|
|
|
|
|
+ options.allowedStartRules.map(
|
|
|
|
|
function(r) { return r + ': ' + asts.indexOfRule(ast, r); }
|
|
|
|
|
).join(', ')
|
|
|
|
|
+ ' }';
|
|
|
|
|
startRuleIndex = asts.indexOfRule(ast, options.allowedStartRules[0]);
|
|
|
|
|
let startRuleIndex = asts.indexOfRule(ast, options.allowedStartRules[0]);
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
' peg$startRuleIndices = ' + startRuleIndices + ',',
|
|
|
|
|
' peg$startRuleIndex = ' + startRuleIndex + ','
|
|
|
|
|
].join('\n'));
|
|
|
|
|
} else {
|
|
|
|
|
startRuleFunctions = '{ '
|
|
|
|
|
let startRuleFunctions = '{ '
|
|
|
|
|
+ options.allowedStartRules.map(
|
|
|
|
|
function(r) { return r + ': peg$parse' + r; }
|
|
|
|
|
).join(', ')
|
|
|
|
|
+ ' }';
|
|
|
|
|
startRuleFunction = 'peg$parse' + options.allowedStartRules[0];
|
|
|
|
|
let startRuleFunction = 'peg$parse' + options.allowedStartRules[0];
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
' peg$startRuleFunctions = ' + startRuleFunctions + ',',
|
|
|
|
@ -989,7 +984,7 @@ function generateJS(ast, options) {
|
|
|
|
|
|
|
|
|
|
if (options.trace) {
|
|
|
|
|
if (options.optimize === "size") {
|
|
|
|
|
ruleNames = '['
|
|
|
|
|
let ruleNames = '['
|
|
|
|
|
+ ast.rules.map(
|
|
|
|
|
function(r) { return '"' + js.stringEscape(r.name) + '"'; }
|
|
|
|
|
).join(', ')
|
|
|
|
|