|
|
|
@ -718,20 +718,15 @@ function generateJS(ast, options) {
|
|
|
|
|
|
|
|
|
|
parts.push('function peg$parse' + rule.name + '() {');
|
|
|
|
|
|
|
|
|
|
if (options.trace) {
|
|
|
|
|
parts.push(' var startPos = peg$currPos;');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i <= stack.maxSp; i++) {
|
|
|
|
|
stackVars[i] = s(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.trace) {
|
|
|
|
|
parts.push([
|
|
|
|
|
' var ' + stackVars.join(', ') + ',',
|
|
|
|
|
' startPos = peg$currPos;'
|
|
|
|
|
].join('\n'));
|
|
|
|
|
} else {
|
|
|
|
|
parts.push(
|
|
|
|
|
' var ' + stackVars.join(', ') + ';'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
parts.push(' var ' + stackVars.join(', ') + ';');
|
|
|
|
|
|
|
|
|
|
parts.push(indent2(generateRuleHeader(
|
|
|
|
|
'"' + js.stringEscape(rule.name) + '"',
|
|
|
|
@ -1248,12 +1243,6 @@ function generateJS(ast, options) {
|
|
|
|
|
commonjs: function() {
|
|
|
|
|
let parts = [];
|
|
|
|
|
let dependencyVars = Object.keys(options.dependencies);
|
|
|
|
|
let requires = dependencyVars.map(
|
|
|
|
|
variable => variable
|
|
|
|
|
+ ' = require("'
|
|
|
|
|
+ js.stringEscape(options.dependencies[variable])
|
|
|
|
|
+ '")'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
parts.push([
|
|
|
|
|
generateGeneratedByComment(),
|
|
|
|
@ -1262,8 +1251,14 @@ function generateJS(ast, options) {
|
|
|
|
|
''
|
|
|
|
|
].join('\n'));
|
|
|
|
|
|
|
|
|
|
if (requires.length > 0) {
|
|
|
|
|
parts.push('var ' + requires.join(', ') + ';');
|
|
|
|
|
if (dependencyVars.length > 0) {
|
|
|
|
|
dependencyVars.forEach(variable => {
|
|
|
|
|
parts.push('var ' + variable
|
|
|
|
|
+ ' = require("'
|
|
|
|
|
+ js.stringEscape(options.dependencies[variable])
|
|
|
|
|
+ '");'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
parts.push('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|