@@ -10,58 +10,62 @@ import callisto.error;
1010import callisto.parser;
1111import callisto.language;
1212
13- Node[] Preprocessor (
14- Node[] nodes, string [] includeDirs, ref string [] included, string [] versions
15- ) {
16- Node [] ret ;
13+ class Preprocessor {
14+ string [] includeDirs;
15+ string [] included;
16+ string [] versions ;
1717
18- foreach (ref inode ; nodes) {
19- switch (inode.type) {
20- case NodeType.Include: {
21- auto node = cast (IncludeNode) inode;
22- auto path = format(" %s/%s" , dirName(node.error.file), node.path);
18+ Node[] Run (Node[] nodes) {
19+ Node[] ret;
2320
24- if ( ! exists(path) ) {
25- bool found;
26-
27- foreach ( ref ipath ; includeDirs) {
28- path = format(" %s/%s" , ipath , node.path);
21+ foreach ( ref inode ; nodes ) {
22+ switch (inode.type) {
23+ case NodeType.Include: {
24+ auto node = cast (IncludeNode) inode;
25+ auto path = format(" %s/%s" , dirName(node.error.file) , node.path);
2926
30- if (exists(path)) {
31- found = true ;
32- break ;
27+ if (! exists(path)) {
28+ bool found;
29+
30+ foreach (ref ipath ; includeDirs) {
31+ path = format(" %s/%s" , ipath, node.path);
32+
33+ if (exists(path)) {
34+ found = true ;
35+ break ;
36+ }
3337 }
34- }
3538
36- if (! found) {
37- ErrorBegin(node.error);
38- stderr.writefln(" Can't find file '%s'" , node.path);
39- exit(1 );
39+ if (! found) {
40+ ErrorBegin(node.error);
41+ stderr.writefln(" Can't find file '%s'" , node.path);
42+ exit(1 );
43+ }
4044 }
41- }
4245
43- if (included.canFind(path)) {
44- continue ;
45- }
46+ if (included.canFind(path)) {
47+ continue ;
48+ }
4649
47- included ~= path;
50+ included ~= path;
4851
49- ret ~= Preprocessor (ParseFile(path), includeDirs, included, versions );
50- break ;
51- }
52- case NodeType.Version: {
53- auto node = cast (VersionNode) inode;
52+ ret ~= Run (ParseFile(path));
53+ break ;
54+ }
55+ case NodeType.Version: {
56+ auto node = cast (VersionNode) inode;
5457
55- if (versions.canFind(node.ver)) {
56- ret ~= node.block;
58+ if (versions.canFind(node.ver)) {
59+ ret ~= node.block;
60+ }
61+ break ;
62+ }
63+ default : {
64+ ret ~= inode;
5765 }
58- break ;
59- }
60- default : {
61- ret ~= inode;
6266 }
6367 }
64- }
6568
66- return ret;
69+ return ret;
70+ }
6771}
0 commit comments