Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parts.push("function peg$parse" + rule.name + "(): " + outputType +" {");
if (options.trace) {
parts.push(" const startPos = peg$currPos;");
}
for (let i = 0; i <= stack.maxSp; i++) {
stackVars[i] = s(i);
}
parts.push(" let " + stackVars.join(", ") + ";");
parts.push(indent2(generateRuleHeader(
"\"" + js.stringEscape(rule.name) + "\"",
asts.indexOfRule(ast, rule.name)
)));
parts.push(indent2(code));
parts.push(indent2(generateRuleFooter(
"\"" + js.stringEscape(rule.name) + "\"",
s(0)
)));
parts.push("}");
return parts.join("\n");
}
rule_ref(node) {
return [op.RULE, asts.indexOfRule(ast, node.name)];
},
r => r + ": " + asts.indexOfRule(ast, r)
).join(", ") +
parts.push([
"function peg$parse(input: string, options?: IParseOptions) {",
" options = options !== undefined ? options : {};",
"",
" const peg$FAILED: Readonly<{}> = {};",
""
].join("\n"));
if (options.optimize === "size") {
let startRuleIndices = "{ " +
options.allowedStartRules.map(
r => r + ": " + asts.indexOfRule(ast, r)
).join(", ") +
" }";
let startRuleIndex = asts.indexOfRule(ast, options.allowedStartRules[0]);
parts.push([
" const peg$startRuleIndices: {[id: string]: number} = " + startRuleIndices + ";",
" let peg$startRuleIndex = " + startRuleIndex + ";"
].join("\n"));
} else {
let startRuleFunctions = "{ " +
options.allowedStartRules.map(
r => r + ": peg$parse" + r
).join(", ") +
" }";
let startRuleFunction = "peg$parse" + options.allowedStartRules[0];
parts.push([
" const peg$startRuleFunctions: {[id: string]: any} = " + startRuleFunctions + ";",
" let peg$startRuleFunction: () => any = " + startRuleFunction + ";"