PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/parsing/d/enumdeclunit.d

http://github.com/wilkie/djehuty
D | 73 lines | 46 code | 9 blank | 18 comment | 5 complexity | fc11bfc94da7fc72f00180d4c61aaf9b MD5 | raw file
 1/*
 2 * expressionunit.d
 3 *
 4 * This module parses expressions.
 5 *
 6 */
 7
 8module parsing.d.enumdeclunit;
 9
10import parsing.parseunit;
11import parsing.token;
12
13import parsing.d.tokens;
14import parsing.d.nodes;
15
16import parsing.d.typeunit;
17import parsing.d.enumbodyunit;
18
19import io.console;
20
21import djehuty;
22
23class EnumDeclUnit : ParseUnit {
24	override bool tokenFound(Token current) {
25		// Looking for a name, or a colon for a type, or a curly
26		// braces for the enum body
27		switch (current.type) {
28			case DToken.Identifier:
29				// The name of the enum
30				if (this.state >= 1) {
31					// We are already passed the name stage.
32					// XXX: error
33				}
34				this.state = 1;
35				cur_string = current.value.toString();
36				Console.putln("Enum: ", current.value);
37				break;
38			case DToken.Colon:
39				// The type of the enum
40				if (this.state >= 2) {
41					// Already passed the type stage.
42					// XXX: error
43				}
44				this.state = 2;
45				auto tree = expand!(TypeUnit)();
46				break;
47			case DToken.Semicolon:
48				if (this.state == 0) {
49					// Need some kind of information about the enum.
50					error(_common_error_msg,
51							"Without a name, the linker will not know what it should be linking to.",
52							["enum FooBar;", "enum FooBar : uint;"]);
53					return false;
54				}
55				// Done.
56				return false;
57			case DToken.LeftCurly:
58				// We are going into the body of the enum
59				auto tree = expand!(EnumBodyUnit)();
60				// Done.
61				return false;
62			default:
63				break;
64		}
65		return true;
66	}
67
68protected:
69	string cur_string = "";
70
71	static const string _common_error_msg = "Enum declaration is invalid.";
72	static const string[] _common_error_usages = null;
73}