-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.dart
90 lines (88 loc) · 3.04 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import "package:mammouth/src/basic/source.dart";
import "package:mammouth/src/diagnostic/diagnosticEngine.dart"
show DiagnosticEngine;
import "package:mammouth/src/diagnostic/error.dart";
import "package:mammouth/src/language/common/ast/ast.dart" as common;
import "package:mammouth/src/language/common/ast/token.dart"
show TokenKind, Token;
import "package:mammouth/src/language/php/version.dart";
import "package:mammouth/src/platform/vm/fileSystem.dart";
import "package:mammouth/src/platform/vm/session.dart";
import "package:mammouth/src/syntactic/lexer.dart";
import "package:mammouth/src/syntactic/parser.dart";
import "package:mammouth/src/semantic/parentResolver.dart";
import "package:mammouth/src/semantic/elementBuilder.dart";
import "package:mammouth/src/semantic/typeChecker.dart";
import "package:mammouth/src/codegen/codegen.dart";
import "package:mammouth/src/codegen/docgen.dart";
import "package:mammouth/src/codegen/resolver.dart";
/**
(1)
* TODO: argument, parameter, loop variable by reference
* TODO: fix echo in while expression between
* TODO: Check visibility on implements
* TODO: more if and while as statement with expression
* TODO: add () when needed example "new RGB->__mmt_converter_i()"
(2)
* TODO: ?.
* TODO: heredoc/multiline String
* TODO: generate .. ? .. : .. for if with just expression
* TODO: range with step, also in slice
* TODO: Test slicing more and more
* TODO: clone
* TODO: native statement
* TODO: inline method must not have access to protected and private data / call the non-inlined version
* TODO: improve visibility
* TODO: Unused main method Converter
*/
String code = r"""
{{
echo "mammouth"
class RGB<T>
T p
int get l ->
this.p
RGB<int> k = new RGB<int>()
k.l
}}
""";
void main() {
Source bisource = new VMSource("./sdk/core.mammouth");
Source source = new BasicSource(code);
DiagnosticEngine de = new DiagnosticEngine();
Lexer lexer = new Lexer(de);
lexer.setInput(source);
Token token = lexer.scanAll();
while(token != null) {
print("${token.kind.name}${token.kind != TokenKind.LINE_FEED &&
token.lexeme != null ? '[' + token.lexeme + ']' : ''}");
token = token.next;
}
de.get(source).forEach((AnalysisError error) {
print(error.message);
print(error.offset);
});
Parser parser = new Parser(de);
parser.setInput(source, lexer.scanAll());
common.Document document = parser
.parseDocument()
.some;
print(document);
VMSession session = new VMSession()..target = new Version(5,3,0);
TypeChecker tc = new TypeChecker(bisource, session, de);
//
lexer.setInput(bisource);
parser.setInput(bisource, lexer.scanAll());
common.Document bidocument = parser
.parseDocument()
.some;
bidocument.accept(new ElementBuilder());
bidocument.accept(tc);
//
tc.setSource(source);
document.accept(new ParentResolver());
document.accept(new ElementBuilder());
document.accept(tc);
print((document.accept(new CodeGenerator(session, source)) as common.Document).accept(
new PHPResultResolver()).accept(new DocumentGenerator()));
}