PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/parsing/d/staticifunit.d

http://github.com/wilkie/djehuty
D | 117 lines | 62 code | 19 blank | 36 comment | 29 complexity | be07b5a878c78b486d1e21377deab7bf MD5 | raw file
  1/*
  2 * expressionunit.d
  3 *
  4 * This module parses expressions.
  5 *
  6 */
  7
  8module parsing.d.staticifunit;
  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 StaticIfUnit : ParseUnit {
 24	override bool tokenFound(Token current) {
 25		if (this.state == 3) {
 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			// Look for a left paren first. It must exist.
 42			case DToken.LeftParen:
 43				if (this.state == 1) {
 44					// Error: Too many left parentheses.
 45					// TODO:
 46				}
 47				else if (this.state == 2) {
 48					// Error: We already found a right paren... Expected colon or brace
 49					// TODO:
 50				}
 51				this.state = 1;
 52
 53				// The conditional part
 54				auto tree = expand!(AssignExprUnit)();
 55				break;
 56
 57			case DToken.RightParen:
 58				if (this.state == 0) {
 59					// Error: Do not have a left paren.
 60					// TODO: Probably forgot a left parenthesis.
 61				}
 62				else if (this.state == 2) {
 63					// Error: Too many right parens
 64					// TODO:
 65				}
 66
 67				// Now we can look for a : or a curly brace for a declaration block
 68				this.state = 2;
 69				break;
 70
 71			// For declaring the rest of the file under this conditional block
 72			// static if (foo):
 73			case DToken.Colon:
 74				if (this.state == 0) {
 75					// Error: Do not have a condition!
 76					// TODO:
 77				}
 78				else if (this.state == 1) {
 79					// Error: Do not have a right paren.
 80					// TODO:
 81				}
 82				else if (this.state == 3) {
 83					// Error: After a left curly brace. We are within the block.
 84					// TODO:
 85				}
 86
 87				// Done.
 88				return false;
 89
 90			// For specifying a declaration block for this condition
 91			case DToken.LeftCurly:
 92				if (this.state == 0) {
 93					// Error: Do not have a condition!
 94					// TODO:
 95				}
 96				else if (this.state == 1) {
 97					// Error: Do not have a right paren.
 98					// TODO:
 99				}
100
101				// Now we look for declarations.
102				this.state = 3;
103				break;
104
105			// Errors for any unknown tokens.
106			default:
107				break;
108		}
109		return true;
110	}
111
112protected:
113	string cur_string = "";
114
115	static const string _common_error_msg = "";
116	static const string[] _common_error_usages = null;
117}