syntax error checking and template matches
This commit is contained in:
@@ -1,3 +1,75 @@
|
||||
var syntaxErrors = function(code) {
|
||||
// trivial check of bracket curlyCount
|
||||
// should be file specific in the future
|
||||
// and understand the syntax of config file
|
||||
|
||||
var normalCount = 0;
|
||||
var squareCount = 0;
|
||||
var curlyCount = 0;
|
||||
|
||||
for (var i = 0, len = code.length; i < len; i++) {
|
||||
if (code[i] === '(') {
|
||||
normalCount++;
|
||||
}
|
||||
if (code[i] === ')') {
|
||||
normalCount--;
|
||||
}
|
||||
|
||||
if (code[i] === '[') {
|
||||
squareCount++;
|
||||
}
|
||||
if (code[i] === ']') {
|
||||
squareCount--;
|
||||
}
|
||||
|
||||
if (code[i] === '{') {
|
||||
curlyCount++;
|
||||
}
|
||||
if (code[i] === '}') {
|
||||
curlyCount--;
|
||||
}
|
||||
}
|
||||
var result = [];
|
||||
if (curlyCount > 0) {
|
||||
result.push("Missing a closing curly bracket }");
|
||||
}
|
||||
if (squareCount > 0) {
|
||||
result.push("Missing a closing square bracket ]");
|
||||
}
|
||||
if (normalCount > 0) {
|
||||
result.push("Missing a closing bracket )");
|
||||
}
|
||||
|
||||
if (curlyCount < 0) {
|
||||
result.push("You have more closing curly brackets than needed }");
|
||||
}
|
||||
if (squareCount < 0) {
|
||||
result.push("You have more closing square brackets than needed ]");
|
||||
}
|
||||
if (normalCount < 0) {
|
||||
result.push("You have more closing brackets than needed )");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var unfilledVariables = function(code) {
|
||||
var result = [];
|
||||
var lines = code.split("\n");
|
||||
for (var i = 0, len = lines.length; i < len; i++) {
|
||||
var lineNumber = '' + (i + 1);
|
||||
var line = lines[i];
|
||||
var matches = line.match(/::.*::/gi)
|
||||
if(!matches) { continue; };
|
||||
for (var j=0, lenMatches = matches.length; j < lenMatches ; j++) {
|
||||
var match = matches[j];
|
||||
result.push("Line " + lineNumber + " - " + match);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
var editor = ace.edit("editor");
|
||||
//editor.setTheme("ace/theme/monokai");
|
||||
@@ -5,6 +77,33 @@ $(document).ready(function() {
|
||||
editor.setOptions({
|
||||
maxLines: 40
|
||||
});
|
||||
|
||||
var onEditorChange = function(e) {
|
||||
value = editor.getValue();
|
||||
var errors = syntaxErrors(value);
|
||||
var message = errors.map(function(error) {
|
||||
return '<li>' + error + '</li>';
|
||||
}).join("");
|
||||
if (message === "") {
|
||||
message = " No errors! Everything is awesome!"
|
||||
}
|
||||
$("#syntax_errors").html(message);
|
||||
|
||||
var variables = unfilledVariables(value);
|
||||
var variableMessages = variables.map(function(variable) {
|
||||
return '<li>' + variable + '</li>';
|
||||
}).join("");
|
||||
if (variableMessages === "") {
|
||||
|
||||
variableMessages = "Everything is filled out!"
|
||||
}
|
||||
|
||||
$("#unfilled_variables").html(variableMessages);
|
||||
};
|
||||
|
||||
editor.on("change", onEditorChange );
|
||||
onEditorChange();
|
||||
|
||||
editor.resize();
|
||||
|
||||
$("#save_button").click(function() {
|
||||
|
||||
Reference in New Issue
Block a user