This app provides monitoring and information features for the common freifunk user and the technical stuff of a freifunk community.
Code base is taken from a TUM Practical Course project and added here to see if Freifunk Altdorf can use it.
https://www.freifunk-altdorf.de
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
"use strict"; |
|
|
|
var GrammarError = require("../../grammar-error"), |
|
arrays = require("../../utils/arrays"), |
|
objects = require("../../utils/objects"), |
|
visitor = require("../visitor"); |
|
|
|
/* Checks that each label is defined only once within each scope. */ |
|
function reportDuplicateLabels(ast) { |
|
function checkExpressionWithClonedEnv(node, env) { |
|
check(node.expression, objects.clone(env)); |
|
} |
|
|
|
var check = visitor.build({ |
|
rule: function(node) { |
|
check(node.expression, { }); |
|
}, |
|
|
|
choice: function(node, env) { |
|
arrays.each(node.alternatives, function(alternative) { |
|
check(alternative, objects.clone(env)); |
|
}); |
|
}, |
|
|
|
action: checkExpressionWithClonedEnv, |
|
|
|
labeled: function(node, env) { |
|
if (env.hasOwnProperty(node.label)) { |
|
throw new GrammarError( |
|
"Label \"" + node.label + "\" is already defined " |
|
+ "at line " + env[node.label].start.line + ", " |
|
+ "column " + env[node.label].start.column + ".", |
|
node.location |
|
); |
|
} |
|
|
|
check(node.expression, env); |
|
|
|
env[node.label] = node.location; |
|
}, |
|
|
|
text: checkExpressionWithClonedEnv, |
|
simple_and: checkExpressionWithClonedEnv, |
|
simple_not: checkExpressionWithClonedEnv, |
|
optional: checkExpressionWithClonedEnv, |
|
zero_or_more: checkExpressionWithClonedEnv, |
|
one_or_more: checkExpressionWithClonedEnv, |
|
group: checkExpressionWithClonedEnv |
|
}); |
|
|
|
check(ast); |
|
} |
|
|
|
module.exports = reportDuplicateLabels;
|
|
|