File: main.bs

package info (click to toggle)
storm-lang 0.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 51,836 kB
  • sloc: ansic: 261,420; cpp: 138,870; sh: 14,877; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (75 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (5)
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
use core:io;
use core:lang;
use lang;
use lang:bnf;
use lang:bs:macro;

// Entry-point for the C++ implementation.
PkgReader reader(Url[] files, Package pkg) on Compiler {
	FilePkgReader(files, pkg, &readFile);
}

// Create files.
private FileReader readFile(FileInfo info) {
	Reader(info);
}

class Reader extends FileReader {
	init(FileInfo info) {
		init(info) {}
	}

	// For syntax highlighting.
	Rule rootRule() : override {
		named{SRoot};
	}

	// Types.
	void readTypes() : override {
		Content c = content();
		for (t in c.types) {
			info.pkg.add(t);
		}
	}

	void resolveTypes() : override {
		Content c = content();
		for (t in c.types) {
			t.resolve();
		}
	}

	// Functions.
	void readFunctions() : override {
		Content c = content();
		for (fn in c.functions) {
			fn.create(info.pkg);
		}

		for (global in c.globals) {
			global.create(info.pkg);
		}
	}

	void resolveFunctions() : override {}

private:

	// Content. Null if not parsed yet.
	Content? cont;

	// Get the parsed content.
	Content content() {
		if (cont)
			return cont;

		Parser<SRoot> parser;
		parser.parse(info.contents, info.url, info.start);
		if (parser.hasError)
			parser.throwError();

		Content c = parser.tree().transform();
		cont = c;
		return c;
	}
}