-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.dart
62 lines (46 loc) · 1.06 KB
/
code.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Code {
// collects all the imports
List<String> imports = [];
//
List<String> functions = [];
//
List<String> statements = [];
// stores all the lines imported so far
List<String> lines = [];
// generate code
String text;
//
bool insideFunction = false;
Code() {
this.imports.add("import 'dart:io'");
}
/**
*
*/
bool analyzeLine(String line) {
lines.add(line);
if(line.startsWith('import ')) {
this.imports.add(line);
return true;
} else if (line.isNotEmpty) {
this.statements.add(line);
return this.insideFunction;
}
return true;
}
/**
*
*/
String generateText() {
// convert imports to text
String importsText = '';
this.imports.forEach((importLine) => importsText += importLine + ';\n');
String statementsText = '';
this.statements.forEach((statementLine) => statementsText += '\t' + statementLine + ';\n');
this.text = importsText +
"\nmain() async {\n\t" +
statementsText +
"\n}\n";
return this.text;
}
}