|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
let arrays = require("../../utils/arrays"),
|
|
|
|
|
objects = require("../../utils/objects"),
|
|
|
|
|
let objects = require("../../utils/objects"),
|
|
|
|
|
asts = require("../asts"),
|
|
|
|
|
op = require("../opcodes"),
|
|
|
|
|
js = require("../js");
|
|
|
|
@ -408,7 +407,9 @@ function generateJS(ast, options) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateRuleFunction(rule) {
|
|
|
|
|
let parts = [], code;
|
|
|
|
|
let parts = [],
|
|
|
|
|
stackVars = [],
|
|
|
|
|
code;
|
|
|
|
|
|
|
|
|
|
function c(i) { return "peg$c" + i; } // |consts[i]| of the abstract machine
|
|
|
|
|
function s(i) { return "s" + i; } // |stack[i]| of the abstract machine
|
|
|
|
@ -429,7 +430,12 @@ function generateJS(ast, options) {
|
|
|
|
|
if (n === undefined) {
|
|
|
|
|
return s(this.sp--);
|
|
|
|
|
} else {
|
|
|
|
|
let values = arrays.range(this.sp - n + 1, this.sp + 1).map(s);
|
|
|
|
|
let values = Array(n);
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
|
|
|
values[i] = s(this.sp - n + 1 + i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.sp -= n;
|
|
|
|
|
|
|
|
|
|
return values;
|
|
|
|
@ -714,14 +720,18 @@ function generateJS(ast, options) {
|
|
|
|
|
|
|
|
|
|
parts.push('function peg$parse' + rule.name + '() {');
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i <= stack.maxSp; i++) {
|
|
|
|
|
stackVars[i] = s(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.trace) {
|
|
|
|
|
parts.push([
|
|
|
|
|
' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ',',
|
|
|
|
|
' var ' + stackVars.join(', ') + ',',
|
|
|
|
|
' startPos = peg$currPos;'
|
|
|
|
|
].join('\n'));
|
|
|
|
|
} else {
|
|
|
|
|
parts.push(
|
|
|
|
|
' var ' + arrays.range(0, stack.maxSp + 1).map(s).join(', ') + ';'
|
|
|
|
|
' var ' + stackVars.join(', ') + ';'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|