PageRenderTime 53ms CodeModel.GetById 18ms app.highlight 28ms RepoModel.GetById 2ms app.codeStats 0ms

/parsing/d/versionunit.d

http://github.com/wilkie/djehuty
D | 207 lines | 109 code | 24 blank | 74 comment | 75 complexity | ca4259f6790b5e1306b86d9625a81108 MD5 | raw file
  1/*
  2 * expressionunit.d
  3 *
  4 * This module parses expressions.
  5 *
  6 */
  7
  8module parsing.d.versionunit;
  9
 10import parsing.parseunit;
 11import parsing.token;
 12
 13import parsing.d.tokens;
 14import parsing.d.nodes;
 15
 16import parsing.d.assignexprunit;
 17import parsing.d.declarationunit;
 18
 19import io.console;
 20
 21import djehuty;
 22
 23class VersionUnit : ParseUnit {
 24	override bool tokenFound(Token current) {
 25		if (this.state == 4) {
 26			// We are looking for declarations
 27			if (current.type == DToken.RightCurly) {
 28				// Done.
 29				return false;
 30			}
 31			else {
 32				lexer.push(current);
 33				auto tree = expand!(DeclarationUnit)();
 34			}
 35			return true;
 36		}
 37
 38		// Else, we are looking for the condition
 39
 40		switch (current.type) {
 41			// We could be declaring a version
 42			// version = Release; etc
 43			case DToken.Assign:
 44				if (this.state == 1) {
 45					// Error: Already started to use an identifier
 46					// TODO:
 47				}
 48				else if (this.state == 2) {
 49					// Error: Already named an identifier.
 50					// TODO:
 51				}
 52				else if (this.state == 3) {
 53					// Error: Found right paren.
 54					// TODO:
 55				}
 56
 57				// We need to find the identifier or integer to enable.
 58				this.state = 5;
 59				break;
 60
 61			// Look for a left paren first. It must exist.
 62			case DToken.LeftParen:
 63				if (this.state == 1) {
 64					// Error: Too many left parentheses.
 65					// TODO:
 66				}
 67				else if (this.state == 2) {
 68					// Error: Found an identifier.
 69					// TODO: Probably mistook left for right parenthesis.
 70				}
 71				else if (this.state == 3) {
 72					// Error: We already found a right paren... Expected colon or brace
 73					// TODO:
 74				}
 75				this.state = 1;
 76				break;
 77
 78			// For version assignment, we are looking for a semicolon to end it.
 79			case DToken.Semicolon:
 80				if (this.state == 5) {
 81					// Error: No identifier given.
 82					// TODO:
 83				}
 84				else if (this.state == 0) {
 85					// Error: Need '=' first.
 86					// TODO:
 87				}
 88				else if (this.state == 1) {
 89					// Error: Have left paren.
 90					// TODO:
 91				}
 92				else if (this.state == 2) {
 93					// Error: Have Identifier for normal foo.
 94					// TODO:
 95				}
 96				else if (this.state == 3) {
 97					// Error: Have right paren.
 98					// TODO:
 99				}
100
101				// else this.state == 6
102
103				// Done.
104				return false;
105
106			// Looking for some literal or identifier to use as the version
107			case DToken.Identifier:
108			case DToken.IntegerLiteral:
109				if (this.state == 5) {
110					// We are assigning a version
111					cur_string = current.value.toString();
112					Console.putln("Version enabled: ", current.value);
113					this.state = 6;
114				}
115				else if (this.state == 6) {
116					// Error: Too many identifiers in a row on a version assign.
117					// TODO:
118				}
119				else if (this.state == 0) {
120					// Error: No left parenthesis.
121					// TODO: Probably forgot it!
122				}
123				else if (this.state == 2) {
124					// Error: Too many identifiers in a row!
125					// TODO: Probably put a space or something in.
126				}
127				else if (this.state == 3) {
128					// Error: Found right parenthesis.
129					// TODO: Probably forgot a curly brace.
130				}
131				else {
132					Console.putln("Version: ", current.value);
133					cur_string = current.value.toString();
134					this.state = 2;
135				}
136				break;
137
138			case DToken.RightParen:
139				if (this.state == 0) {
140					// Error: Do not have a left paren.
141					// TODO: Probably forgot a left parenthesis.
142				}
143				else if (this.state == 3) {
144					// Error: Too many right parens
145					// TODO:
146				}
147
148				// Now we can look for a : or a curly brace for a declaration block
149				this.state = 3;
150				break;
151
152			// For declaring the rest of the file under this conditional block
153			// static if (foo):
154			case DToken.Colon:
155				if (this.state == 0) {
156					// Error: Do not have a condition!
157					// TODO:
158				}
159				else if (this.state == 1) {
160					// Error: Do not have an identifier.
161					// TODO:
162				}
163				else if (this.state == 2) {
164					// Error: Do not have a right paren.
165					// TODO:
166				}
167				else if (this.state == 4) {
168					// Error: After a left curly brace. We are within the block.
169					// TODO:
170				}
171
172				// Done.
173				return false;
174
175			// For specifying a declaration block for this condition
176			case DToken.LeftCurly:
177				if (this.state == 0) {
178					// Error: Do not have a condition!
179					// TODO:
180				}
181				else if (this.state == 1) {
182					// Error: Do not have an identifier.
183					// TODO:
184				}
185				else if (this.state == 2) {
186					// Error: Do not have a right paren.
187					// TODO:
188				}
189
190				// Now we look for declarations.
191				this.state = 4;
192				break;
193
194			// Errors for any unknown tokens.
195			default:
196				// TODO:
197				break;
198		}
199		return true;
200	}
201
202protected:
203	string cur_string = "";
204
205	static const string _common_error_msg = "";
206	static const string[] _common_error_usages = null;
207}