Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
literal(node) {
if (node.value.length > 0) {
let stringIndex = addConst("\""
+ js.stringEscape(
node.ignoreCase ? node.value.toLowerCase() : node.value
)
+ "\""
);
let expectedIndex = addConst(
"peg$literalExpectation("
+ "\"" + js.stringEscape(node.value) + "\", "
+ node.ignoreCase
+ ")"
);
// For case-sensitive strings the value must match the beginning of the
// remaining input exactly. As a result, we can use |ACCEPT_STRING| and
// save one |substr| call that would be needed if we used |ACCEPT_N|.
return buildCondition(
node.ignoreCase
? [op.MATCH_STRING_IC, stringIndex]
: [op.MATCH_STRING, stringIndex],
node.ignoreCase
? [op.ACCEPT_N, node.value.length]
: [op.ACCEPT_STRING, stringIndex],
[op.FAIL, expectedIndex]
);
literal(node) {
if (node.value.length > 0) {
let stringIndex = addConst("\""
+ js.stringEscape(
node.ignoreCase ? node.value.toLowerCase() : node.value
)
+ "\""
);
let expectedIndex = addConst(
"peg$literalExpectation("
+ "\"" + js.stringEscape(node.value) + "\", "
+ node.ignoreCase
+ ")"
);
// For case-sensitive strings the value must match the beginning of the
// remaining input exactly. As a result, we can use |ACCEPT_STRING| and
// save one |substr| call that would be needed if we used |ACCEPT_N|.
return buildCondition(
node.ignoreCase
named(node, context) {
let nameIndex = addConst(
"peg$otherExpectation(\"" + js.stringEscape(node.name) + "\")"
);
// The code generated below is slightly suboptimal because |FAIL| pushes
// to the stack, so we need to stick a |POP| in front of it. We lack a
// dedicated instruction that would just report the failure and not touch
// the stack.
return buildSequence(
[op.SILENT_FAILS_ON],
generate(node.expression, context),
[op.SILENT_FAILS_OFF],
buildCondition([op.IF_ERROR], [op.FAIL, nameIndex], [])
);
},
r => "\"" + js.stringEscape(r.name) + "\""
).join(", ") +
id => "require(\"" + js.stringEscape(id) + "\")"
).join(", ");
+ node.parts.map(part =>
Array.isArray(part)
? "[\"" + js.stringEscape(part[0]) + "\", \"" + js.stringEscape(part[1]) + "\"]"
: "\"" + js.stringEscape(part) + "\""
).join(", ")
options.returnTypes[rule.name] : "any";
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");
}
+ node.parts.map(part =>
Array.isArray(part)
? "[\"" + js.stringEscape(part[0]) + "\", \"" + js.stringEscape(part[1]) + "\"]"
: "\"" + js.stringEscape(part) + "\""
).join(", ")
dependencyVars.forEach(variable => {
parts.push("let " + variable +
" = require(\"" +
js.stringEscape(options.dependencies[variable]) +
"\");"
);
});
parts.push("");
indent2(ast.rules.map(rule =>
"peg$decode(\"" +
js.stringEscape(rule.bytecode.map(
b => String.fromCharCode(b + 32)
).join("")) +
"\")"
).join(",\n")),