Skip to content

Commit

Permalink
Merge pull request #5 from WyattSL/experimental
Browse files Browse the repository at this point in the history
experimental
  • Loading branch information
WyattSL authored Oct 21, 2021
2 parents 223e969 + 41c8ecd commit f1255af
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.6.0
- Introduced support for error checking, will currently check for disallowed functions inside encryption/decryption. Will be expanded in future releases.

## 1.4.2
- Visual Studio Code will now auto-indent as you type.

Expand Down Expand Up @@ -64,4 +67,4 @@

## 1.0.1
- Introduction of autocompletion.
- Minor bug fixes.
- Minor bug fixes.
78 changes: 78 additions & 0 deletions ecomp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const NormVarReg = new RegExp(`^\s*([^'"\s]+)\s?=\s?(.*)$`)
const TabVarReg = new RegExp(`^\s*([^'"\s]+)(\[.*\])+\s?=\s?(.*)$`);
const FunctionReg = new RegExp(`^function(\([a-zA-Z0-9_]+((,\s?[a-zA-Z0-9_]+)*)\))?$`);
const IfReg = new RegExp(`^\s*if (.*) then`);
const ElseIfReg = new RegExp(`^\s*else if (.*) then`);
const ElseReg = new RegExp(`^\s*else`);
const WhileReg = new RegExp(`^\s*while (.*)`);
const ForReg = new RegExp(`^\s*for [a-zA-Z0-9_]+ in .*`);
const EndReg = new RegExp(`^\s*end (if|for|while|function)`);
const Break = new RegExp(`^\s*break$`);
const Continue = new RegExp(`^\s*continue$`);

exports.run = (src) => {
let errors = [];
let warns = []
let lines = src.split("\n");
let line;
let nested = []
for (line of lines) {
let lt;
if (line.test(NormVarReg)) lt = "AssignVarNorm";
if (line.test(TabVarReg)) lt = "AssignVarTable";
if (line.test(IfReg)) lt = "If";
if (line.test(ElseIfReg)) lt = "ElseIf"
if (line.test(ElseReg)) lt = "Else";
if (line.test(WhileReg)) lt = "While";
if (line.test(ForReg)) lt = "For";
if (line.test(EndReg)) lt = "End";
if (line.test(BreakReg)) lt = "Break";
if (line.test(ContinueReg)) lt = "Continue"

let nt = nested[nested.length-1];

if (lt == "Break" || lt == "Continue") {
if (nt != "while" && nt != "for") errors.push({line: line, text: `${lt} Statement outside of loop loop`});
}
if (lt.includes("AssignVar")) {
let d;
if (lt == "AssignVarNorm") {
d = line.match(NormVarReg)[1];
} else {
d = line.match(TabVarReg)[2];
}
if (line.includes("func") && !line.test(FunctionReg)) {
errors.push({line: line, text: "Function declaration invalid"});
}
}
if (lt == "If") {
nested.push("if") //TODO check conditional
}
if (lt == "ElseIf") {
if (nested[nested.length-1] == "if") {
//TODO check conditional
} else {
errors.push({line: line, text: "ElseIf outside of If statement"});
}
}
if (lt == "Else") {
if (nested[nested.length-1] == "if") {
//TODO check conditional
} else {
errors.push({line: line, text: "Else outside of If statement"});
}
}
if (lt == "While") {
nested.push("while")
//TODO check conditional
}
if (lt == "For") nested.push("for");
if (lt == "End") {
let g = line.match(EndReg);
let nt = nested[nested.length-1]
if (nt == g[0]) { nested.pop } else {
errors.push({line: line, text: "End Statement '"+g[0]+" found, expected End Statement '"+nt+"'"});
}
}
}
};
48 changes: 47 additions & 1 deletion extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,57 @@ function activate(context) {
});

if (vscode.workspace.getConfiguration("greyscript").get("autocomplete")) context.subscriptions.push(compD)

function LookForErrors(source) {
console.log("Looking for errors")
let outp = [];
let reg = new RegExp(`(Encode|Decode)(?:\\s)?=(?:\\s)?function\\(.+\\).*(${Encryption.join("|")}).*end function`, "s");
let m = source.match(reg);
console.log("Match "+m)
if (m) {
let match = m;
console.log("Match m "+match);
let s = source.indexOf(match[2]);
let e = source.indexOf(match[2])+match[2].length;
let li = source.slice(0, s).split("/n").length;
let eli = source.slice(e, source.length).split("/n").length;
let max = source.slice(0, s);
let max2 = source.slice(0, e);
let sch = max.slice(max.lastIndexOf("/n"), max.indexOf(match[2])).length;
let ech = max2.slice(max2.lastIndexOf("/n"), max2.indexOf(match[2])+match[2].length).length;
let r = new vscode.Range(li, 1, eli, 99999)
let ms = "Cannot use "+match[2]+" in "+ (match[1] == "Encode" ? "encryption." : "decryption.");
let d = new vscode.Diagnostic(r, ms, vscode.DiagnosticSeverity.Error);
outp.push(d);
}
console.log(outp.length+" errors found")
return outp;
}

let collection = vscode.languages.createDiagnosticCollection("greyscript");


function readerror(document) {
console.log("Reading Errors")
let uri = document.uri;
//collection.clear();
console.log("Sniffing errors on "+uri)
let e = LookForErrors(document.getText());
console.log("Found Errors "+e.length)
collection.set(uri, e);
}
let listen1 = vscode.workspace.onDidOpenTextDocument( readerror);
let listen2 = vscode.workspace.onDidChangeTextDocument(function(event) {
console.log("Doc Changed")
readerror(event.document);
});
console.log("Hello Hackers!")
context.subscriptions.push(collection, listen1, listen2);

let gecmd = vscode.commands.registerTextEditorCommand("greyScript.gotoError", (editor, edit, context) => {
let options = {"prompt": "Enter provided line number"}
vscode.window.showInputBox(options).then((line) => {
line = Number(line)
line = Number(line);
//debug.appendLine("line: "+line)
var text = editor.document.getText();
var exp = new RegExp("else","gm")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"email": "wyattlipscomb20@gmail.com",
"url": "https://github.com/WyattSL"
},
"version": "1.5.0",
"version": "1.6.0",
"repository": {
"type": "git",
"url": "https://github.com/WyattSL/greyscript.git"
Expand Down

0 comments on commit f1255af

Please sign in to comment.