forked from akvelon/flutter-code-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolang_syntax.dart
46 lines (43 loc) · 1.5 KB
/
golang_syntax.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Search for syntax errors for java and dart : for loop errors
Including comments, strings. */
Map<int, String> findGolangErrors(String text) {
List<String> lines = text.split("\n");
Map<int, String> errors = {};
for (int i = 0; i < lines.length; i++) {
if (lines[i].trim().isEmpty || lines[i].startsWith(RegExp("\\s*//"))) {
continue;
}
if (lines[i].startsWith(RegExp("\\s*/\\*"))) {
while (
(!lines[i].contains(RegExp("\\*/\\s*"))) && (i < lines.length - 1)) {
i++;
}
} else if (lines[i].startsWith(RegExp(".*`"))) {
do {
i++;
} while ((!lines[i].contains(RegExp("`"))) && (i < lines.length - 1));
}
// error in for construct
if (lines[i].contains(RegExp("\\s*for\\s+")) &&
(!lines[i].contains(RegExp("[\"']\\s*for\\s+[\"']"))) &&
(!lines[i].contains(RegExp("//\\s*for\\s+")))) {
String commandFor = "";
while ((!lines[i].contains(RegExp("{")) ||
(lines[i].contains(RegExp("[\"'].*{.*[\"']"))) ||
(lines[i].contains(RegExp("//.*{")))) &&
(i < lines.length - 1)) {
commandFor += lines[i];
i++;
lines[i] = lines[i];
}
commandFor += lines[i];
if (commandFor.contains(RegExp("for.*:=")) &&
commandFor.contains(RegExp("for.*[\+-][\+-]"))) {
if (!commandFor.contains(RegExp("for.*:=.*;.*;.*[\+-][\+-]"))) {
errors.addAll({(i + 1): "Incorrect for statement"});
}
}
}
}
return errors;
}