Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rulesSource += tab + 'var ' + name + ' = null;\n';
seen.add(name);
}
};
// Collect all the code blocks in the AST.
var dumpCode = function(node) {
if (node.code) {
// remove trailing whitespace for single-line predicates
var code = node.code.replace(/[ \t]+$/, '');
// wrap with a function, to prevent spurious errors caused
// by redeclarations or multiple returns in a block.
rulesSource += tab + '(function() {\n' + code + '\n' +
tab + '})();\n';
}
};
var visit = visitor.build({
initializer: function(node) {
if (node.code) {
rulesSource += node.code + '\n';
}
},
semantic_and: dumpCode,
semantic_node: dumpCode,
rule: function(node) {
rulesSource += 'function rule_' + node.name + '() {\n';
seen.clear();
visit(node.expression);
rulesSource += '}\n';
},
labeled: function(node) {
addVar(node.label);
visit(node.expression);
function generateCallgraph(opts) {
var file = getOutputStream(opts);
var tokenizer = new PegTokenizer();
var pegOpts = { php: opts.php };
var ast = tokenizer.parseTokenizer(pegOpts);
var visitor = require('wikipeg/lib/compiler/visitor');
var edges = [];
var currentRuleName;
var visit = visitor.build({
rule: function(node) {
currentRuleName = node.name;
visit(node.expression);
},
rule_ref: function(node) {
var edge = "\t" + currentRuleName + " -> " + node.name + ";";
if (edges.indexOf(edge) === -1) {
edges.push(edge);
}
}
});
visit(ast);
var dot = "digraph {\n" +
function listOrphans(opts) {
var file = getOutputStream(opts);
var tokenizer = new PegTokenizer();
var pegOpts = { php: opts.php };
var ast = tokenizer.parseTokenizer(pegOpts);
var visitor = require('wikipeg/lib/compiler/visitor');
var rules = {};
visitor.build({
rule: function(node) {
rules[node.name] = true;
},
})(ast);
visitor.build({
rule_ref: function(node) {
delete rules[node.name];
},
})(ast);
file.write(Object.getOwnPropertyNames(rules).join('\n') + '\n');
}