Skip to content

Commit f1255af

Browse files
authored
Merge pull request #5 from WyattSL/experimental
experimental
2 parents 223e969 + 41c8ecd commit f1255af

File tree

4 files changed

+130
-3
lines changed

4 files changed

+130
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.6.0
2+
- Introduced support for error checking, will currently check for disallowed functions inside encryption/decryption. Will be expanded in future releases.
3+
14
## 1.4.2
25
- Visual Studio Code will now auto-indent as you type.
36

@@ -64,4 +67,4 @@
6467

6568
## 1.0.1
6669
- Introduction of autocompletion.
67-
- Minor bug fixes.
70+
- Minor bug fixes.

ecomp.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
const NormVarReg = new RegExp(`^\s*([^'"\s]+)\s?=\s?(.*)$`)
2+
const TabVarReg = new RegExp(`^\s*([^'"\s]+)(\[.*\])+\s?=\s?(.*)$`);
3+
const FunctionReg = new RegExp(`^function(\([a-zA-Z0-9_]+((,\s?[a-zA-Z0-9_]+)*)\))?$`);
4+
const IfReg = new RegExp(`^\s*if (.*) then`);
5+
const ElseIfReg = new RegExp(`^\s*else if (.*) then`);
6+
const ElseReg = new RegExp(`^\s*else`);
7+
const WhileReg = new RegExp(`^\s*while (.*)`);
8+
const ForReg = new RegExp(`^\s*for [a-zA-Z0-9_]+ in .*`);
9+
const EndReg = new RegExp(`^\s*end (if|for|while|function)`);
10+
const Break = new RegExp(`^\s*break$`);
11+
const Continue = new RegExp(`^\s*continue$`);
12+
13+
exports.run = (src) => {
14+
let errors = [];
15+
let warns = []
16+
let lines = src.split("\n");
17+
let line;
18+
let nested = []
19+
for (line of lines) {
20+
let lt;
21+
if (line.test(NormVarReg)) lt = "AssignVarNorm";
22+
if (line.test(TabVarReg)) lt = "AssignVarTable";
23+
if (line.test(IfReg)) lt = "If";
24+
if (line.test(ElseIfReg)) lt = "ElseIf"
25+
if (line.test(ElseReg)) lt = "Else";
26+
if (line.test(WhileReg)) lt = "While";
27+
if (line.test(ForReg)) lt = "For";
28+
if (line.test(EndReg)) lt = "End";
29+
if (line.test(BreakReg)) lt = "Break";
30+
if (line.test(ContinueReg)) lt = "Continue"
31+
32+
let nt = nested[nested.length-1];
33+
34+
if (lt == "Break" || lt == "Continue") {
35+
if (nt != "while" && nt != "for") errors.push({line: line, text: `${lt} Statement outside of loop loop`});
36+
}
37+
if (lt.includes("AssignVar")) {
38+
let d;
39+
if (lt == "AssignVarNorm") {
40+
d = line.match(NormVarReg)[1];
41+
} else {
42+
d = line.match(TabVarReg)[2];
43+
}
44+
if (line.includes("func") && !line.test(FunctionReg)) {
45+
errors.push({line: line, text: "Function declaration invalid"});
46+
}
47+
}
48+
if (lt == "If") {
49+
nested.push("if") //TODO check conditional
50+
}
51+
if (lt == "ElseIf") {
52+
if (nested[nested.length-1] == "if") {
53+
//TODO check conditional
54+
} else {
55+
errors.push({line: line, text: "ElseIf outside of If statement"});
56+
}
57+
}
58+
if (lt == "Else") {
59+
if (nested[nested.length-1] == "if") {
60+
//TODO check conditional
61+
} else {
62+
errors.push({line: line, text: "Else outside of If statement"});
63+
}
64+
}
65+
if (lt == "While") {
66+
nested.push("while")
67+
//TODO check conditional
68+
}
69+
if (lt == "For") nested.push("for");
70+
if (lt == "End") {
71+
let g = line.match(EndReg);
72+
let nt = nested[nested.length-1]
73+
if (nt == g[0]) { nested.pop } else {
74+
errors.push({line: line, text: "End Statement '"+g[0]+" found, expected End Statement '"+nt+"'"});
75+
}
76+
}
77+
}
78+
};

extension.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,57 @@ function activate(context) {
143143
});
144144

145145
if (vscode.workspace.getConfiguration("greyscript").get("autocomplete")) context.subscriptions.push(compD)
146+
147+
function LookForErrors(source) {
148+
console.log("Looking for errors")
149+
let outp = [];
150+
let reg = new RegExp(`(Encode|Decode)(?:\\s)?=(?:\\s)?function\\(.+\\).*(${Encryption.join("|")}).*end function`, "s");
151+
let m = source.match(reg);
152+
console.log("Match "+m)
153+
if (m) {
154+
let match = m;
155+
console.log("Match m "+match);
156+
let s = source.indexOf(match[2]);
157+
let e = source.indexOf(match[2])+match[2].length;
158+
let li = source.slice(0, s).split("/n").length;
159+
let eli = source.slice(e, source.length).split("/n").length;
160+
let max = source.slice(0, s);
161+
let max2 = source.slice(0, e);
162+
let sch = max.slice(max.lastIndexOf("/n"), max.indexOf(match[2])).length;
163+
let ech = max2.slice(max2.lastIndexOf("/n"), max2.indexOf(match[2])+match[2].length).length;
164+
let r = new vscode.Range(li, 1, eli, 99999)
165+
let ms = "Cannot use "+match[2]+" in "+ (match[1] == "Encode" ? "encryption." : "decryption.");
166+
let d = new vscode.Diagnostic(r, ms, vscode.DiagnosticSeverity.Error);
167+
outp.push(d);
168+
}
169+
console.log(outp.length+" errors found")
170+
return outp;
171+
}
172+
173+
let collection = vscode.languages.createDiagnosticCollection("greyscript");
174+
175+
176+
function readerror(document) {
177+
console.log("Reading Errors")
178+
let uri = document.uri;
179+
//collection.clear();
180+
console.log("Sniffing errors on "+uri)
181+
let e = LookForErrors(document.getText());
182+
console.log("Found Errors "+e.length)
183+
collection.set(uri, e);
184+
}
185+
let listen1 = vscode.workspace.onDidOpenTextDocument( readerror);
186+
let listen2 = vscode.workspace.onDidChangeTextDocument(function(event) {
187+
console.log("Doc Changed")
188+
readerror(event.document);
189+
});
190+
console.log("Hello Hackers!")
191+
context.subscriptions.push(collection, listen1, listen2);
146192

147193
let gecmd = vscode.commands.registerTextEditorCommand("greyScript.gotoError", (editor, edit, context) => {
148194
let options = {"prompt": "Enter provided line number"}
149195
vscode.window.showInputBox(options).then((line) => {
150-
line = Number(line)
196+
line = Number(line);
151197
//debug.appendLine("line: "+line)
152198
var text = editor.document.getText();
153199
var exp = new RegExp("else","gm")

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"email": "wyattlipscomb20@gmail.com",
99
"url": "https://github.com/WyattSL"
1010
},
11-
"version": "1.5.0",
11+
"version": "1.6.0",
1212
"repository": {
1313
"type": "git",
1414
"url": "https://github.com/WyattSL/greyscript.git"

0 commit comments

Comments
 (0)