1 module checker
is aliced
;
6 void loadScript (string name
, bool warnings
=false) {
7 import std
.algorithm
: startsWith
;
8 import std
.file
: readText
;
9 import std
.path
: baseName
, extension
;
11 import std
.string
: replace
;
14 auto s
= readText(name
);
15 s
= s
.replace("\r\n", "\n").replace("\r", "\n");
16 if (s
.startsWith("<?xml")) {
17 import std
.string
: indexOf
;
18 auto pos
= s
.indexOf(`<argument kind="STRING">`);
19 if (pos
< 0) assert(0, "wtf?!");
21 pos
= s
.indexOf(`</argument>`);
22 if (pos
< 0) assert(0, "wtfx?!");
27 auto lex
= new Lexer(s
, name
);
29 auto parser
= new Parser(lex
);
30 parser
.strict
= false;
31 parser
.warnings
= warnings
;
32 bool asGmx
= (name
.extension
== ".gmx");
35 while (lex
.isKw(Keyword
.Function
)) {
37 lex
.expect(Keyword
.Function
);
38 string fname
= lex
.expectId
;
39 auto fnode
= new NodeFunc(fname
, loc
);
41 if (lex
.isKw(Keyword
.LCurly
)) {
42 st
= parser
.parseCodeBlock();
44 st
= parser
.parseStatement();
46 if (auto b
= cast(NodeBlock
)st
) {
49 auto blk
= new NodeBlock(st
.loc
);
53 //if (exec.hasFunction(fnode.name)) throw new Exception("duplicate script '"~fnode.name~"' (from file '"~name~"')");
54 exec
[fnode
.name
] = fnode
;
57 string scname
= name
.baseName(".gml");
58 auto n
= parser
.parseFunctionBody(new NodeFunc(scname
, lex
.loc
));
59 //writeln(n.toString);
60 //if (exec.hasFunction(n.name)) throw new Exception("duplicate script '"~n.name~"'");
63 if (!lex
.empty
) throw new Exception("script '"~name
~"' has some extra code");
67 writeln("ERROR at ", e
.loc
, ": ", e
.msg
);
68 writeln(typeid(e
).name
, "@", e
.file
, "(", e
.line
, "): ", e
.msg
);
70 } catch (Exception e
) {
72 writeln(typeid(e
).name
, "@", e
.file
, "(", e
.line
, "): ", e
.msg
);
78 NodeFunc
parseScript (string code
, string scname
, bool strict
=true) {
79 auto lex
= new Lexer(code
, scname
);
81 auto parser
= new Parser(lex
, strict
);
82 //parser.warnings = true;
84 return parser
.parseFunctionBody(new NodeFunc(scname
, lex
.loc
));
87 writeln("ERROR at ", e
.loc
, ": ", e
.msg
);
88 writeln(typeid(e
).name
, "@", e
.file
, "(", e
.line
, "): ", e
.msg
);
91 } catch (Exception e
) {
93 writeln(typeid(e
).name
, "@", e
.file
, "(", e
.line
, "): ", e
.msg
);